Browse files

Fix failing spec in 1.8.7 and potential problem in 1.9...

"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...
1 parent 046f0c1 commit 3958111d3735cee4f3ffde60813fe624835cad2c @johndouthat committed Mar 22, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/searchlogic/active_record/scope.rb
@@ -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)

0 comments on commit 3958111

Please sign in to comment.