Skip to content
Browse files

Use Rails 3.1 `change` method in 'add_' migration generator

  • Loading branch information...
1 parent 9e64dfa commit ad343d7263d0922bbe32f550e7057d55f2c4d311 @sikachu sikachu committed with tenderlove Jan 1, 2011
View
8 activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
@@ -1,4 +1,11 @@
class <%= migration_class_name %> < ActiveRecord::Migration
+<%- if migration_action == 'add' -%>
+ def change
+<% attributes.each do |attribute| -%>
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %>
+<%- end -%>
+ end
+<%- else -%>
def up
<% attributes.each do |attribute| -%>
<%- if migration_action -%>
@@ -14,4 +21,5 @@ def down
<%- end -%>
<%- end -%>
end
+<%- end -%>
end
View
7 railties/test/generators/migration_generator_test.rb
@@ -34,15 +34,10 @@ def test_add_migration_with_attributes
run_generator [migration, "title:string", "body:text"]
assert_migration "db/migrate/#{migration}.rb" do |content|
- assert_method :up, content do |up|
+ assert_method :change, content do |up|
assert_match /add_column :posts, :title, :string/, up
assert_match /add_column :posts, :body, :text/, up
end
-
- assert_method :down, content do |down|
- assert_match /remove_column :posts, :title/, down
- assert_match /remove_column :posts, :body/, down
- end
end
end

0 comments on commit ad343d7

Please sign in to comment.
Something went wrong with that request. Please try again.