mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
move fake ActiveRecord::Relation to helper, use #kind_of instead of comparing to string
This commit is contained in:
parent
0f02556cc8
commit
c46b0fd17d
4 changed files with 9 additions and 5 deletions
|
@ -256,7 +256,7 @@ module Draper
|
|||
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 @@ module Draper
|
|||
|
||||
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 @@ module Draper
|
|||
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,7 +51,6 @@ describe Draper::Base do
|
|||
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 }
|
||||
|
@ -59,7 +58,6 @@ describe Draper::Base do
|
|||
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 }
|
||||
|
|
|
@ -34,3 +34,8 @@ module ActionController
|
|||
Draper::System.setup(self)
|
||||
end
|
||||
end
|
||||
|
||||
module ActiveRecord
|
||||
class Relation
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue