Permalink
Browse files

move fake ActiveRecord::Relation to helper, use #kind_of instead of c…

…omparing to string
  • Loading branch information...
1 parent 0f02556 commit c46b0fd17d59e1d8c0d303fb8d614dcdf6d4fe6a @jhsu jhsu committed Aug 23, 2012
Showing with 9 additions and 5 deletions.
  1. +3 −2 lib/draper/base.rb
  2. +1 −1 lib/draper/decorated_enumerable_proxy.rb
  3. +0 −2 spec/draper/base_spec.rb
  4. +5 −0 spec/spec_helper.rb
View
@@ -256,7 +256,7 @@ def method_missing(method, *args, &block)
if model.respond_to?(method)
self.class.send :define_method, method do |*args, &blokk|
result = model.send method, *args, &blokk
- if result.class.name == "ActiveRecord::Relation"
+ if defined?(ActiveRecord) && result.kind_of?(ActiveRecord::Relation)
self.class.new(model,self.options)
else
result
@@ -275,7 +275,8 @@ def method_missing(method, *args, &block)
def self.method_missing(method, *args, &block)
model_result = model_class.send(method, *args, &block)
- if model_result.is_a?(model_class) || model_result.class.name == 'ActiveRecord::Relation'
+ if model_result.kind_of?(model_class) ||
+ (defined?(ActiveRecord) && model_result.kind_of?(ActiveRecord::Relation))
self.decorate(model_result, :context => args.dup.extract_options!)
else
model_result
@@ -28,7 +28,7 @@ def method_missing (method, *args, &block)
if @wrapped_collection.respond_to?(method)
self.class.send :define_method, method do |*args, &blokk|
scoped_result = @wrapped_collection.send(method, *args, &block)
- if scoped_result.class.name == "ActiveRecord::Relation"
+ if defined?(ActiveRecord) && scoped_result.kind_of?(ActiveRecord::Relation)
self.class.new(scoped_result, @klass, @options)
else
scoped_result
@@ -51,15 +51,13 @@
end
it "returns a Decorator when a scope is called on decorated object" do
- class ActiveRecord::Relation; end
proxy = ProductDecorator.new(source)
klass = proxy.model.class
klass.class_eval { def some_scope ; ActiveRecord::Relation.new ; end }
proxy.some_scope.should be_instance_of(proxy.class)
end
it "returns a Decorator when a scope is called on the decorator" do
- class ActiveRecord::Relation; end
proxy = ProductDecorator
klass = source.class
klass.class_eval { def self.some_scope ; ActiveRecord::Relation.new ; end }
View
@@ -34,3 +34,8 @@ class Base
Draper::System.setup(self)
end
end
+
+module ActiveRecord
+ class Relation
+ end
+end

0 comments on commit c46b0fd

Please sign in to comment.