remarkable-rb / remarkable

Simplifying tests!
http://www.nomedojogo.com/category/remarkable/
MIT License
121 stars 64 forks source link

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

Open vits opened 13 years ago

vits commented 13 years ago

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