Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent deprecation warning in Rails 4.0

Use `all` instead of `scoped` if possible. Closes #484
  • Loading branch information...
commit 47ee29c3b739eee3fc28a561432ad2363c14813c 1 parent 2de0592
@haines haines authored
View
3  lib/draper/decoratable.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.
View
6 spec/draper/decoratable_spec.rb
@@ -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
1  spec/spec_helper.rb
@@ -1,5 +1,6 @@
require 'bundler/setup'
require 'draper'
+require 'rails/version'
require 'action_controller'
require 'action_controller/test_case'
Please sign in to comment.
Something went wrong with that request. Please try again.