From 7f587f78ee3a84b20ee895b25a094a513cb2d641 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Tue, 20 Aug 2019 17:19:02 +0200 Subject: [PATCH 01/18] CI: Update Rubies (#862) --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 02f9017b..0146b913 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,10 @@ services: - mongodb rvm: - - 2.3.5 - - 2.4.3 - - 2.5.4 - - 2.6.2 + - 2.3.8 + - 2.4.6 + - 2.5.5 + - 2.6.3 - ruby-head matrix: From dd32a4aa2cd16e2682d9e9c2486630ec53383442 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Tue, 20 Aug 2019 17:29:10 +0200 Subject: [PATCH 02/18] CI: Drop unused sudo: false Travis directive (#861) See https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration for more details --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0146b913..9806f553 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ env: - CC_TEST_REPORTER_ID=b7ba588af2a540fa96c267b3655a2afe31ea29976dc25905a668dd28d5e88915 language: ruby -sudo: false cache: bundler services: From 09d373f90af1fa2a7b028eb5d98cf9370bb1d5c8 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 17 Oct 2019 17:25:57 +0200 Subject: [PATCH 03/18] CI: Use ruby 2.4.9, 2.5.7, 2.6.5 (#863) * CI: Use ruby 2.4.7, 2.5.6, 2.6.4 * CI: Use 2.4.9, 2.5.7, 2.6.5 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9806f553..92ea339d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,9 @@ services: rvm: - 2.3.8 - - 2.4.6 - - 2.5.5 - - 2.6.3 + - 2.4.9 + - 2.5.7 + - 2.6.5 - ruby-head matrix: From eb3468238f9a05bb3031dc524b5de1080adbc239 Mon Sep 17 00:00:00 2001 From: Cliff Braton Date: Fri, 18 Oct 2019 09:54:26 -0500 Subject: [PATCH 04/18] Add manifest.js for newer versions of sprockets --- spec/dummy/app/assets/config/manifest.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spec/dummy/app/assets/config/manifest.js diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js new file mode 100644 index 00000000..b16e53d6 --- /dev/null +++ b/spec/dummy/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css From 661c1a9f0fd3e47a3f0c610ccc6d385ec8bbed9e Mon Sep 17 00:00:00 2001 From: Douglas Lutz Date: Fri, 3 Jan 2020 18:17:34 -0300 Subject: [PATCH 05/18] Add preservation of decorator options on QueryMethods (#868) --- lib/draper/query_methods.rb | 2 +- spec/draper/query_methods_spec.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/draper/query_methods.rb b/lib/draper/query_methods.rb index 267ee8a7..59c42bb8 100644 --- a/lib/draper/query_methods.rb +++ b/lib/draper/query_methods.rb @@ -6,7 +6,7 @@ module QueryMethods def method_missing(method, *args, &block) return super unless strategy.allowed? method - object.send(method, *args, &block).decorate + object.send(method, *args, &block).decorate(with: decorator_class, context: context) end def respond_to_missing?(method, include_private = false) diff --git a/spec/draper/query_methods_spec.rb b/spec/draper/query_methods_spec.rb index 3884d349..7849654d 100644 --- a/spec/draper/query_methods_spec.rb +++ b/spec/draper/query_methods_spec.rb @@ -11,7 +11,8 @@ module Draper describe '#method_missing' do let(:collection) { [ Post.new, Post.new ] } - let(:collection_decorator) { PostDecorator.decorate_collection(collection) } + let(:collection_context) { { user: 'foo' } } + let(:collection_decorator) { PostDecorator.decorate_collection(collection, context: collection_context) } context 'when strategy allows collection to call the method' do let(:results) { spy(:results) } @@ -26,6 +27,12 @@ module Draper expect(results).to have_received(:decorate) end + + it 'calls the method on the collection and keeps the decoration options' do + collection_decorator.some_query_method + + expect(results).to have_received(:decorate).with({ context: collection_context, with: PostDecorator }) + end end context 'when strategy does not allow collection to call the method' do From 89ec4b70f443bd6db526eddf73bddac52d6ca75b Mon Sep 17 00:00:00 2001 From: y-yagi Date: Wed, 8 Jan 2020 01:58:00 +0900 Subject: [PATCH 06/18] Add support for Rails 6.0 to `ViewContext::BuildStrategy` (#866) * Add support for Rails 6.0 to `ViewContext::BuildStrategy` In Rails 6.0 the API for `ActionView::Base.new` is changing. `ActionView::Base.new` now take arguments [1], otherwise you will see the following deprecation warning: ``` DEPRECATION WARNING: ActionView::Base instances should be constructed with a lookup context, assignments, and a controller. ``` [1] https://github.com/rails/rails/commit/e17fe52e0e0ef0842b6c409e1110a862c4e005bc `ViewContext::BuildStrategy::Fast` does not have lookup context, so use `empty` method instead of `new` to build instance. * Bump a Rails version of dummy application Also bump a sqlite version because Rails 6.0 requires upper sqlite 1.4.0. * Add `ApplicationController` to dummy application Because Action Text expects `ApplicationController` exists. Ref: https://github.com/rails/rails/issues/35749#issuecomment-525083643 * Test against Rails 6.0 that only supported Ruby versions --- Gemfile | 12 ++++++++++-- lib/draper/view_context/build_strategy.rb | 2 +- spec/dummy/app/controllers/application_controller.rb | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 spec/dummy/app/controllers/application_controller.rb diff --git a/Gemfile b/Gemfile index 788cbd01..4328990d 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,11 @@ source "https://rubygems.org" gemspec platforms :ruby do - gem 'sqlite3', '~> 1.3.6' + if RUBY_VERSION >= "2.5.0" + gem 'sqlite3' + else + gem 'sqlite3', '~> 1.3.6' + end end platforms :jruby do @@ -11,5 +15,9 @@ platforms :jruby do gem "activerecord-jdbcsqlite3-adapter" end -gem "rails", "~> 5.0" +if RUBY_VERSION >= "2.5.0" + gem "rails", "~> 6.0" +else + gem "rails", "~> 5.0" +end gem "mongoid", github: "mongodb/mongoid" diff --git a/lib/draper/view_context/build_strategy.rb b/lib/draper/view_context/build_strategy.rb index d1bdd3fc..9832a05d 100644 --- a/lib/draper/view_context/build_strategy.rb +++ b/lib/draper/view_context/build_strategy.rb @@ -12,7 +12,7 @@ def initialize(&block) end def call - view_context_class.new + view_context_class.respond_to?(:empty) ? view_context_class.empty : view_context_class.new end private diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb new file mode 100644 index 00000000..09705d12 --- /dev/null +++ b/spec/dummy/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end From 6a3bf0dae9a15f6ff980aaeb398b811e1903d1e9 Mon Sep 17 00:00:00 2001 From: Yury Druzhkov Date: Tue, 7 Jan 2020 20:02:07 +0300 Subject: [PATCH 07/18] Remove ruby 2.7 deprecation (#870) Co-authored-by: Cliff Braton --- lib/draper/delegation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/draper/delegation.rb b/lib/draper/delegation.rb index 30555f8a..1ed06f92 100644 --- a/lib/draper/delegation.rb +++ b/lib/draper/delegation.rb @@ -7,7 +7,7 @@ module Delegation # @return [void] def delegate(*methods) options = methods.extract_options! - super *methods, options.reverse_merge(to: :object) + super(*methods, **options.reverse_merge(to: :object)) end end end From e31a54e92db572d4d2580e39d90591fbe5d8047f Mon Sep 17 00:00:00 2001 From: John DeSilva Date: Fri, 10 Jan 2020 12:57:48 -0500 Subject: [PATCH 08/18] CI: Update travis Ruby versions (#871) Ruby 2.7.0 is out as of 2019-12-15. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 92ea339d..00c75fff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ rvm: - 2.4.9 - 2.5.7 - 2.6.5 + - 2.7.0 - ruby-head matrix: From 19c48c20088865d94446f33669206dd8e6463793 Mon Sep 17 00:00:00 2001 From: Cliff Braton Date: Wed, 5 Feb 2020 08:55:02 -0600 Subject: [PATCH 09/18] Release v4.0.0 (#872) * Update the changelog * Update the readme * Bump draper version * Drop support for Ruby 2.3 in CI --- .travis.yml | 1 - CHANGELOG.md | 17 +++++++++++++++++ README.md | 2 +- lib/draper/version.rb | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 00c75fff..d8ab0e9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ services: - mongodb rvm: - - 2.3.8 - 2.4.9 - 2.5.7 - 2.6.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cc89335..5654747f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Draper Changelog +## 4.0.0 - 2020-02-05 + +### Breaking Changes +* Drop support for Ruby < 2.4 [#852](https://github.com/drapergem/draper/pull/852), [#872](https://github.com/drapergem/draper/pull/872) +* Don't delegate public methods overridden by a private method in the decorator [#849](https://github.com/drapergem/draper/pull/849) + +### Fixes +* Add preservation of decorator options on QueryMethods [#868](https://github.com/drapergem/draper/pull/868) +* Add `#respond_to_missing?` to `CollectionDecorator` so it correctly responds to ORM methods [#850](https://github.com/drapergem/draper/pull/850) +* Fix deprecation warning with the new Rails 6 `ActionView::Base` constructor [#866](https://github.com/drapergem/draper/pull/866) +* Fix deprecation warning with Ruby 2.7 [#870](https://github.com/drapergem/draper/pull/870) + +### Other Changes +* Add SimpleCov for code coverage analysis [#851](https://github.com/drapergem/draper/pull/851) +* Update RSpec syntax in the README [#855](https://github.com/drapergem/draper/pull/855) +* Update continuous integration configuration [#861](https://github.com/drapergem/draper/pull/861), [#862](https://github.com/drapergem/draper/pull/862), [#863](https://github.com/drapergem/draper/pull/863), [#872](https://github.com/drapergem/draper/pull/872) + ## 3.1.0 * Rails 6 support [#841](https://github.com/drapergem/draper/pull/841) * Include ORM query methods in `CollectionDecorator` (e.g. `includes`) [#845](https://github.com/drapergem/draper/pull/845) diff --git a/README.md b/README.md index f687c712..a7b65fba 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Decorators are the ideal place to: ## Installation -As of version 3.0.0, Draper is only compatible with Rails 5 / Ruby 2.2 and later. Add Draper to your Gemfile. +As of version 4.0.0, Draper only officially supports Rails 5.2 / Ruby 2.4 and later. Add Draper to your Gemfile. ```ruby gem 'draper' diff --git a/lib/draper/version.rb b/lib/draper/version.rb index 03b9f5f8..284743bb 100644 --- a/lib/draper/version.rb +++ b/lib/draper/version.rb @@ -1,3 +1,3 @@ module Draper - VERSION = '3.1.0' + VERSION = '4.0.0' end From 4439ed8e84fd2af49f0df45fa21d7daf887b93ce Mon Sep 17 00:00:00 2001 From: Igor Springer Date: Tue, 11 Feb 2020 17:47:49 +0100 Subject: [PATCH 10/18] =?UTF-8?q?fix:=20Check=20only=20object's=20private?= =?UTF-8?q?=20method=20when=20preventing=20delegati=E2=80=A6=20(#875)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/drapergem/draper/pull/849 introduced a valid fix to prevent calling object's public method when a decorator overwrites it through a private one. There is one caveat, though. `private_methods` methods has `all` parameter set to `true` by default (https://ruby-doc.org/core-2.7.0/Object.html#method-i-private_methods)`. As a result all private methods are returned, instead of only the ones defined on the object. This commit fixes the above issue by setting the `all` parameter to `false`. --- lib/draper/automatic_delegation.rb | 2 +- spec/draper/decorator_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/draper/automatic_delegation.rb b/lib/draper/automatic_delegation.rb index 8d62faf5..bd788845 100644 --- a/lib/draper/automatic_delegation.rb +++ b/lib/draper/automatic_delegation.rb @@ -20,7 +20,7 @@ def respond_to_missing?(method, include_private = false) # @private def delegatable?(method) - return if private_methods.include?(method) + return if private_methods(false).include?(method) object.respond_to?(method) end diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index 0f50aa4e..9517ee38 100644 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -684,6 +684,18 @@ def hello_world expect{ decorator.hello_world }.to raise_error NoMethodError end end + + context 'when delegated method has the same name as private method defined on another object' do + let(:decorator_class) { Class.new(Decorator) } + let(:object) { Class.new { def print; end }.new } + + it 'delegates the public method defined on the object' do + decorator = decorator_class.new(object) + + # `print` private method is defined on `Object` + expect{ decorator.print }.not_to raise_error NoMethodError + end + end end context ".method_missing" do From 1ab605f076669da46a2c1ecade33e0adbe3c1274 Mon Sep 17 00:00:00 2001 From: 4geru koichi uchinishi Date: Thu, 27 Feb 2020 06:01:53 +0900 Subject: [PATCH 11/18] fix alias method (#877) --- lib/draper/compatibility/api_only.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/draper/compatibility/api_only.rb b/lib/draper/compatibility/api_only.rb index df989ba2..44fb0415 100644 --- a/lib/draper/compatibility/api_only.rb +++ b/lib/draper/compatibility/api_only.rb @@ -14,9 +14,9 @@ module ApiOnly extend ActiveSupport::Concern included do - alias_method :previous_render_to_body, :render_to_body + alias :previous_render_to_body :render_to_body include ActionView::Rendering - alias_method :render_to_body, :previous_render_to_body + alias :render_to_body :previous_render_to_body end end end From 8f4f407bc0237d3236300aa188ecfeaec8219c9e Mon Sep 17 00:00:00 2001 From: Cliff Braton Date: Wed, 25 Mar 2020 10:51:34 -0500 Subject: [PATCH 12/18] Release v4.0.1 (#879) --- CHANGELOG.md | 8 ++++++++ lib/draper/version.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5654747f..b752920a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Draper Changelog +## 4.0.1 - 2020-03-25 + +### Fixes +* Check only object's private methods when preventing delegation [#875](https://github.com/drapergem/draper/pull/875) + +### Other Changes +* Use `alias` over `alias_method` [#877](https://github.com/drapergem/draper/pull/877) + ## 4.0.0 - 2020-02-05 ### Breaking Changes diff --git a/lib/draper/version.rb b/lib/draper/version.rb index 284743bb..7df64a75 100644 --- a/lib/draper/version.rb +++ b/lib/draper/version.rb @@ -1,3 +1,3 @@ module Draper - VERSION = '4.0.0' + VERSION = '4.0.1' end From 3e7faa4369efd1253a338369b4c8ad8e31ba8b68 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sun, 5 Apr 2020 17:11:25 +0200 Subject: [PATCH 13/18] Avoid Ruby warnings "ambiguous first argument" (#881) - add parentheses to disambiguate --- spec/draper/collection_decorator_spec.rb | 2 +- spec/draper/decorator_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/draper/collection_decorator_spec.rb b/spec/draper/collection_decorator_spec.rb index d329e861..63212f78 100644 --- a/spec/draper/collection_decorator_spec.rb +++ b/spec/draper/collection_decorator_spec.rb @@ -217,7 +217,7 @@ module Draper it "uses the custom class name" do decorator = ProductsDecorator.new([]) - expect(decorator.to_s).to match /ProductsDecorator/ + expect(decorator.to_s).to match(/ProductsDecorator/) end end end diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index 9517ee38..a849874e 100644 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -439,7 +439,7 @@ module Draper it "returns a detailed description of the decorator" do decorator = ProductDecorator.new(double) - expect(decorator.inspect).to match /#/ + expect(decorator.inspect).to match(/#/) end it "includes the object" do From b077a9a2bb5267faa616f4734eba20403665d883 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 13 Jan 2021 23:47:44 +0100 Subject: [PATCH 14/18] Migrate from Travis to GithubActions (#893) --- .github/workflows/ci.yml | 47 ++++++++++++++++ .travis.yml | 28 ---------- bin/bundle | 114 +++++++++++++++++++++++++++++++++++++++ bin/rake | 29 ++++++++++ 4 files changed, 190 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100755 bin/bundle create mode 100755 bin/rake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..3a7e35ca --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +--- +name: CI + +on: + - push + - pull_request + +jobs: + rspec: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + ruby: + - '2.7' + - '2.6' + - '2.5' + - '2.4' + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Setup Ruby cache + uses: actions/cache@v2 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems-${{ matrix.ruby }}- + + - name: Bundle + run: | + gem install bundler + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + + - name: RSpec & publish code coverage + uses: paambaati/codeclimate-action@v2.7.5 + env: + CC_TEST_REPORTER_ID: b7ba588af2a540fa96c267b3655a2afe31ea29976dc25905a668dd28d5e88915 + with: + coverageCommand: bin/rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d8ab0e9c..00000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -env: - global: - - CC_TEST_REPORTER_ID=b7ba588af2a540fa96c267b3655a2afe31ea29976dc25905a668dd28d5e88915 - -language: ruby -cache: bundler - -services: - - mongodb - -rvm: - - 2.4.9 - - 2.5.7 - - 2.6.5 - - 2.7.0 - - ruby-head - -matrix: - allow_failures: - - rvm: ruby-head - -before_script: - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build - -after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 00000000..a71368e3 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,114 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= + env_var_version || cli_arg_version || + lockfile_version + end + + def bundler_requirement + return "#{Gem::Requirement.default}.a" unless bundler_version + + bundler_gem_version = Gem::Version.new(bundler_version) + + requirement = bundler_gem_version.approximate_recommendation + + return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + + requirement += ".a" if bundler_gem_version.prerelease? + + requirement + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/rake b/bin/rake new file mode 100755 index 00000000..9275675e --- /dev/null +++ b/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") From 92587ec1ff76b2eaf55d80dfeb6f7c6b3c19b816 Mon Sep 17 00:00:00 2001 From: Matt Gerst Date: Wed, 13 Jan 2021 18:27:10 -0600 Subject: [PATCH 15/18] Add mongo service to Github Actions (#896) --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a7e35ca..46e35bc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,13 @@ jobs: - '2.6' - '2.5' - '2.4' + + services: + mongodb: + image: mongo + ports: + - 27017:27017 + steps: - name: Checkout uses: actions/checkout@v2 From 4edc462b61589138f7b67aa6dbc5309746559e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=BChlmann?= Date: Thu, 14 Jan 2021 19:59:46 +0100 Subject: [PATCH 16/18] Fix decoration spec (#895) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Bühlmann --- Gemfile | 1 + draper.gemspec | 2 +- spec/draper/collection_decorator_spec.rb | 7 ++++--- spec/dummy/config/environments/development.rb | 2 ++ spec/dummy/config/environments/production.rb | 2 ++ spec/dummy/config/environments/test.rb | 2 ++ spec/dummy/config/storage.yml | 7 +++++++ spec/generators/decorator/decorator_generator_spec.rb | 2 +- 8 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 spec/dummy/config/storage.yml diff --git a/Gemfile b/Gemfile index 4328990d..521aaf1d 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,7 @@ end if RUBY_VERSION >= "2.5.0" gem "rails", "~> 6.0" + gem 'webrick' else gem "rails", "~> 5.0" end diff --git a/draper.gemspec b/draper.gemspec index 71343187..cdb79fc5 100644 --- a/draper.gemspec +++ b/draper.gemspec @@ -30,5 +30,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'capybara' s.add_development_dependency 'active_model_serializers', '>= 0.10' s.add_development_dependency 'rubocop' - s.add_development_dependency 'simplecov' + s.add_development_dependency 'simplecov', '0.17.1' end diff --git a/spec/draper/collection_decorator_spec.rb b/spec/draper/collection_decorator_spec.rb index 63212f78..e18f40dd 100644 --- a/spec/draper/collection_decorator_spec.rb +++ b/spec/draper/collection_decorator_spec.rb @@ -60,10 +60,11 @@ module Draper context "when the collection has not yet been decorated" do it "does not trigger decoration" do - decorator = CollectionDecorator.new([]) + decorated = CollectionDecorator.new([]).tap(&:to_a) + undecorated = CollectionDecorator.new([]) - expect(decorator).not_to receive(:decorated_collection) - decorator.context = {other: "context"} + expect(decorated.instance_variable_defined?(:@decorated_collection)).to be_truthy + expect(undecorated.instance_variable_defined?(:@decorated_collection)).to be_falsy end it "sets context after decoration is triggered" do diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 23294c6b..80d91ee2 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -30,4 +30,6 @@ # Expands the lines which load the assets # config.assets.debug = true + + config.active_storage.service = :local end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index 851d8e7a..fb828684 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -54,4 +54,6 @@ # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 + + config.active_storage.service = :local end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index f2f925cc..de472e37 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -30,4 +30,6 @@ config.eager_load = false config.active_job.queue_adapter = :test + + config.active_storage.service = :test end diff --git a/spec/dummy/config/storage.yml b/spec/dummy/config/storage.yml new file mode 100644 index 00000000..695f17bd --- /dev/null +++ b/spec/dummy/config/storage.yml @@ -0,0 +1,7 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> diff --git a/spec/generators/decorator/decorator_generator_spec.rb b/spec/generators/decorator/decorator_generator_spec.rb index c4318e88..3846dc87 100644 --- a/spec/generators/decorator/decorator_generator_spec.rb +++ b/spec/generators/decorator/decorator_generator_spec.rb @@ -40,7 +40,7 @@ context "with an ApplicationDecorator" do before do - allow_any_instance_of(Object).to receive(:require) + allow_any_instance_of(Object).to receive(:require).and_call_original allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return( stub_const "ApplicationDecorator", Class.new ) From da6cd976ef1acf189936dbc569432dcbfd57bbbb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 21 Jan 2021 21:01:42 +0100 Subject: [PATCH 17/18] Fix Rake warning in CI (#897) --- draper.gemspec | 3 +-- spec/draper/decorator_spec.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/draper.gemspec b/draper.gemspec index cdb79fc5..84fafc6b 100644 --- a/draper.gemspec +++ b/draper.gemspec @@ -1,4 +1,4 @@ -require File.join(__dir__, "lib", "draper", "version") +require_relative 'lib/draper/version' Gem::Specification.new do |s| s.name = "draper" @@ -12,7 +12,6 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.required_ruby_version = '>= 2.2.2' diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index a849874e..876a3dd1 100644 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -693,7 +693,7 @@ def hello_world decorator = decorator_class.new(object) # `print` private method is defined on `Object` - expect{ decorator.print }.not_to raise_error NoMethodError + expect{ decorator.print }.not_to raise_error end end end From 9cb42f6e714764c1b196f49754328132bcc7ed32 Mon Sep 17 00:00:00 2001 From: oieioi Date: Thu, 28 Jan 2021 01:44:29 +0900 Subject: [PATCH 18/18] Fix kwargs for Ruby 2.7 (#885) * Fix kwargs for Ruby 2.7 * Test with Ruby 3.0 Co-authored-by: Nicolas Rodriguez --- .github/workflows/ci.yml | 1 + draper.gemspec | 1 + lib/draper.rb | 2 ++ lib/draper/automatic_delegation.rb | 4 ++-- lib/draper/helper_proxy.rb | 3 ++- lib/draper/lazy_helpers.rb | 2 +- lib/draper/query_methods.rb | 2 +- lib/draper/view_helpers.rb | 2 +- 8 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46e35bc9..0b73e450 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ jobs: fail-fast: false matrix: ruby: + - '3.0' - '2.7' - '2.6' - '2.5' diff --git a/draper.gemspec b/draper.gemspec index 84fafc6b..5c73dd15 100644 --- a/draper.gemspec +++ b/draper.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'request_store', '>= 1.0' s.add_dependency 'activemodel', '>= 5.0' s.add_dependency 'activemodel-serializers-xml', '>= 1.0' + s.add_dependency 'ruby2_keywords' s.add_development_dependency 'ammeter' s.add_development_dependency 'rake' diff --git a/lib/draper.rb b/lib/draper.rb index 4f8b667d..0e5dc697 100644 --- a/lib/draper.rb +++ b/lib/draper.rb @@ -8,6 +8,8 @@ require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/name_error' +require 'ruby2_keywords' + require 'draper/version' require 'draper/configuration' require 'draper/view_helpers' diff --git a/lib/draper/automatic_delegation.rb b/lib/draper/automatic_delegation.rb index bd788845..81c45c42 100644 --- a/lib/draper/automatic_delegation.rb +++ b/lib/draper/automatic_delegation.rb @@ -6,7 +6,7 @@ module AutomaticDelegation # method calls to `object` as well. Calling `super` will first try to call the method on # the parent decorator class. If no method exists on the parent class, it will then try # to call the method on the `object`. - def method_missing(method, *args, &block) + ruby2_keywords def method_missing(method, *args, &block) return super unless delegatable?(method) object.send(method, *args, &block) @@ -27,7 +27,7 @@ def delegatable?(method) module ClassMethods # Proxies missing class methods to the source class. - def method_missing(method, *args, &block) + ruby2_keywords def method_missing(method, *args, &block) return super unless delegatable?(method) object_class.send(method, *args, &block) diff --git a/lib/draper/helper_proxy.rb b/lib/draper/helper_proxy.rb index 8645a138..9f9a267d 100644 --- a/lib/draper/helper_proxy.rb +++ b/lib/draper/helper_proxy.rb @@ -8,7 +8,7 @@ def initialize(view_context) end # Sends helper methods to the view context. - def method_missing(method, *args, &block) + ruby2_keywords def method_missing(method, *args, &block) self.class.define_proxy method send(method, *args, &block) end @@ -31,6 +31,7 @@ def self.define_proxy(name) define_method name do |*args, &block| view_context.send(name, *args, &block) end + ruby2_keywords name end end end diff --git a/lib/draper/lazy_helpers.rb b/lib/draper/lazy_helpers.rb index c25761a5..7f6e7ae2 100644 --- a/lib/draper/lazy_helpers.rb +++ b/lib/draper/lazy_helpers.rb @@ -4,7 +4,7 @@ module Draper # bazillion methods. module LazyHelpers # Sends missing methods to the {HelperProxy}. - def method_missing(method, *args, &block) + ruby2_keywords def method_missing(method, *args, &block) helpers.send(method, *args, &block) rescue NoMethodError super diff --git a/lib/draper/query_methods.rb b/lib/draper/query_methods.rb index 59c42bb8..abeeda81 100644 --- a/lib/draper/query_methods.rb +++ b/lib/draper/query_methods.rb @@ -3,7 +3,7 @@ module Draper module QueryMethods # Proxies missing query methods to the source class if the strategy allows. - def method_missing(method, *args, &block) + ruby2_keywords def method_missing(method, *args, &block) return super unless strategy.allowed? method object.send(method, *args, &block).decorate(with: decorator_class, context: context) diff --git a/lib/draper/view_helpers.rb b/lib/draper/view_helpers.rb index 3b8ce0b7..8fcba4ac 100644 --- a/lib/draper/view_helpers.rb +++ b/lib/draper/view_helpers.rb @@ -28,7 +28,7 @@ def helpers # Alias for `helpers.localize`, since localize is something that's used # quite often. Further aliased to `l` for convenience. - def localize(*args) + ruby2_keywords def localize(*args) helpers.localize(*args) end