Commit eb95be4cf1132d285daeaedd5da329a44b23f236
1 parent
a5ec8f61
Exists in
master
and in
1 other branch
upgrading coulda
Showing
3 changed files
with
31 additions
and
31 deletions
Show diff stats
vendor/plugins/coulda/features/step_definitions/migration_steps.rb
1 | Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table| | 1 | Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table| |
2 | - up = " add_column :#{table}, :#{attr}_file_name, :string\n" << | ||
3 | - " add_column :#{table}, :#{attr}_content_type, :string\n" << | ||
4 | - " add_column :#{table}, :#{attr}_file_size, :integer\n" << | ||
5 | - " add_column :#{table}, :#{attr}_updated_at, :datetime" | ||
6 | - down = " remove_column :#{table}, :#{attr}_file_name\n" << | ||
7 | - " remove_column :#{table}, :#{attr}_content_type\n" << | ||
8 | - " remove_column :#{table}, :#{attr}_file_size\n" << | ||
9 | - " remove_column :#{table}, :#{attr}_updated_at" | ||
10 | - assert_generated_migration(table) do |body| | ||
11 | - assert body.include?(up), body.inspect | ||
12 | - assert body.include?(down), body.inspect | 2 | + assert_generated_migration(table) do |
3 | + " add_column :#{table}, :#{attr}_file_name, :string, :default => \"\"\n" << | ||
4 | + " add_column :#{table}, :#{attr}_content_type, :string, :default => \"\"\n" << | ||
5 | + " add_column :#{table}, :#{attr}_file_size, :integer, :default => \"\"\n" << | ||
6 | + " add_column :#{table}, :#{attr}_updated_at, :datetime, :default => \"\"" | ||
7 | + end | ||
8 | + assert_generated_migration(table) do | ||
9 | + " remove_column :#{table}, :#{attr}_file_name\n" << | ||
10 | + " remove_column :#{table}, :#{attr}_content_type\n" << | ||
11 | + " remove_column :#{table}, :#{attr}_file_size\n" << | ||
12 | + " remove_column :#{table}, :#{attr}_updated_at" | ||
13 | + end | ||
14 | +end | ||
15 | + | ||
16 | +Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key| | ||
17 | + assert_generated_migration(table) do | ||
18 | + "add_index :#{table}, :#{foreign_key}" | ||
19 | + end | ||
20 | +end | ||
21 | + | ||
22 | +Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr| | ||
23 | + assert_generated_migration(table) do | ||
24 | + " table.string :#{attr}_file_name, :default => \"\"\n" << | ||
25 | + " table.string :#{attr}_content_type, :default => \"\"\n" << | ||
26 | + " table.integer :#{attr}_file_size\n" << | ||
27 | + " table.datetime :#{attr}_updated_at" | ||
13 | end | 28 | end |
14 | end | 29 | end |
30 | + |
vendor/plugins/coulda/features/step_definitions/model_steps.rb
@@ -80,21 +80,3 @@ Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro| | @@ -80,21 +80,3 @@ Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro| | ||
80 | end | 80 | end |
81 | end | 81 | end |
82 | 82 | ||
83 | -# MIGRATION | ||
84 | - | ||
85 | -Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key| | ||
86 | - assert_generated_migration(table) do | ||
87 | - "add_index :#{table}, :#{foreign_key}" | ||
88 | - end | ||
89 | -end | ||
90 | - | ||
91 | -Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr| | ||
92 | - assert_generated_migration(table) do | ||
93 | - " table.string :#{attr}_file_name\n" << | ||
94 | - " table.string :#{attr}_content_type\n" << | ||
95 | - " table.integer :#{attr}_file_size\n" << | ||
96 | - " table.datetime :#{attr}_updated_at" | ||
97 | - end | ||
98 | -end | ||
99 | - | ||
100 | - |
vendor/plugins/coulda/generators/model/templates/migration.rb
@@ -3,10 +3,12 @@ class <%= migration_name %> < ActiveRecord::Migration | @@ -3,10 +3,12 @@ class <%= migration_name %> < ActiveRecord::Migration | ||
3 | create_table :<%= table_name %> do |table| | 3 | create_table :<%= table_name %> do |table| |
4 | <% attributes.each do |attribute| -%> | 4 | <% attributes.each do |attribute| -%> |
5 | <% if attribute.type == :paperclip -%> | 5 | <% if attribute.type == :paperclip -%> |
6 | - table.string :<%= attribute.name %>_file_name | ||
7 | - table.string :<%= attribute.name %>_content_type | 6 | + table.string :<%= attribute.name %>_file_name, :default => "" |
7 | + table.string :<%= attribute.name %>_content_type, :default => "" | ||
8 | table.integer :<%= attribute.name %>_file_size | 8 | table.integer :<%= attribute.name %>_file_size |
9 | table.datetime :<%= attribute.name %>_updated_at | 9 | table.datetime :<%= attribute.name %>_updated_at |
10 | +<% elsif attribute.type == :string -%> | ||
11 | + table.string :<%= attribute.name %>, :default => "" | ||
10 | <% else -%> | 12 | <% else -%> |
11 | table.<%= attribute.type %> :<%= attribute.name %> | 13 | table.<%= attribute.type %> :<%= attribute.name %> |
12 | <% end -%> | 14 | <% end -%> |