rails/rails — Issue #3923: scope with lambda duplicates where and order values
Author: amatsuda
Created: 2011-12-09 22:07:09+00:00
State: open

Calling a named_scope with `lambda` doubles all existing finder_options since 788bd30859f3f21184defd240c3d32f179515225.
For example, having the following model code

```ruby
class User < ActiveRecord::Base
scope :foo, lambda {scoped}
end
```

every time we chain the `foo` scope, it doubles `where_values` and `order_values`.

```ruby
> User.where('1=1').foo.where_values
=> ["1=1", "1=1"]
> User.where('1=1').foo.foo.where_values
=> ["1=1", "1=1", "1=1", "1=1"]
> User.order(:id).foo.foo.foo.order_values
=> [:id, :id, :id, :id, :id, :id, :id, :id]
```

Is this an intentional specification change or a regression?
I think this is a bug because these values are considered to be a public API so we could use them for assertions like this.
https://github.com/amatsuda/kaminari/blob/master/spec/models/scopes_spec.rb#L49