Permalink
Browse files

Prevent deprecation warning in Rails 4.0

Use `all` instead of `scoped` if possible. Closes #484
  • Loading branch information...
haines committed Mar 3, 2013
1 parent 2de0592 commit 47ee29c3b739eee3fc28a561432ad2363c14813c
Showing with 7 additions and 3 deletions.
  1. +2 −1 lib/draper/decoratable.rb
  2. +4 −2 spec/draper/decoratable_spec.rb
  3. +1 −0 spec/spec_helper.rb
@@ -53,7 +53,8 @@ module ClassMethods
# @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,17 +108,19 @@ 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
end
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
@@ -1,5 +1,6 @@
require 'bundler/setup'
require 'draper'
+require 'rails/version'
require 'action_controller'
require 'action_controller/test_case'

0 comments on commit 47ee29c

Please sign in to comment.