diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 7 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/postgresql.drop.sql | 1 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/postgresql.sql | 5 | ||||
-rwxr-xr-x | activerecord/test/fixtures_test.rb | 24 | ||||
-rw-r--r-- | activerecord/test/pk_test.rb | 2 |
6 files changed, 35 insertions, 6 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index bfe797b167..ff687fcd77 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -710,7 +710,7 @@ end class BelongsToAssociationsTest < Test::Unit::TestCase fixtures :accounts, :companies, :developers, :projects, :topics, - :developers_projects + :developers_projects, :computers, :authors, :posts def test_belongs_to Client.find(3).firm.name @@ -832,7 +832,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase end def test_field_name_same_as_foreign_key - computer = Computer.find 1 + computer = Computer.find(1) assert_not_nil computer.developer, ":foreign key == attribute didn't lock up" # ' end @@ -939,7 +939,10 @@ class BelongsToAssociationsTest < Test::Unit::TestCase def test_association_assignment_sticks post = Post.find(:first) + author1, author2 = Author.find(:all, :limit => 2) + assert_not_nil author1 + assert_not_nil author2 # make sure the association is loaded post.author diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 28e7f28f21..ef65b9859c 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -553,7 +553,7 @@ class BasicsTest < Test::Unit::TestCase end def test_mass_assignment_accessible - reply = Reply.new("title" => "hello", "content" => "world", "approved" => false) + reply = Reply.new("title" => "hello", "content" => "world", "approved" => true) reply.save assert reply.approved? diff --git a/activerecord/test/fixtures/db_definitions/postgresql.drop.sql b/activerecord/test/fixtures/db_definitions/postgresql.drop.sql index d8d41cf974..7919d13a7f 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.drop.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.drop.sql @@ -1,5 +1,6 @@ DROP TABLE accounts; DROP TABLE companies; +DROP SEQUENCE companies_nonstd_seq; DROP TABLE topics; DROP TABLE developers; DROP TABLE projects; diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql index feea20b827..67f3673734 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.sql @@ -6,8 +6,10 @@ CREATE TABLE accounts ( ); SELECT setval('accounts_id_seq', 100); +CREATE SEQUENCE companies_nonstd_seq START 101; + CREATE TABLE companies ( - id serial, + id integer DEFAULT nextval('companies_nonstd_seq'), "type" character varying(50), "ruby_type" character varying(50), firm_id integer, @@ -16,7 +18,6 @@ CREATE TABLE companies ( rating integer default 1, PRIMARY KEY (id) ); -SELECT setval('companies_id_seq', 100); CREATE TABLE developers_projects ( developer_id integer NOT NULL, diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb index ae45a9f251..e3a37b99a3 100755 --- a/activerecord/test/fixtures_test.rb +++ b/activerecord/test/fixtures_test.rb @@ -168,6 +168,30 @@ class FixturesTest < Test::Unit::TestCase end end end + + if Account.connection.respond_to?(:reset_pk_sequence!) + def test_resets_to_min_pk + Account.delete_all + Account.connection.reset_pk_sequence!(Account.table_name) + + one = Account.new(:credit_limit => 50) + one.save! + assert_equal 1, one.id + 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 + 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 + end + end end diff --git a/activerecord/test/pk_test.rb b/activerecord/test/pk_test.rb index d77982df1b..0ee27f969b 100644 --- a/activerecord/test/pk_test.rb +++ b/activerecord/test/pk_test.rb @@ -53,7 +53,7 @@ class PrimaryKeysTest < Test::Unit::TestCase subscriber.id = "jdoe" assert_equal("jdoe", subscriber.id) subscriber.name = "John Doe" - assert_nothing_raised{ subscriber.save } + assert_nothing_raised { subscriber.save! } subscriberReloaded = Subscriber.find("jdoe") assert_equal("John Doe", subscriberReloaded.name) |