diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/fixtures_test.rb | 48 | ||||
-rw-r--r-- | activerecord/test/migration_test.rb | 8 |
3 files changed, 43 insertions, 19 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index f64821361f..7be6441f1d 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -839,10 +839,10 @@ class BasicsTest < Test::Unit::TestCase def test_column_name_properly_quoted col_record = ColumnName.new col_record.references = 40 - col_record.save + assert col_record.save col_record.references = 41 - col_record.save - c2 = ColumnName.find(col_record.id) + assert col_record.save + assert_not_nil c2 = ColumnName.find(col_record.id) assert_equal(41, c2.references) end diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb index 888d743078..41fc666945 100755 --- a/activerecord/test/fixtures_test.rb +++ b/activerecord/test/fixtures_test.rb @@ -173,27 +173,45 @@ end if Account.connection.respond_to?(:reset_pk_sequence!) class FixturesResetPkSequenceTest < Test::Unit::TestCase fixtures :accounts + fixtures :companies - def test_resets_to_min_pk - Account.delete_all - Account.connection.reset_pk_sequence!(Account.table_name) + def setup + @instances = [Account.new(:credit_limit => 50), Company.new(:name => 'RoR Consulting')] + end + + def test_resets_to_min_pk_with_specified_pk_and_sequence + @instances.each do |instance| + model = instance.class + model.delete_all + model.connection.reset_pk_sequence!(model.table_name, model.primary_key, model.sequence_name) - one = Account.new(:credit_limit => 50) - one.save! - assert_equal 1, one.id + instance.save! + assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed." + end end - def test_create_fixtures_resets_sequences - # create_fixtures performs reset_pk_sequence! - max_id = create_fixtures('accounts').inject(0) do |max_id, (name, fixture)| - fixture_id = fixture['id'].to_i - fixture_id > max_id ? fixture_id : max_id + def test_resets_to_min_pk_with_default_pk_and_sequence + @instances.each do |instance| + model = instance.class + model.delete_all + model.connection.reset_pk_sequence!(model.table_name) + + instance.save! + assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed." end + end - # Clone the last fixture to check that it gets the next greatest id. - another = Account.new(:credit_limit => 1200) - another.save! - assert_equal max_id + 1, another.id + def test_create_fixtures_resets_sequences + @instances.each do |instance| + max_id = create_fixtures(instance.class.table_name).inject(0) do |max_id, (name, fixture)| + fixture_id = fixture['id'].to_i + fixture_id > max_id ? fixture_id : max_id + end + + # Clone the last fixture to check that it gets the next greatest id. + instance.save! + assert_equal max_id + 1, instance.id, "Sequence reset for #{instance.class.table_name} failed." + end end end end diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index 9c5c2285b7..3fa680b94a 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -362,6 +362,9 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.table_name_suffix = "" Reminder.reset_table_name assert_equal "schema_info", ActiveRecord::Migrator.schema_info_table_name + ensure + ActiveRecord::Base.table_name_prefix = "" + ActiveRecord::Base.table_name_suffix = "" end def test_proper_table_name @@ -398,17 +401,20 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.table_name_prefix = 'prefix_' ActiveRecord::Base.table_name_suffix = '_suffix' Reminder.reset_table_name + Reminder.reset_sequence_name WeNeedReminders.up assert Reminder.create("content" => "hello world", "remind_at" => Time.now) assert_equal "hello world", Reminder.find(:first).content WeNeedReminders.down assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) } + ensure ActiveRecord::Base.table_name_prefix = '' ActiveRecord::Base.table_name_suffix = '' Reminder.reset_table_name + Reminder.reset_sequence_name end - + def test_migrator_with_duplicates assert_raises(ActiveRecord::DuplicateMigrationVersionError) do ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_duplicate/', nil) |