aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/migration_generator_test.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-07-31 16:21:07 -0300
committerEmilio Tagua <miloops@gmail.com>2009-07-31 16:21:07 -0300
commit3de59e916d6a3d4eab202cf0c99b1f88905a3b43 (patch)
treedef6d6a808ebe187be1f37f8a739fd786cc11f02 /railties/test/generators/migration_generator_test.rb
parentc1cbf02e3170f1004daf4a146cbc41176c2458d3 (diff)
parent62fd1d3716b4b5fd1d91cdcc77003efe80fc5a7e (diff)
downloadrails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.tar.gz
rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.tar.bz2
rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.zip
Merge commit 'rails/master'
Conflicts: activerecord/lib/active_record/associations.rb
Diffstat (limited to 'railties/test/generators/migration_generator_test.rb')
-rw-r--r--railties/test/generators/migration_generator_test.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
new file mode 100644
index 0000000000..a4335068e6
--- /dev/null
+++ b/railties/test/generators/migration_generator_test.rb
@@ -0,0 +1,59 @@
+require 'abstract_unit'
+require 'generators/generators_test_helper'
+require 'generators/rails/migration/migration_generator'
+
+class MigrationGeneratorTest < GeneratorsTestCase
+
+ def test_migration
+ @migration = "change_title_body_from_posts"
+ run_generator
+ assert_migration "db/migrate/#{@migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/
+ end
+
+ def test_migration_with_class_name
+ @migration = "ChangeTitleBodyFromPosts"
+ run_generator
+ assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{@migration} < ActiveRecord::Migration/
+ end
+
+ def test_add_migration_with_attributes
+ @migration = "add_title_body_to_posts"
+ run_generator [@migration, "title:string", "body:text"]
+
+ assert_migration "db/migrate/#{@migration}.rb" do |content|
+ assert_class_method content, :up do |up|
+ assert_match /add_column :posts, :title, :string/, up
+ assert_match /add_column :posts, :body, :text/, up
+ end
+
+ assert_class_method content, :down do |down|
+ assert_match /remove_column :posts, :title/, down
+ assert_match /remove_column :posts, :body/, down
+ end
+ end
+ end
+
+ def test_remove_migration_with_attributes
+ @migration = "remove_title_body_from_posts"
+ run_generator [@migration, "title:string", "body:text"]
+
+ assert_migration "db/migrate/#{@migration}.rb" do |content|
+ assert_class_method content, :up do |up|
+ assert_match /remove_column :posts, :title/, up
+ assert_match /remove_column :posts, :body/, up
+ end
+
+ assert_class_method content, :down do |down|
+ assert_match /add_column :posts, :title, :string/, down
+ assert_match /add_column :posts, :body, :text/, down
+ end
+ end
+ end
+
+ protected
+
+ def run_generator(args=[@migration])
+ silence(:stdout) { Rails::Generators::MigrationGenerator.start args, :destination_root => destination_root }
+ end
+
+end