Merge pull request #486 from haines/scoped_deprecation
Prevent Rails 4.0 deprecation warning for `scoped`
This commit is contained in:
commit
2d5756b321
|
@ -1,7 +1,10 @@
|
|||
language: ruby
|
||||
|
||||
before_install:
|
||||
- gem install bundler --pre
|
||||
- gem install bundler
|
||||
|
||||
services:
|
||||
- mongodb
|
||||
|
||||
rvm:
|
||||
- 1.9.3
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
class MongoidPostDecorator < Draper::Decorator
|
||||
end
|
|
@ -46,8 +46,8 @@ describe PostDecorator do
|
|||
end
|
||||
|
||||
it "serializes to XML" do
|
||||
# Rails < 3.2 does not use `serializable_hash` in `to_xml`
|
||||
pending if Rails.version.to_f < 3.2
|
||||
pending("Rails < 3.2 does not use `serializable_hash` in `to_xml`") if Rails.version.to_f < 3.2
|
||||
|
||||
xml = Capybara.string(decorator.to_xml)
|
||||
expect(xml).to have_css "post > updated-at", text: "overridden"
|
||||
end
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require 'shared_examples/decoratable'
|
||||
|
||||
if defined?(Mongoid)
|
||||
describe MongoidPost do
|
||||
it "is decoratable" do
|
||||
expect(MongoidPost).to respond_to :decorator_class
|
||||
expect(MongoidPost.new).to respond_to :decorate
|
||||
end
|
||||
it_behaves_like "a decoratable model"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require 'shared_examples/decoratable'
|
||||
|
||||
describe Post do
|
||||
describe "#==" do
|
||||
it "is true for other instances' decorators" do
|
||||
Post.create
|
||||
one = Post.first
|
||||
other = Post.first
|
||||
|
||||
expect(one).not_to be other
|
||||
expect(one == other.decorate).to be_true
|
||||
end
|
||||
end
|
||||
it_behaves_like "a decoratable model"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
shared_examples_for "a decoratable model" do
|
||||
describe ".decorate" do
|
||||
it "applies a collection decorator to a scope" do
|
||||
described_class.create
|
||||
decorated = described_class.limit(1).decorate
|
||||
|
||||
expect(decorated).to have(1).items
|
||||
expect(decorated).to be_decorated
|
||||
end
|
||||
end
|
||||
|
||||
describe "#==" do
|
||||
it "is true for other instances' decorators" do
|
||||
pending "Mongoid < 3.1 overrides `#==`" if defined?(Mongoid) && Mongoid::VERSION.to_f < 3.1 && described_class < Mongoid::Document
|
||||
|
||||
described_class.create
|
||||
one = described_class.first
|
||||
other = described_class.first
|
||||
|
||||
expect(one).not_to be other
|
||||
expect(one == other.decorate).to be_true
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
require 'bundler/setup'
|
||||
require 'draper'
|
||||
require 'rails/version'
|
||||
require 'action_controller'
|
||||
require 'action_controller/test_case'
|
||||
|
||||
|
|
Loading…
Reference in New Issue