1
0
Fork 0
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:
Andrew Haines 2013-03-03 11:14:18 +00:00
parent 2de0592214
commit 47ee29c3b7
3 changed files with 7 additions and 3 deletions

View file

@ -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.

View file

@ -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)

View file

@ -1,5 +1,6 @@
require 'bundler/setup'
require 'draper'
require 'rails/version'
require 'action_controller'
require 'action_controller/test_case'