Skip to content

Commit

Permalink
Fix failing spec in 1.8.7 and potential problem in 1.9...
Browse files Browse the repository at this point in the history
"should inherit alias scopes from superclasses" creates an anonymous subclass for its test. Anonymous classes return nil for .name by default.
It passed in 1.9 because Searchlogic::ActiveRecord::Scope#scopes's monkey patched `include?` was inadvertantly calling .respond_to?(key) on `result` instead of the AR class. In 1.8.7, it resulted in a syntax error `unexpected '.', expecting kEND` in `.respond_to?(key)` because name was nil. So, instead of looking up the AR class by name, now a reference to the class is passed in.
  • Loading branch information
johndouthat committed Mar 22, 2012
1 parent 046f0c1 commit 3958111
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/searchlogic/active_record/scope.rb
Expand Up @@ -8,14 +8,21 @@ module ActiveRecord
module Scope
def scopes
read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {}.tap do |h|

class << h
attr_accessor :active_record_class
end
h.active_record_class = self

h.instance_eval <<-eval
def include?(key)
result = super
return result if result
#{name}.respond_to?(key)
active_record_class.respond_to?(key)
super
end
eval

end)
end
end
Expand Down

0 comments on commit 3958111

Please sign in to comment.