aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-08-06 11:31:05 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-08-06 11:31:05 -0700
commit12b3eca420c2de46d34a363c91b2263d366f4d6c (patch)
tree35b900fcfd75f0da9510acd0ebad3bb12ad03a84
parent62bb83d0a27e83b0800e67676cfa0d0c47453f8e (diff)
downloadrails-12b3eca420c2de46d34a363c91b2263d366f4d6c.tar.gz
rails-12b3eca420c2de46d34a363c91b2263d366f4d6c.tar.bz2
rails-12b3eca420c2de46d34a363c91b2263d366f4d6c.zip
do not rely on arel class structure
-rw-r--r--activerecord/lib/active_record/relation.rb4
-rw-r--r--activerecord/test/cases/method_scoping_test.rb7
2 files changed, 10 insertions, 1 deletions
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