Wrap the .all method to return a DecoratedEnumerableProxy
This commit is contained in:
parent
173c705422
commit
3670ef76ee
|
@ -95,6 +95,14 @@ module Draper
|
||||||
def self.decorate(input, context = {})
|
def self.decorate(input, context = {})
|
||||||
input.respond_to?(:each) ? Draper::DecoratedEnumerableProxy.new(input, self, context) : new(input, context)
|
input.respond_to?(:each) ? Draper::DecoratedEnumerableProxy.new(input, self, context) : new(input, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Fetch all instances of the decorated class and decorate them.
|
||||||
|
#
|
||||||
|
# @param [Object] context (optional)
|
||||||
|
# @return [Draper::DecoratedEnumerableProxy]
|
||||||
|
def self.all(context = {})
|
||||||
|
Draper::DecoratedEnumerableProxy.new(model_class.all, self, context)
|
||||||
|
end
|
||||||
|
|
||||||
# Access the helpers proxy to call built-in and user-defined
|
# Access the helpers proxy to call built-in and user-defined
|
||||||
# Rails helpers. Aliased to `.h` for convinience.
|
# Rails helpers. Aliased to `.h` for convinience.
|
||||||
|
|
|
@ -237,6 +237,16 @@ describe Draper::Base do
|
||||||
subject_one.should_not == subject_two
|
subject_one.should_not == subject_two
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#all' do
|
||||||
|
it "should return a decorated collection" do
|
||||||
|
ProductDecorator.all.first.should be_instance_of ProductDecorator
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should accept a context" do
|
||||||
|
collection = ProductDecorator.all(:admin)
|
||||||
|
collection.first.context.should == :admin
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "a sample usage with denies" do
|
describe "a sample usage with denies" do
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
include Draper::ModelSupport
|
include Draper::ModelSupport
|
||||||
|
|
||||||
|
def self.all
|
||||||
|
[Product.new, Product.new]
|
||||||
|
end
|
||||||
|
|
||||||
def self.scoped
|
def self.scoped
|
||||||
[Product.new]
|
[Product.new]
|
||||||
|
|
Loading…
Reference in New Issue