Return self from CollectionDecorator#replace

Closes #516
This commit is contained in:
Andrew Haines 2013-04-15 22:46:19 +01:00
parent e20604ac02
commit 5b5c9f45d9
2 changed files with 21 additions and 0 deletions

View File

@ -74,6 +74,11 @@ module Draper
end
alias_method :is_a?, :kind_of?
def replace(other)
decorated_collection.replace(other)
self
end
protected
# @return the collection being decorated.

View File

@ -278,5 +278,21 @@ module Draper
end
end
describe "#replace" do
it "replaces the decorated collection" do
decorator = CollectionDecorator.new([Product.new])
replacement = [:foo, :bar]
decorator.replace replacement
expect(decorator).to match_array replacement
end
it "returns itself" do
decorator = CollectionDecorator.new([Product.new])
expect(decorator.replace([:foo, :bar])).to be decorator
end
end
end
end