aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb9
-rw-r--r--activerecord/lib/active_record/relation.rb4
-rw-r--r--activerecord/test/cases/method_scoping_test.rb7
-rw-r--r--activerecord/test/cases/relations_test.rb18
4 files changed, 30 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 9d0251dda3..02a8f4e214 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -103,8 +103,8 @@ module ActiveRecord
# Signal that the thread is finished with the current connection.
# #release_connection releases the connection-thread association
# and returns the connection to the pool.
- def release_connection
- conn = @reserved_connections.delete(current_connection_id)
+ def release_connection(with_id = current_connection_id)
+ conn = @reserved_connections.delete(with_id)
checkin conn if conn
end
@@ -112,10 +112,11 @@ module ActiveRecord
# exists checkout a connection, yield it to the block, and checkin the
# connection when finished.
def with_connection
- fresh_connection = true unless @reserved_connections[current_connection_id]
+ connection_id = current_connection_id
+ fresh_connection = true unless @reserved_connections[connection_id]
yield connection
ensure
- release_connection if fresh_connection
+ release_connection(connection_id) if fresh_connection
end
# Returns true if a connection has already been opened.
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index deacced627..30be723291 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -319,7 +319,9 @@ module ActiveRecord
def scope_for_create
@scope_for_create ||= begin
@create_with_value || Hash[
- @where_values.grep(Arel::Predicates::Equality).map { |where|
+ @where_values.find_all { |w|
+ w.respond_to?(:operator) && w.operator == :==
+ }.map { |where|
[where.operand1.name,
where.operand2.respond_to?(:value) ?
where.operand2.value : where.operand2]
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb
index 774b50e2e4..5256ab8d11 100644
--- a/activerecord/test/cases/method_scoping_test.rb
+++ b/activerecord/test/cases/method_scoping_test.rb
@@ -208,6 +208,13 @@ class MethodScopingTest < ActiveRecord::TestCase
end
end
+ def test_scope_for_create_only_uses_equal
+ table = VerySpecialComment.arel_table
+ relation = VerySpecialComment.scoped
+ relation.where_values << table[:id].not_eq(1)
+ assert_equal({:type => "VerySpecialComment"}, relation.send(:scope_for_create))
+ end
+
def test_scoped_create
new_comment = nil
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index c9313fe7b6..ac7b501bb7 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -192,11 +192,23 @@ class RelationTest < ActiveRecord::TestCase
end
end
- def test_respond_to_private_arel_methods
+ def test_respond_to_delegates_to_relation
relation = Topic.scoped
+ fake_arel = Struct.new(:responds) {
+ def respond_to? method, access = false
+ responds << [method, access]
+ end
+ }.new []
+
+ relation.extend(Module.new { attr_accessor :arel })
+ relation.arel = fake_arel
+
+ relation.respond_to?(:matching_attributes)
+ assert_equal [:matching_attributes, false], fake_arel.responds.first
- assert ! relation.respond_to?(:matching_attributes)
- assert relation.respond_to?(:matching_attributes, true)
+ fake_arel.responds = []
+ relation.respond_to?(:matching_attributes, true)
+ assert_equal [:matching_attributes, true], fake_arel.responds.first
end
def test_respond_to_dynamic_finders