From 8987cda2bb64fe289f7a28b2833a2786cfbc8259 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 4 Mar 2011 22:29:40 +0000 Subject: When preloading has_and_belongs_to_many associations, we should only instantiate one AR object per actual record in the database. (Even when IM is off.) --- activerecord/test/cases/associations/eager_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 26808ae931..48406a9b98 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -525,6 +525,22 @@ class EagerAssociationTest < ActiveRecord::TestCase assert posts[1].categories.include?(categories(:general)) end + # This is only really relevant when the identity map is off. Since the preloader for habtm + # gets raw row hashes from the database and then instantiates them, this test ensures that + # it only instantiates one actual object per record from the database. + def test_has_and_belongs_to_many_should_not_instantiate_same_records_multiple_times + welcome = posts(:welcome) + categories = Category.includes(:posts) + + general = categories.find { |c| c == categories(:general) } + technology = categories.find { |c| c == categories(:technology) } + + post1 = general.posts.to_a.find { |p| p == posts(:welcome) } + post2 = technology.posts.to_a.find { |p| p == posts(:welcome) } + + assert_equal post1.object_id, post2.object_id + end + def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers posts = authors(:david).posts.find(:all, :include => :comments, -- cgit v1.2.3 From 3b10b8a201d9fbef831be81d7a4bc9b82c75a6f4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 Mar 2011 01:10:00 +0100 Subject: implements ActiveRecord::Base.connection_config to be able to check the configuration of the current connection at runtime --- activerecord/test/cases/pooled_connections_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index 6269437b14..379cf5b44e 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -94,6 +94,11 @@ class PooledConnectionsTest < ActiveRecord::TestCase ActiveRecord::Base.connection_handler = old_handler end + def test_connection_config + ActiveRecord::Base.establish_connection(@connection) + assert_equal @connection, ActiveRecord::Base.connection_config + end + def test_with_connection_nesting_safety ActiveRecord::Base.establish_connection(@connection.merge({:pool => 1, :wait_timeout => 0.1})) -- cgit v1.2.3 From a1b4d8e7b277ddcfba6c31cbb9245025123cf04b Mon Sep 17 00:00:00 2001 From: "R.T. Lechow" Date: Thu, 3 Mar 2011 23:54:58 -0500 Subject: Active Record typos. --- activerecord/test/cases/base_test.rb | 4 ++-- activerecord/test/cases/identity_map_test.rb | 4 ++-- activerecord/test/cases/migration_test.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index b62b5003e4..d03fc68a11 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -832,12 +832,12 @@ class BasicsTest < ActiveRecord::TestCase def test_dup_of_saved_object_marks_as_dirty_only_changed_attributes developer = Developer.create! :name => 'Bjorn' - assert !developer.name_changed? # both attributes of saved object should be threated as not changed + assert !developer.name_changed? # both attributes of saved object should be treated as not changed assert !developer.salary_changed? cloned_developer = developer.dup assert cloned_developer.name_changed? # ... but on cloned object should be - assert !cloned_developer.salary_changed? # ... BUT salary has non-nil default which should be threated as not changed on cloned instance + assert !cloned_developer.salary_changed? # ... BUT salary has non-nil default which should be treated as not changed on cloned instance end def test_bignum diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb index d98638ab73..399d6c26df 100644 --- a/activerecord/test/cases/identity_map_test.rb +++ b/activerecord/test/cases/identity_map_test.rb @@ -295,7 +295,7 @@ class IdentityMapTest < ActiveRecord::TestCase end ############################################################################## - # Behaviour releated to saving failures + # Behaviour related to saving failures ############################################################################## def test_reload_object_if_save_failed @@ -338,7 +338,7 @@ class IdentityMapTest < ActiveRecord::TestCase end ############################################################################## - # Behaviour of readonly, forzen, destroyed + # Behaviour of readonly, frozen, destroyed ############################################################################## def test_find_using_identity_map_respects_readonly_when_loading_associated_object_first diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 9d7c49768b..bf7565a0d0 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -543,7 +543,7 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "I was born ....", bob.bio assert_equal 18, bob.age - # Test for 30 significent digits (beyond the 16 of float), 10 of them + # Test for 30 significant digits (beyond the 16 of float), 10 of them # after the decimal place. unless current_adapter?(:SQLite3Adapter) @@ -1975,7 +1975,7 @@ if ActiveRecord::Base.connection.supports_migrations? t.integer :age end - # Adding an index fires a query everytime to check if an index already exists or not + # Adding an index fires a query every time to check if an index already exists or not assert_queries(3) do with_bulk_change_table do |t| t.index :username, :unique => true, :name => :awesome_username_index -- cgit v1.2.3