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
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: