Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have_scope with options always fails (4.0.0.alpha4, Rails 3.0.10) #27

Open
vits opened this issue Aug 19, 2011 · 0 comments
Open

have_scope with options always fails (4.0.0.alpha4, Rails 3.0.10) #27

vits opened this issue Aug 19, 2011 · 0 comments

Comments

@vits
Copy link

vits commented Aug 19, 2011

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant