From 696c2ea68d7cdbf7eb15f7dce2d83498ef659eb7 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 20 May 2011 13:17:16 +0900 Subject: Tests for new create_table DSL --- activerecord/test/cases/migration_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index bf7565a0d0..111dd01f2b 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1653,6 +1653,26 @@ if ActiveRecord::Base.connection.supports_migrations? end # SexyMigrationsTest + class SexierMigrationsTest < ActiveRecord::TestCase + def test_create_table_with_column_without_block_parameter + Person.connection.create_table :testings, :force => true do + column :foo, :string + end + assert Person.connection.column_exists?(:testings, :foo, :string) + ensure + Person.connection.drop_table :testings rescue nil + end + + def test_create_table_with_sexy_column_without_block_parameter + Person.connection.create_table :testings, :force => true do + integer :bar + end + assert Person.connection.column_exists?(:testings, :bar, :integer) + ensure + Person.connection.drop_table :testings rescue nil + end + end # SexierMigrationsTest + class MigrationLoggerTest < ActiveRecord::TestCase def test_migration_should_be_run_without_logger previous_logger = ActiveRecord::Base.logger -- cgit v1.2.3 From 3dbedd2823ff6c8a1f2f078ae9df9c6ceb275e1b Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Fri, 14 Oct 2011 21:09:53 -0700 Subject: Default timestamps to non-null --- activerecord/test/cases/migration_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 93a1249e43..4b5dd18be8 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -389,8 +389,8 @@ if ActiveRecord::Base.connection.supports_migrations? created_at_column = created_columns.detect {|c| c.name == 'created_at' } updated_at_column = created_columns.detect {|c| c.name == 'updated_at' } - assert created_at_column.null - assert updated_at_column.null + assert !created_at_column.null + assert !updated_at_column.null ensure Person.connection.drop_table table_name rescue nil end @@ -471,11 +471,11 @@ if ActiveRecord::Base.connection.supports_migrations? # Do a manual insertion if current_adapter?(:OracleAdapter) - Person.connection.execute "insert into people (id, wealth) values (people_seq.nextval, 12345678901234567890.0123456789)" + Person.connection.execute "insert into people (id, wealth, created_at, updated_at) values (people_seq.nextval, 12345678901234567890.0123456789, 0, 0)" elsif current_adapter?(:OpenBaseAdapter) || (current_adapter?(:MysqlAdapter) && Mysql.client_version < 50003) #before mysql 5.0.3 decimals stored as strings - Person.connection.execute "insert into people (wealth) values ('12345678901234567890.0123456789')" + Person.connection.execute "insert into people (wealth, created_at, updated_at) values ('12345678901234567890.0123456789', 0, 0)" else - Person.connection.execute "insert into people (wealth) values (12345678901234567890.0123456789)" + Person.connection.execute "insert into people (wealth, created_at, updated_at) values (12345678901234567890.0123456789, 0, 0)" end # SELECT -- cgit v1.2.3 From 76af2818a6b729955ad799b5346da7ed115440ea Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 18 Oct 2011 10:07:40 -0700 Subject: use now() for dates in pg --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 4b5dd18be8..6ce7ae7877 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -475,7 +475,7 @@ if ActiveRecord::Base.connection.supports_migrations? elsif current_adapter?(:OpenBaseAdapter) || (current_adapter?(:MysqlAdapter) && Mysql.client_version < 50003) #before mysql 5.0.3 decimals stored as strings Person.connection.execute "insert into people (wealth, created_at, updated_at) values ('12345678901234567890.0123456789', 0, 0)" else - Person.connection.execute "insert into people (wealth, created_at, updated_at) values (12345678901234567890.0123456789, 0, 0)" + Person.connection.execute "insert into people (wealth, created_at, updated_at) values (12345678901234567890.0123456789, now(), now())" end # SELECT -- cgit v1.2.3 From c2f3c9bf56534f8f50b4e47a7e18e822f6600bbe Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 18 Oct 2011 13:30:01 -0700 Subject: only use now() on pg! --- activerecord/test/cases/migration_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 6ce7ae7877..b3f1785f44 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -474,8 +474,10 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.execute "insert into people (id, wealth, created_at, updated_at) values (people_seq.nextval, 12345678901234567890.0123456789, 0, 0)" elsif current_adapter?(:OpenBaseAdapter) || (current_adapter?(:MysqlAdapter) && Mysql.client_version < 50003) #before mysql 5.0.3 decimals stored as strings Person.connection.execute "insert into people (wealth, created_at, updated_at) values ('12345678901234567890.0123456789', 0, 0)" - else + elsif current_adapter?(:PostgreSQLAdapter) Person.connection.execute "insert into people (wealth, created_at, updated_at) values (12345678901234567890.0123456789, now(), now())" + else + Person.connection.execute "insert into people (wealth, created_at, updated_at) values (12345678901234567890.0123456789, 0, 0)" end # SELECT -- cgit v1.2.3 From 5bc23e4fb503e038c8e24a3a58d4eb1c323e94c8 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Wed, 19 Oct 2011 15:56:25 -0400 Subject: Fix ORA-00932 error when trying to insert 0 to DATE type columns. --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index b3f1785f44..47ab5d5f9d 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -471,7 +471,7 @@ if ActiveRecord::Base.connection.supports_migrations? # Do a manual insertion if current_adapter?(:OracleAdapter) - Person.connection.execute "insert into people (id, wealth, created_at, updated_at) values (people_seq.nextval, 12345678901234567890.0123456789, 0, 0)" + Person.connection.execute "insert into people (id, wealth, created_at, updated_at) values (people_seq.nextval, 12345678901234567890.0123456789, sysdate, sysdate)" elsif current_adapter?(:OpenBaseAdapter) || (current_adapter?(:MysqlAdapter) && Mysql.client_version < 50003) #before mysql 5.0.3 decimals stored as strings Person.connection.execute "insert into people (wealth, created_at, updated_at) values ('12345678901234567890.0123456789', 0, 0)" elsif current_adapter?(:PostgreSQLAdapter) -- cgit v1.2.3 From f092be821db4a2e8f142e8f0b9d08e497ccf2eb2 Mon Sep 17 00:00:00 2001 From: Greg Reinacker Date: Fri, 21 Oct 2011 17:30:39 -0600 Subject: preserve decimal column attributes after migration --- activerecord/test/cases/migration_test.rb | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index b3f1785f44..49944eced9 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -518,6 +518,42 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal 7, wealth_column.scale end + # Test SQLite adapter specifically for decimal types with precision and scale + # attributes, since these need to be maintained in schema but aren't actually + # used in SQLite itself + if current_adapter?(:SQLite3Adapter) + def test_change_column_with_new_precision_and_scale + Person.delete_all + Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7 + Person.reset_column_information + + Person.connection.change_column 'people', 'wealth', :decimal, :precision => 12, :scale => 8 + Person.reset_column_information + + wealth_column = Person.columns_hash['wealth'] + assert_equal 12, wealth_column.precision + assert_equal 8, wealth_column.scale + end + + def test_change_column_preserve_other_column_precision_and_scale + Person.delete_all + Person.connection.add_column 'people', 'last_name', :string + Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7 + Person.reset_column_information + + wealth_column = Person.columns_hash['wealth'] + assert_equal 9, wealth_column.precision + assert_equal 7, wealth_column.scale + + Person.connection.change_column 'people', 'last_name', :string, :null => false + Person.reset_column_information + + wealth_column = Person.columns_hash['wealth'] + assert_equal 9, wealth_column.precision + assert_equal 7, wealth_column.scale + end + end + def test_native_types Person.delete_all Person.connection.add_column "people", "last_name", :string -- cgit v1.2.3 From ff9c2799c1a065fb132df64da6d19683c647b5b4 Mon Sep 17 00:00:00 2001 From: Laust Rud Jacobsen Date: Tue, 1 Nov 2011 07:29:48 +0100 Subject: dump_schema_information: explicitly order inserts into schema_migrations table This change reduces churn in the db/development_structure.sql file when using :sql as active_record.schema_format, and makes comparing diffs much easier. Test ensures the output SQL-statements are lexically ordered by version. --- activerecord/test/cases/migration_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 49944eced9..4fdb7d2f25 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1339,6 +1339,15 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_dump_schema_information_outputs_lexically_ordered_versions + migration_path = MIGRATIONS_ROOT + '/valid_with_timestamps' + ActiveRecord::Migrator.run(:up, migration_path, 20100301010101) + ActiveRecord::Migrator.run(:up, migration_path, 20100201010101) + + schema_info = ActiveRecord::Base.connection.dump_schema_information + assert_match schema_info, /20100201010101.*20100301010101/m + end + def test_finds_pending_migrations ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1) migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations -- cgit v1.2.3 From 1afe269a4aa18a815c509d3f0348ed99a9b4b560 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 31 Oct 2011 19:01:03 +0530 Subject: assert_match takes a regexp and a string in that order --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 4fdb7d2f25..f61d0315d0 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1345,7 +1345,7 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Migrator.run(:up, migration_path, 20100201010101) schema_info = ActiveRecord::Base.connection.dump_schema_information - assert_match schema_info, /20100201010101.*20100301010101/m + assert_match(/20100201010101.*20100301010101/m, schema_info) end def test_finds_pending_migrations -- cgit v1.2.3 From 69dcd45aea770ca90bb3e1f8ce4e944dfb37e766 Mon Sep 17 00:00:00 2001 From: Vlad Jebelev Date: Fri, 4 Nov 2011 15:45:24 -0500 Subject: AR changes to support creating ordered (asc, desc) indexes --- activerecord/test/cases/migration_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 5c47a8ad33..e8ad37d437 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -121,6 +121,18 @@ if ActiveRecord::Base.connection.supports_migrations? assert_nothing_raised { Person.connection.add_index("people", %w(last_name first_name administrator), :name => "named_admin") } assert_nothing_raised { Person.connection.remove_index("people", :name => "named_admin") } end + + # Selected adapters support index sort order + if current_adapter?(:SQLite3Adapter, :MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter) + assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :order => {:last_name => :desc}) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name"]) } + assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :order => {:last_name => :desc}) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } + assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :order => {:last_name => :desc, :first_name => :asc}) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } + assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :order => :desc) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } + end end def test_index_symbol_names -- cgit v1.2.3 From b805c71655ada0e3fcf7ccc1cdf3376e55b2b9ce Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 10 Nov 2011 19:05:37 +0530 Subject: Checking the arity of the block passed to create_table A recent change made to create_table does away with the need for the block argument. Checking the arity will prevent the mixing up of the two syntaxes. --- activerecord/test/cases/migration_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index e8ad37d437..50242a497c 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1742,6 +1742,21 @@ if ActiveRecord::Base.connection.supports_migrations? ensure Person.connection.drop_table :testings rescue nil end + + def test_create_table_should_not_have_mixed_syntax + assert_raise(NoMethodError) do + Person.connection.create_table :testings, :force => true do |t| + t.string :foo + integer :bar + end + end + assert_raise(NameError) do + Person.connection.create_table :testings, :force => true do + t.string :foo + integer :bar + end + end + end end # SexierMigrationsTest class MigrationLoggerTest < ActiveRecord::TestCase -- cgit v1.2.3 From 6e112e42176c6842270f879fd15a0b7b7371ecef Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 11 Nov 2011 02:47:27 +0530 Subject: Modify change_table to remove the need for the block argument. --- activerecord/test/cases/migration_test.rb | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 50242a497c..e276993508 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1757,6 +1757,58 @@ if ActiveRecord::Base.connection.supports_migrations? end end end + + def test_change_table_without_block_parameter_no_bulk + Person.connection.create_table :testings, :force => true do + string :foo + end + assert Person.connection.column_exists?(:testings, :foo, :string) + + Person.connection.change_table :testings do + remove :foo + integer :bar + end + + assert_equal %w(bar id), Person.connection.columns(:testings).map { |c| c.name }.sort + ensure + Person.connection.drop_table :testings rescue nil + end + + def test_change_table_without_block_parameter_with_bulk + Person.connection.create_table :testings, :force => true do + string :foo + end + assert Person.connection.column_exists?(:testings, :foo, :string) + + assert_queries(1) do + Person.connection.change_table(:testings, :bulk => true) do + integer :bar + string :foo_bar + end + end + + assert_equal %w(bar foo foo_bar id), Person.connection.columns(:testings).map { |c| c.name }.sort + ensure + Person.connection.drop_table :testings rescue nil + end + + def test_change_table_should_not_have_mixed_syntax + Person.connection.create_table :testings, :force => true do + string :foo + end + assert_raise(NoMethodError) do + Person.connection.change_table :testings do |t| + t.remove :foo + integer :bar + end + end + assert_raise(NameError) do + Person.connection.change_table :testings do + t.remove :foo + integer :bar + end + end + end end # SexierMigrationsTest class MigrationLoggerTest < ActiveRecord::TestCase -- cgit v1.2.3 From 2e5c4717ba8aca8459637f9413b100ed58a6bcd1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 11 Nov 2011 12:47:03 +0530 Subject: change_table bulk test case should check if the connection supports bulk alter --- activerecord/test/cases/migration_test.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index e276993508..d6c7edc461 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1774,22 +1774,24 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.drop_table :testings rescue nil end - def test_change_table_without_block_parameter_with_bulk - Person.connection.create_table :testings, :force => true do - string :foo - end - assert Person.connection.column_exists?(:testings, :foo, :string) + if ActiveRecord::Base.connection.supports_bulk_alter? + def test_change_table_without_block_parameter_with_bulk + Person.connection.create_table :testings, :force => true do + string :foo + end + assert Person.connection.column_exists?(:testings, :foo, :string) - assert_queries(1) do - Person.connection.change_table(:testings, :bulk => true) do - integer :bar - string :foo_bar + assert_queries(1) do + Person.connection.change_table(:testings, :bulk => true) do + integer :bar + string :foo_bar + end end - end - assert_equal %w(bar foo foo_bar id), Person.connection.columns(:testings).map { |c| c.name }.sort - ensure - Person.connection.drop_table :testings rescue nil + assert_equal %w(bar foo foo_bar id), Person.connection.columns(:testings).map { |c| c.name }.sort + ensure + Person.connection.drop_table :testings rescue nil + end end def test_change_table_should_not_have_mixed_syntax -- cgit v1.2.3 From 649f2513a453cae319be8b63a9de25ae11fb9e8f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 17 Nov 2011 10:00:33 -0800 Subject: Revert "Merge pull request #3603 from vijaydev/change_table_without_block_arg" This reverts commit 81fad6a270ec3cbbb88553c9f2e8200c34fd4d13, reversing changes made to 23101de283de13517e30c4c3d1ecc65525264886. Conflicts: activerecord/test/cases/migration_test.rb --- activerecord/test/cases/migration_test.rb | 54 ------------------------------- 1 file changed, 54 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 75eb9c2bce..ae5b2a62b5 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1757,60 +1757,6 @@ if ActiveRecord::Base.connection.supports_migrations? end end end - - def test_change_table_without_block_parameter_no_bulk - Person.connection.create_table :testings, :force => true do - string :foo - end - assert Person.connection.column_exists?(:testings, :foo, :string) - - Person.connection.change_table :testings do - remove :foo - integer :bar - end - - assert_equal %w(bar id), Person.connection.columns(:testings).map { |c| c.name }.sort - ensure - Person.connection.drop_table :testings rescue nil - end - - if ActiveRecord::Base.connection.supports_bulk_alter? - def test_change_table_without_block_parameter_with_bulk - Person.connection.create_table :testings, :force => true do - string :foo - end - assert Person.connection.column_exists?(:testings, :foo, :string) - - assert_queries(1) do - Person.connection.change_table(:testings, :bulk => true) do - integer :bar - string :foo_bar - end - end - - assert_equal %w(bar foo foo_bar id), Person.connection.columns(:testings).map { |c| c.name }.sort - ensure - Person.connection.drop_table :testings rescue nil - end - end - - def test_change_table_should_not_have_mixed_syntax - Person.connection.create_table :testings, :force => true do - string :foo - end - assert_raise(NoMethodError) do - Person.connection.change_table :testings do |t| - t.remove :foo - integer :bar - end - end - assert_raise(NameError) do - Person.connection.change_table :testings do - t.remove :foo - integer :bar - end - end - end end # SexierMigrationsTest class MigrationLoggerTest < ActiveRecord::TestCase -- cgit v1.2.3 From a2f14e23441ec016f9643b9054f409006b0e16b3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 17 Nov 2011 10:28:23 -0800 Subject: Revert "Merge pull request #1163 from amatsuda/sexier_migration_31" This reverts commit 0e407a90413d8a19002b85508d811ccdf2190783, reversing changes made to 533a9f84b035756eedf9fdccf0c494dc9701ba72. Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/migration_test.rb --- activerecord/test/cases/migration_test.rb | 120 ------------------------------ 1 file changed, 120 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index ae5b2a62b5..3e219f2a49 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1639,126 +1639,6 @@ if ActiveRecord::Base.connection.supports_migrations? end - class SexyMigrationsTest < ActiveRecord::TestCase - def test_references_column_type_adds_id - with_new_table do |t| - t.expects(:column).with('customer_id', :integer, {}) - t.references :customer - end - end - - def test_references_column_type_with_polymorphic_adds_type - with_new_table do |t| - t.expects(:column).with('taggable_type', :string, {}) - t.expects(:column).with('taggable_id', :integer, {}) - t.references :taggable, :polymorphic => true - end - end - - def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag - with_new_table do |t| - t.expects(:column).with('taggable_type', :string, {:null => false}) - t.expects(:column).with('taggable_id', :integer, {:null => false}) - t.references :taggable, :polymorphic => true, :null => false - end - end - - def test_belongs_to_works_like_references - with_new_table do |t| - t.expects(:column).with('customer_id', :integer, {}) - t.belongs_to :customer - end - end - - def test_timestamps_creates_updated_at_and_created_at - with_new_table do |t| - t.expects(:column).with(:created_at, :datetime, kind_of(Hash)) - t.expects(:column).with(:updated_at, :datetime, kind_of(Hash)) - t.timestamps - end - end - - def test_integer_creates_integer_column - with_new_table do |t| - t.expects(:column).with(:foo, 'integer', {}) - t.expects(:column).with(:bar, 'integer', {}) - t.integer :foo, :bar - end - end - - def test_string_creates_string_column - with_new_table do |t| - t.expects(:column).with(:foo, 'string', {}) - t.expects(:column).with(:bar, 'string', {}) - t.string :foo, :bar - end - end - - if current_adapter?(:PostgreSQLAdapter) || current_adapter?(:SQLite3Adapter) || current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter) - def test_xml_creates_xml_column - type = current_adapter?(:PostgreSQLAdapter) ? 'xml' : :text - - with_new_table do |t| - t.expects(:column).with(:data, type, {}) - t.xml :data - end - end - else - def test_xml_creates_xml_column - with_new_table do |t| - assert_raises(NotImplementedError) do - t.xml :data - end - end - end - end - - protected - def with_new_table - Person.connection.create_table :delete_me, :force => true do |t| - yield t - end - ensure - Person.connection.drop_table :delete_me rescue nil - end - - end # SexyMigrationsTest - - class SexierMigrationsTest < ActiveRecord::TestCase - def test_create_table_with_column_without_block_parameter - Person.connection.create_table :testings, :force => true do - column :foo, :string - end - assert Person.connection.column_exists?(:testings, :foo, :string) - ensure - Person.connection.drop_table :testings rescue nil - end - - def test_create_table_with_sexy_column_without_block_parameter - Person.connection.create_table :testings, :force => true do - integer :bar - end - assert Person.connection.column_exists?(:testings, :bar, :integer) - ensure - Person.connection.drop_table :testings rescue nil - end - - def test_create_table_should_not_have_mixed_syntax - assert_raise(NoMethodError) do - Person.connection.create_table :testings, :force => true do |t| - t.string :foo - integer :bar - end - end - assert_raise(NameError) do - Person.connection.create_table :testings, :force => true do - t.string :foo - integer :bar - end - end - end - end # SexierMigrationsTest - class MigrationLoggerTest < ActiveRecord::TestCase def test_migration_should_be_run_without_logger previous_logger = ActiveRecord::Base.logger -- cgit v1.2.3 From 0b72a04d0c93b666c23500aefbe4a6a76593cd36 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 29 Nov 2011 12:28:04 +0000 Subject: Deprecate set_table_name in favour of self.table_name= or defining your own method. --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 3e219f2a49..00c811194c 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1027,7 +1027,7 @@ if ActiveRecord::Base.connection.supports_migrations? t.column :title, :string end person_klass = Class.new(Person) - person_klass.set_table_name 'testings' + person_klass.table_name = 'testings' person_klass.connection.add_column "testings", "wealth", :integer, :null => false, :default => 99 person_klass.reset_column_information -- cgit v1.2.3 From 0968ee3456a874aa46d37d68b2d7d2dd0a84a5fe Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sat, 26 Nov 2011 17:23:20 +0300 Subject: add prefix and suffix to renamed tables, closes #1510 --- activerecord/test/cases/migration_test.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 00c811194c..6b17d3d63e 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -6,6 +6,8 @@ require 'models/topic' require 'models/developer' require MIGRATIONS_ROOT + "/valid/2_we_need_reminders" +require MIGRATIONS_ROOT + "/rename/1_we_need_things" +require MIGRATIONS_ROOT + "/rename/2_rename_things" require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers" if ActiveRecord::Base.connection.supports_migrations? @@ -13,6 +15,8 @@ if ActiveRecord::Base.connection.supports_migrations? class Reminder < ActiveRecord::Base; end + class Thing < ActiveRecord::Base; end + class ActiveRecord::Migration class << self attr_accessor :message_count @@ -57,6 +61,11 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.connection.initialize_schema_migrations_table ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}" + %w(things awesome_things prefix_things_suffix prefix_awesome_things_suffix).each do |table| + Thing.connection.drop_table(table) rescue nil + end + Thing.reset_column_information + %w(reminders people_reminders prefix_reminders_suffix).each do |table| Reminder.connection.drop_table(table) rescue nil end @@ -1534,6 +1543,28 @@ if ActiveRecord::Base.connection.supports_migrations? Reminder.reset_table_name end + def test_rename_table_with_prefix_and_suffix + assert !Thing.table_exists? + ActiveRecord::Base.table_name_prefix = 'prefix_' + ActiveRecord::Base.table_name_suffix = '_suffix' + Thing.reset_table_name + Thing.reset_sequence_name + WeNeedThings.up + + assert Thing.create("content" => "hello world") + assert_equal "hello world", Thing.find(:first).content + + RenameThings.up + Thing.set_table_name("prefix_awesome_things_suffix") + + assert_equal "hello world", Thing.find(:first).content + ensure + ActiveRecord::Base.table_name_prefix = '' + ActiveRecord::Base.table_name_suffix = '' + Thing.reset_table_name + Thing.reset_sequence_name + end + def test_add_drop_table_with_prefix_and_suffix assert !Reminder.table_exists? ActiveRecord::Base.table_name_prefix = 'prefix_' -- cgit v1.2.3 From 9dee5400845a5355b28868c475bc58c6cfb06216 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 6 Dec 2011 10:07:47 -0800 Subject: avoid deprecated methods --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 6b17d3d63e..42d62eca8e 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1555,7 +1555,7 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "hello world", Thing.find(:first).content RenameThings.up - Thing.set_table_name("prefix_awesome_things_suffix") + Thing.table_name = "prefix_awesome_things_suffix" assert_equal "hello world", Thing.find(:first).content ensure -- cgit v1.2.3 From 652db2fc3e1d62737e4bedb3b7cee313d7400c0a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 00:50:39 +0100 Subject: Fix copying migrations from engines There was a bug in ActiveRecord::Migration.copy method, which prevented adding special comment about the origin of migration. Because of that, the check if migration is identical or if it's not and should be skipped was always saying that migration is skipped, which was causing additional useless warnings about skipped migrations. --- activerecord/test/cases/migration_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 42d62eca8e..1997fc96ea 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -2103,6 +2103,9 @@ if ActiveRecord::Base.connection.supports_migrations? assert File.exists?(@migrations_path + "/5_people_have_descriptions.rb") assert_equal [@migrations_path + "/4_people_have_hobbies.rb", @migrations_path + "/5_people_have_descriptions.rb"], copied.map(&:filename) + expected = "# This migration comes from bukkits (originally 1)" + assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.rb")[0].chomp + files_count = Dir[@migrations_path + "/*.rb"].length copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"}) assert_equal files_count, Dir[@migrations_path + "/*.rb"].length @@ -2213,6 +2216,24 @@ if ActiveRecord::Base.connection.supports_migrations? clear end + def test_skip_is_not_called_if_migrations_are_identical + @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps" + @existing_migrations = Dir[@migrations_path + "/*.rb"] + + sources = ActiveSupport::OrderedHash.new + sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps" + + skipped = [] + on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" } + copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) + ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) + + assert_equal 2, copied.length + assert_equal 0, skipped.length + ensure + clear + end + def test_copying_migrations_to_non_existing_directory @migrations_path = MIGRATIONS_ROOT + "/non_existing" @existing_migrations = [] -- cgit v1.2.3 From 62d556424adcbf473ec5fe2ed9b460c058a36463 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 01:49:08 +0100 Subject: Ignore origin comment when checking for duplicates on Migration.copy 49ebe51 fixed copying migrations, but existing migrations would still trigger warnings. The proper way to compare migrations is to ignore origin lines - if migration is identical it means that we can silently skip it, regardless where it comes from. --- activerecord/test/cases/migration_test.rb | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 1997fc96ea..7c92db5def 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -2203,15 +2203,16 @@ if ActiveRecord::Base.connection.supports_migrations? @existing_migrations = Dir[@migrations_path + "/*.rb"] sources = ActiveSupport::OrderedHash.new - sources[:bukkits] = sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_timestamps" + sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps" + sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision" skipped = [] on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" } copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) assert_equal 2, copied.length - assert_equal 2, skipped.length - assert_equal ["bukkits PeopleHaveHobbies", "bukkits PeopleHaveDescriptions"], skipped + assert_equal 1, skipped.length + assert_equal ["omg PeopleHaveHobbies"], skipped ensure clear end @@ -2234,6 +2235,31 @@ if ActiveRecord::Base.connection.supports_migrations? clear end + def test_skip_ignores_origin_comment + ActiveRecord::Base.timestamped_migrations = false + @migrations_path = MIGRATIONS_ROOT + "/valid" + @existing_migrations = Dir[@migrations_path + "/*.rb"] + + sources = ActiveSupport::OrderedHash.new + sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy" + + skipped = [] + on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" } + copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) + + # remove origin comment + migration = @migrations_path + "/4_people_have_hobbies.rb" + migration_source = File.read(migration).to_a[1..-1].join + File.open(migration, "w") { |f| f.write migration_source } + + ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) + + assert_equal 2, copied.length + assert_equal 0, skipped.length + ensure + clear + end + def test_copying_migrations_to_non_existing_directory @migrations_path = MIGRATIONS_ROOT + "/non_existing" @existing_migrations = [] -- cgit v1.2.3 From 1d9de9d7585f2c753b629080b1239969aaf8499a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 03:15:59 +0100 Subject: Run also migrations in subdirectories. With this commit, ActiveRecord will also look for migrations in db/migrate subdirectories. --- activerecord/test/cases/migration_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 7c92db5def..fb49dccbd3 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1346,6 +1346,15 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_finds_migrations_in_subdirectories + migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid_with_subdirectories").migrations + + [[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i| + assert_equal migrations[i].version, pair.first + assert_equal migrations[i].name, pair.last + end + end + def test_finds_migrations_from_two_directories directories = [MIGRATIONS_ROOT + '/valid_with_timestamps', MIGRATIONS_ROOT + '/to_copy_with_timestamps'] migrations = ActiveRecord::Migrator.new(:up, directories).migrations -- cgit v1.2.3 From 255d9f5ac1f2afa5a293a4b45d3aa17a31da46bf Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 10:33:37 +0100 Subject: String#to_a is not available in 1.9 --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index fb49dccbd3..e27a1ff535 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -2258,7 +2258,7 @@ if ActiveRecord::Base.connection.supports_migrations? # remove origin comment migration = @migrations_path + "/4_people_have_hobbies.rb" - migration_source = File.read(migration).to_a[1..-1].join + migration_source = File.read(migration).lines.to_a[1..-1].join File.open(migration, "w") { |f| f.write migration_source } ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) -- cgit v1.2.3 From ed0b1f6eed6d894f9a0f32a226d29337782ada3c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 11:45:19 +0100 Subject: Add suffix for migrations copied from engines --- activerecord/test/cases/migration_test.rb | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index e27a1ff535..c185efe1d6 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -2108,12 +2108,12 @@ if ActiveRecord::Base.connection.supports_migrations? @existing_migrations = Dir[@migrations_path + "/*.rb"] copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"}) - assert File.exists?(@migrations_path + "/4_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/5_people_have_descriptions.rb") - assert_equal [@migrations_path + "/4_people_have_hobbies.rb", @migrations_path + "/5_people_have_descriptions.rb"], copied.map(&:filename) + assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb") + assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename) expected = "# This migration comes from bukkits (originally 1)" - assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.rb")[0].chomp + assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.bukkits.rb")[0].chomp files_count = Dir[@migrations_path + "/*.rb"].length copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"}) @@ -2132,10 +2132,10 @@ if ActiveRecord::Base.connection.supports_migrations? sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy" sources[:omg] = MIGRATIONS_ROOT + "/to_copy2" ActiveRecord::Migration.copy(@migrations_path, sources) - assert File.exists?(@migrations_path + "/4_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/5_people_have_descriptions.rb") - assert File.exists?(@migrations_path + "/6_create_articles.rb") - assert File.exists?(@migrations_path + "/7_create_comments.rb") + assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb") + assert File.exists?(@migrations_path + "/6_create_articles.omg.rb") + assert File.exists?(@migrations_path + "/7_create_comments.omg.rb") files_count = Dir[@migrations_path + "/*.rb"].length ActiveRecord::Migration.copy(@migrations_path, sources) @@ -2150,10 +2150,10 @@ if ActiveRecord::Base.connection.supports_migrations? Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"}) - assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb") - expected = [@migrations_path + "/20100726101010_people_have_hobbies.rb", - @migrations_path + "/20100726101011_people_have_descriptions.rb"] + assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb") + expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb", + @migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"] assert_equal expected, copied.map(&:filename) files_count = Dir[@migrations_path + "/*.rb"].length @@ -2175,10 +2175,10 @@ if ActiveRecord::Base.connection.supports_migrations? Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do copied = ActiveRecord::Migration.copy(@migrations_path, sources) - assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb") - assert File.exists?(@migrations_path + "/20100726101012_create_articles.rb") - assert File.exists?(@migrations_path + "/20100726101013_create_comments.rb") + assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb") + assert File.exists?(@migrations_path + "/20100726101012_create_articles.omg.rb") + assert File.exists?(@migrations_path + "/20100726101013_create_comments.omg.rb") assert_equal 4, copied.length files_count = Dir[@migrations_path + "/*.rb"].length @@ -2195,8 +2195,8 @@ if ActiveRecord::Base.connection.supports_migrations? Time.travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"}) - assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.rb") + assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb") files_count = Dir[@migrations_path + "/*.rb"].length copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"}) @@ -2257,7 +2257,7 @@ if ActiveRecord::Base.connection.supports_migrations? copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) # remove origin comment - migration = @migrations_path + "/4_people_have_hobbies.rb" + migration = @migrations_path + "/4_people_have_hobbies.bukkits.rb" migration_source = File.read(migration).lines.to_a[1..-1].join File.open(migration, "w") { |f| f.write migration_source } @@ -2275,8 +2275,8 @@ if ActiveRecord::Base.connection.supports_migrations? Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"}) - assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb") + assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb") assert_equal 2, copied.length end ensure @@ -2290,8 +2290,8 @@ if ActiveRecord::Base.connection.supports_migrations? Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"}) - assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb") - assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb") + assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb") + assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb") assert_equal 2, copied.length end ensure -- cgit v1.2.3 From 929b2646b606e639a127bdd17f1aad169a26e2c5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 12:15:54 +0100 Subject: Compare migrations for copying only by name and scope --- activerecord/test/cases/migration_test.rb | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index c185efe1d6..b5fae3b7d3 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -2226,7 +2226,7 @@ if ActiveRecord::Base.connection.supports_migrations? clear end - def test_skip_is_not_called_if_migrations_are_identical + def test_skip_is_not_called_if_migrations_are_from_the_same_plugin @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps" @existing_migrations = Dir[@migrations_path + "/*.rb"] @@ -2244,31 +2244,6 @@ if ActiveRecord::Base.connection.supports_migrations? clear end - def test_skip_ignores_origin_comment - ActiveRecord::Base.timestamped_migrations = false - @migrations_path = MIGRATIONS_ROOT + "/valid" - @existing_migrations = Dir[@migrations_path + "/*.rb"] - - sources = ActiveSupport::OrderedHash.new - sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy" - - skipped = [] - on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" } - copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) - - # remove origin comment - migration = @migrations_path + "/4_people_have_hobbies.bukkits.rb" - migration_source = File.read(migration).lines.to_a[1..-1].join - File.open(migration, "w") { |f| f.write migration_source } - - ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip) - - assert_equal 2, copied.length - assert_equal 0, skipped.length - ensure - clear - end - def test_copying_migrations_to_non_existing_directory @migrations_path = MIGRATIONS_ROOT + "/non_existing" @existing_migrations = [] -- cgit v1.2.3 From f0b782d060f76647e36adc40fe5fe818ec8e2c66 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 20:07:29 +0100 Subject: Allow to filter migrations by passing a block Example: ActiveRecord::Migrator.migrate(path) do |migration| migration.name =~ /User/ end The above example will migrate only migrations with User in the name --- activerecord/test/cases/migration_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activerecord/test/cases/migration_test.rb') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index b5fae3b7d3..1e68911ab3 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1235,6 +1235,24 @@ if ActiveRecord::Base.connection.supports_migrations? assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) } end + def test_filtering_migrations + assert !Person.column_methods_hash.include?(:last_name) + assert !Reminder.table_exists? + + name_filter = lambda { |migration| migration.name == "ValidPeopleHaveLastNames" } + ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", &name_filter) + + Person.reset_column_information + assert Person.column_methods_hash.include?(:last_name) + assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) } + + ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter) + + Person.reset_column_information + assert !Person.column_methods_hash.include?(:last_name) + assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) } + end + class MockMigration < ActiveRecord::Migration attr_reader :went_up, :went_down def initialize -- cgit v1.2.3