Permalink
Browse files

Merge pull request #514 from haines/find_method

Fix `CollectionDecorator#find`
  • Loading branch information...
2 parents 18e27a5 + 29590a5 commit 94f66e4d89af480a123374c9ffbfadc890938378 @steveklabnik steveklabnik committed Apr 5, 2013
Showing with 10 additions and 6 deletions.
  1. +2 −1 lib/draper/collection_decorator.rb
  2. +8 −5 spec/draper/collection_decorator_spec.rb
View
3 lib/draper/collection_decorator.rb
@@ -48,7 +48,8 @@ def find(*args, &block)
if block_given?
decorated_collection.find(*args, &block)
else
- decorator_class.find(*args)
+ 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(source.find(*args))
end
end
View
13 spec/draper/collection_decorator_spec.rb
@@ -131,12 +131,15 @@ module Draper
end
context "without a block" do
- it "decorates Model.find" do
- item_decorator = Class.new
- decorator = CollectionDecorator.new([], with: item_decorator)
+ it "decorates source.find" do
+ source = []
+ found = stub(decorate: :decorated)
+ decorator = CollectionDecorator.new(source)
- item_decorator.should_receive(:find).with(1).and_return(:delegated)
- expect(decorator.find(1)).to be :delegated
+ source.should_receive(:find).and_return(found)
+ ActiveSupport::Deprecation.silence do
+ expect(decorator.find(1)).to be :decorated
+ end
end
end
end

0 comments on commit 94f66e4

Please sign in to comment.