You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
have_scope given any options always fails with something like
Failure/Error: it { should have_scope(:ordered).order('name') }
Expected :ordered when called on User scope to SELECT "users".* FROM "users" ORDER BY name, got SELECT "users".* FROM "users" ORDER BY name
i.e. expected and real SQL queries are the same. This is due to fact that comparison of two similarly created arel objects returns false. I can test this from rails console. Given class
class User < ActiveRecord::Base
scope :ordered, order('name')
end
from console
real = User.ordered.arel
expected = User.scoped.send(:order, 'name').arel
real == expected #=> false
real.to_sql == expected.to_sql #=> true
Changing options_match? to compare to_sql values fixes problem:
def options_match?
@options.empty? || @scope_object.arel.to_sql == arel(subject_class, @options.except(:with)).to_sql
end
The text was updated successfully, but these errors were encountered:
webgago
added a commit
to webgago/remarkable
that referenced
this issue
Aug 25, 2011
have_scope given any options always fails with something like
i.e. expected and real SQL queries are the same. This is due to fact that comparison of two similarly created arel objects returns false. I can test this from rails console. Given class
from console
Changing options_match? to compare to_sql values fixes problem:
The text was updated successfully, but these errors were encountered: