Skip to content

Commit

Permalink
Use Rails 3.1 change method in 'add_' migration generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu authored and tenderlove committed Jan 4, 2011
1 parent 9e64dfa commit ad343d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
@@ -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 -%>
Expand All @@ -14,4 +21,5 @@ def down
<%- end -%>
<%- end -%>
end
<%- end -%>
end
7 changes: 1 addition & 6 deletions railties/test/generators/migration_generator_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit ad343d7

Please sign in to comment.