Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix `CollectionDecorator#find` #514

Merged
merged 1 commit into from

2 participants

@haines
Collaborator

Fixes, and deprecates, the use of ActiveRecord's find method on a collection decorator.

Closes #509

@haines haines Fix `CollectionDecorator#find`
Deprecates the use of ActiveRecord's `find` method on a collection
decorator.

Closes #509
29590a5
@steveklabnik steveklabnik merged commit 94f66e4 into drapergem:master

1 check passed

Details default The Travis build passed
@steveklabnik
Owner

<3

@haines haines deleted the haines:find_method branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2013
  1. @haines

    Fix `CollectionDecorator#find`

    haines authored
    Deprecates the use of ActiveRecord's `find` method on a collection
    decorator.
    
    Closes #509
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.