1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

remove old compatibility code

This commit is contained in:
Sean Linsley 2016-07-04 16:07:06 -05:00
parent ce7a505345
commit 5d9e6919c4
13 changed files with 22 additions and 64 deletions

View file

@ -1,5 +1,10 @@
# Draper Changelog
## 3.0.0 - 2016-07-XX
* Dropped support for Rails < 5
* Dropped support for Ruby < 2.2
## 2.1.0 - 2015-03-26
* Cleared most issues and merged a few PRs

View file

@ -564,15 +564,15 @@ end
This is only necessary when proxying class methods.
Once this association between the decorator and the model is set up, you can call `SomeModel.decorator_class` to access class methods defined in the decorator. If necessary, you can check if your model is decorated with `SomeModel.decorator_class?`.
Once this association between the decorator and the model is set up, you can call
`SomeModel.decorator_class` to access class methods defined in the decorator.
If necessary, you can check if your model is decorated with `SomeModel.decorator_class?`.
### Making Models Decoratable
Models get their `decorate` method from the `Draper::Decoratable` module, which
is included in `ActiveRecord::Base` and `Mongoid::Document` by default. If
you're [using another
ORM](https://github.com/drapergem/draper/wiki/Using-other-ORMs) (including
versions of Mongoid prior to 3.0), or want to decorate plain old Ruby objects,
you're using another ORM, or want to decorate plain old Ruby objects,
you can include this module manually.
## Contributors
@ -587,3 +587,4 @@ great community of open source
* Steve Klabnik (steve@jumpstartlab.com)
* Vasiliy Ermolovich
* Andrew Haines
* Sean Linsley

View file

@ -56,8 +56,7 @@ module Draper
# @param [Hash] options
# see {Decorator.decorate_collection}.
def decorate(options = {})
collection = Rails::VERSION::MAJOR >= 4 ? all : scoped
decorator_class.decorate_collection(collection, options.reverse_merge(with: nil))
decorator_class.decorate_collection(all, options.reverse_merge(with: nil))
end
def decorator_class?

View file

@ -203,18 +203,6 @@ module Draper
super || object.instance_of?(klass)
end
if RUBY_VERSION < "2.0"
# nasty hack to stop 1.9.x using the delegated `to_s` in `inspect`
alias_method :_to_s, :to_s
def inspect
ivars = instance_variables.map do |name|
"#{name}=#{instance_variable_get(name).inspect}"
end
_to_s.insert(-2, " #{ivars.join(", ")}")
end
end
delegate :to_s
# In case object is nil

View file

@ -1,23 +1,9 @@
require 'rake/testtask'
rails_version = Rails.version.to_f
test_task = if rails_version < 3.2 || rails_version > 4.2
require 'rails/test_unit/railtie'
Rake::TestTask
else
require 'rails/test_unit/sub_test_task'
Rails::SubTestTask
end
require 'rails/test_unit/railtie'
namespace :test do
test_task.new(:decorators => "test:prepare") do |t|
Rake::TestTask.new(:decorators => "test:prepare") do |t|
t.libs << "test"
t.pattern = "test/decorators/**/*_test.rb"
end
end
if Rails.version.to_f < 4.2 && Rake::Task.task_defined?('test:run')
Rake::Task['test:run'].enhance do
Rake::Task['test:decorators'].invoke
end
end

View file

@ -7,11 +7,7 @@ module Draper
end
RSpec.configure do |config|
if RSpec::Core::Version::STRING.starts_with?("3")
config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator
else
config.include DecoratorExampleGroup, example_group: {file_path: %r{spec/decorators}}, type: :decorator
end
config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator
[:decorator, :controller, :mailer].each do |type|
config.before(:each, type: type) { Draper::ViewContext.clear! }

View file

@ -29,14 +29,10 @@ module Draper
end
end
if defined?(ActionController::TestCase)
class ActionController::TestCase
include Draper::TestCase::ViewContextTeardown
end
class ActionController::TestCase
include Draper::TestCase::ViewContextTeardown
end
if defined?(ActionMailer::TestCase)
class ActionMailer::TestCase
include Draper::TestCase::ViewContextTeardown
end
class ActionMailer::TestCase
include Draper::TestCase::ViewContextTeardown
end

View file

@ -38,13 +38,7 @@ module Draper
def controller
(Draper::ViewContext.controller || ApplicationController.new).tap do |controller|
if defined?(ActionController::TestRequest)
controller.request ||= if ActionController::TestRequest.respond_to?(:create)
ActionController::TestRequest.create
else
ActionController::TestRequest.new
end
end
controller.request ||= ActionController::TestRequest.create
end
end
end

View file

@ -128,11 +128,9 @@ 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 scoping_method => scoped
Product.stub all: scoped
Product.decorator_class.should_receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
expect(Product.decorate).to be :decorated_collection
@ -140,7 +138,7 @@ module Draper
it "accepts options" do
options = {with: ProductDecorator, context: {some: "context"}}
Product.stub scoping_method => []
Product.stub all: []
Product.decorator_class.should_receive(:decorate_collection).with([], options)
Product.decorate(options)

View file

@ -54,8 +54,6 @@ describe PostDecorator do
end
it "serializes to XML" do
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

View file

@ -11,8 +11,6 @@ shared_examples_for "a decoratable model" do
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

View file

@ -1,7 +1,7 @@
require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Bundler.require(:default) if defined?(Bundler)
Bundler.require :default
require "benchmark"
require "draper"

View file

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