mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Prevent deprecation warning in Rails 4.0
Use `all` instead of `scoped` if possible. Closes #484
This commit is contained in:
parent
2de0592214
commit
47ee29c3b7
3 changed files with 7 additions and 3 deletions
|
@ -53,7 +53,8 @@ module Draper
|
|||
# @param [Hash] options
|
||||
# see {Decorator.decorate_collection}.
|
||||
def decorate(options = {})
|
||||
decorator_class(options[:namespace]).decorate_collection(scoped, options.reverse_merge(with: nil))
|
||||
collection = Rails::VERSION::MAJOR >= 4 ? all : scoped
|
||||
decorator_class(options[:namespace]).decorate_collection(collection, options.reverse_merge(with: nil))
|
||||
end
|
||||
|
||||
# Infers the decorator class to be used by {Decoratable#decorate} (e.g.
|
||||
|
|
|
@ -108,9 +108,11 @@ module Draper
|
|||
end
|
||||
|
||||
describe ".decorate" do
|
||||
let(:scoping_method) { Rails::VERSION::MAJOR >= 4 ? :all : :scoped }
|
||||
|
||||
it "calls #decorate_collection on .decorator_class" do
|
||||
scoped = [Product.new]
|
||||
Product.stub scoped: scoped
|
||||
Product.stub scoping_method => scoped
|
||||
|
||||
Product.decorator_class.should_receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
|
||||
expect(Product.decorate).to be :decorated_collection
|
||||
|
@ -118,7 +120,7 @@ module Draper
|
|||
|
||||
it "accepts options" do
|
||||
options = {with: ProductDecorator, context: {some: "context"}}
|
||||
Product.stub scoped: []
|
||||
Product.stub scoping_method => []
|
||||
|
||||
Product.decorator_class.should_receive(:decorate_collection).with([], options)
|
||||
Product.decorate(options)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'bundler/setup'
|
||||
require 'draper'
|
||||
require 'rails/version'
|
||||
require 'action_controller'
|
||||
require 'action_controller/test_case'
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue