File tree Expand file tree Collapse file tree 3 files changed +8
-1
lines changed
lib/active_record/scoping Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ def scope(name, scope_options = {})
177177 extension = Module . new ( &Proc . new ) if block_given?
178178
179179 scope_proc = lambda do |*args |
180- options = scope_options . respond_to? ( :call ) ? scope_options . call ( *args ) : scope_options
180+ options = scope_options . respond_to? ( :call ) ? unscoped { scope_options . call ( *args ) } : scope_options
181181 options = scoped . apply_finder_options ( options ) if options . is_a? ( Hash )
182182
183183 relation = scoped . merge ( options )
Original file line number Diff line number Diff line change @@ -337,6 +337,11 @@ def test_size_should_use_length_when_results_are_loaded
337337 end
338338 end
339339
340+ def test_should_not_duplicates_where_values
341+ where_values = Topic . where ( "1=1" ) . scope_with_lambda . where_values
342+ assert_equal [ "1=1" ] , where_values
343+ end
344+
340345 def test_chaining_with_duplicate_joins
341346 join = "INNER JOIN comments ON comments.post_id = posts.id"
342347 post = Post . find ( 1 )
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ class Topic < ActiveRecord::Base
88 scope :approved , :conditions => { :approved => true }
99 scope :rejected , :conditions => { :approved => false }
1010
11+ scope :scope_with_lambda , lambda { scoped }
12+
1113 scope :by_lifo , :conditions => { :author_name => 'lifo' }
1214
1315 scope :approved_as_hash_condition , :conditions => { :topics => { :approved => true } }
You can’t perform that action at this time.
0 commit comments