From 5501b99a19a2a67a9a920fd3c7bff071a2ecf058 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 1 May 2009 14:58:10 +0100 Subject: Ensure ActiveRecord::Base.connection_pool.with_connection creates a new connection only when needed [#1752 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/pooled_connections_test.rb | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index 2649a9358a..bbd943fc6e 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -1,4 +1,6 @@ require "cases/helper" +require "models/project" +require "timeout" class PooledConnectionsTest < ActiveRecord::TestCase def setup @@ -89,6 +91,33 @@ class PooledConnectionsTest < ActiveRecord::TestCase ensure ActiveRecord::Base.connection_handler = old_handler end + + def test_with_connection_nesting_safety + ActiveRecord::Base.establish_connection(@connection.merge({:pool => 1, :wait_timeout => 0.1})) + + before_count = Project.count + + add_record('one') + + ActiveRecord::Base.connection.transaction do + add_record('two') + # Have another thread try to screw up the transaction + Thread.new do + raise ActiveRecord::Rollback + ActiveRecord::Base.connection_pool.release_connection + end.join rescue nil + add_record('three') + end + + after_count = Project.count + assert_equal 3, after_count - before_count + end + + private + + def add_record(name) + ActiveRecord::Base.connection_pool.with_connection { Project.create! :name => name } + end end unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name class AllowConcurrencyDeprecatedTest < ActiveRecord::TestCase -- cgit v1.2.3 From 60a6284a461afda5911ecadf3a147d4da6ed5d22 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 1 May 2009 16:00:09 +0100 Subject: Tests should use ActiveRecord::Base.connection.rollback_db_transaction to rollback a transaction Signed-off-by: Pratik Naik --- activerecord/test/cases/pooled_connections_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index bbd943fc6e..bb9013c2a1 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -103,7 +103,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase add_record('two') # Have another thread try to screw up the transaction Thread.new do - raise ActiveRecord::Rollback + ActiveRecord::Base.connection.rollback_db_transaction ActiveRecord::Base.connection_pool.release_connection end.join rescue nil add_record('three') -- cgit v1.2.3 From db0bfe4ede3cdfc2e4ccdb2a89525a914e6d0913 Mon Sep 17 00:00:00 2001 From: Alexander Podgorbunsky Date: Thu, 26 Mar 2009 15:00:12 +0300 Subject: Default scope :order should be overridden by named scopes. [#2346 state:committed] Signed-off-by: Jeremy Kemper --- activerecord/test/cases/method_scoping_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 2165d2f7e8..c479859ee0 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -628,9 +628,9 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal expected, received end - def test_named_scope - expected = Developer.find(:all, :order => 'salary DESC, name DESC').collect { |dev| dev.salary } - received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.salary } + def test_named_scope_overwrites_default + expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.name } + received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.name } assert_equal expected, received end -- cgit v1.2.3 From 99c103be1165da9c8299bc0977188ecf167e06a5 Mon Sep 17 00:00:00 2001 From: Ruy Asan Date: Fri, 1 May 2009 13:09:29 -0700 Subject: Fixed bug with polymorphic has_one :as pointing to an STI record [#2594 state:committed] Signed-off-by: Jeremy Kemper --- .../test/cases/associations/has_one_associations_test.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 1ddb3f49bf..3984945f9f 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -2,9 +2,11 @@ require "cases/helper" require 'models/developer' require 'models/project' require 'models/company' +require 'models/sponsor' +require 'models/organization' class HasOneAssociationsTest < ActiveRecord::TestCase - fixtures :accounts, :companies, :developers, :projects, :developers_projects + fixtures :accounts, :companies, :developers, :projects, :developers_projects, :organizations, :sponsors def setup Account.destroyed_account_ids.clear @@ -306,4 +308,9 @@ class HasOneAssociationsTest < ActiveRecord::TestCase Firm.find(@firm.id, :include => :account).save! end end + + def test_polymorphic_sti + assert_equal organizations(:sponsorable), sponsors(:org_sponsor).sponsorable + assert_equal sponsors(:org_sponsor), organizations(:sponsorable).sponsor + end end -- cgit v1.2.3