1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge pull request #470 from haines/sti

Support STI in Decoratable.decorate
This commit is contained in:
Steve Klabnik 2013-02-12 09:23:25 -08:00
commit 7802d97446
3 changed files with 4 additions and 4 deletions

View file

@ -52,7 +52,7 @@ module Draper
# @param [Hash] options # @param [Hash] options
# see {Decorator.decorate_collection}. # see {Decorator.decorate_collection}.
def decorate(options = {}) def decorate(options = {})
decorator_class.decorate_collection(self.scoped, options) decorator_class.decorate_collection(scoped, options.reverse_merge(with: nil))
end end
# Infers the decorator class to be used by {Decoratable#decorate} (e.g. # Infers the decorator class to be used by {Decoratable#decorate} (e.g.

View file

@ -112,12 +112,12 @@ module Draper
scoped = [Product.new] scoped = [Product.new]
Product.stub scoped: scoped Product.stub scoped: scoped
Product.decorator_class.should_receive(:decorate_collection).with(scoped, {}).and_return(:decorated_collection) Product.decorator_class.should_receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
expect(Product.decorate).to be :decorated_collection expect(Product.decorate).to be :decorated_collection
end end
it "accepts options" do it "accepts options" do
options = {context: {some: "context"}} options = {with: ProductDecorator, context: {some: "context"}}
Product.stub scoped: [] Product.stub scoped: []
Product.decorator_class.should_receive(:decorate_collection).with([], options) Product.decorator_class.should_receive(:decorate_collection).with([], options)

View file

@ -6,7 +6,7 @@ describe Rails::Generators::DecoratorGenerator do
destination File.expand_path("../tmp", __FILE__) destination File.expand_path("../tmp", __FILE__)
before { prepare_destination } before { prepare_destination }
#after(:all) { FileUtils.rm_rf destination_root } after(:all) { FileUtils.rm_rf destination_root }
describe "the generated decorator" do describe "the generated decorator" do
subject { file("app/decorators/your_model_decorator.rb") } subject { file("app/decorators/your_model_decorator.rb") }