From 3958111d3735cee4f3ffde60813fe624835cad2c Mon Sep 17 00:00:00 2001 From: "John F. Douthat" Date: Thu, 22 Mar 2012 06:55:21 -0500 Subject: [PATCH] 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. --- lib/searchlogic/active_record/scope.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/searchlogic/active_record/scope.rb b/lib/searchlogic/active_record/scope.rb index 58a98ade..ff148268 100644 --- a/lib/searchlogic/active_record/scope.rb +++ b/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) super end eval + end) end end