Done with first pass of removing .decorate calls from CollectionDecorator
This commit is contained in:
parent
f60628eaee
commit
0686a073ac
|
@ -47,18 +47,6 @@ module Draper
|
||||||
@decorated_collection ||= object.map{|item| decorate_item(item)}
|
@decorated_collection ||= object.map{|item| decorate_item(item)}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delegated to the decorated collection when using the block form
|
|
||||||
# (`Enumerable#find`) or to the decorator class if not
|
|
||||||
# (`ActiveRecord::FinderMethods#find`)
|
|
||||||
def find(*args, &block)
|
|
||||||
if block_given?
|
|
||||||
decorated_collection.find(*args, &block)
|
|
||||||
else
|
|
||||||
ActiveSupport::Deprecation.warn("Using ActiveRecord's `find` on a CollectionDecorator is deprecated. Call `find` on a model, and then decorate the result", caller)
|
|
||||||
decorate_item(object.find(*args))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#<#{self.class.name} of #{decorator_class || "inferred decorators"} for #{object.inspect}>"
|
"#<#{self.class.name} of #{decorator_class || "inferred decorators"} for #{object.inspect}>"
|
||||||
end
|
end
|
||||||
|
|
|
@ -116,30 +116,6 @@ module Draper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#find" do
|
|
||||||
context "with a block" do
|
|
||||||
it "decorates Enumerable#find" do
|
|
||||||
decorator = CollectionDecorator.new([], :with => NullDecorator)
|
|
||||||
|
|
||||||
decorator.decorated_collection.should_receive(:find).and_return(:delegated)
|
|
||||||
expect(decorator.find{|p| p.title == "title"}).to be :delegated
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "without a block" do
|
|
||||||
it "decorates object.find" do
|
|
||||||
object = []
|
|
||||||
found = double(decorate: :decorated)
|
|
||||||
decorator = CollectionDecorator.new(object, :with => NullDecorator)
|
|
||||||
|
|
||||||
object.should_receive(:find).and_return(found)
|
|
||||||
ActiveSupport::Deprecation.silence do
|
|
||||||
expect(decorator.find(1)).to be :decorated
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#to_ary" do
|
describe "#to_ary" do
|
||||||
# required for `render @collection` in Rails
|
# required for `render @collection` in Rails
|
||||||
it "delegates to the decorated collection" do
|
it "delegates to the decorated collection" do
|
||||||
|
@ -202,7 +178,7 @@ module Draper
|
||||||
decorator = CollectionDecorator.new(object, :with => ProductDecorator)
|
decorator = CollectionDecorator.new(object, :with => ProductDecorator)
|
||||||
other = object.dup
|
other = object.dup
|
||||||
|
|
||||||
decorator << Product.new.decorate
|
decorator << ProductDecorator.new(Product.new)
|
||||||
expect(decorator == other).to be_falsey
|
expect(decorator == other).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -217,14 +193,6 @@ module Draper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when :with option was not given" do
|
|
||||||
it "returns a string representation of the collection decorator" do
|
|
||||||
decorator = CollectionDecorator.new(["a", "b", "c"], :with => NullDecorator)
|
|
||||||
|
|
||||||
expect(decorator.to_s).to eq '#<Draper::CollectionDecorator of inferred decorators for ["a", "b", "c"]>'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "for a custom subclass" do
|
context "for a custom subclass" do
|
||||||
it "uses the custom class name" do
|
it "uses the custom class name" do
|
||||||
decorator = ProductsDecorator.new([], :with => ProductDecorator)
|
decorator = ProductsDecorator.new([], :with => ProductDecorator)
|
||||||
|
|
Loading…
Reference in New Issue