Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
26a18c8cc9 | |
![]() |
43a6e34529 | |
![]() |
3524d8876d | |
![]() |
cc10465484 | |
![]() |
7b9267a4b5 | |
![]() |
9cb42f6e71 | |
![]() |
da6cd976ef | |
![]() |
4edc462b61 | |
![]() |
92587ec1ff | |
![]() |
b077a9a2bb | |
![]() |
3e7faa4369 |
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
name: CI
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
rspec:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby:
|
||||
- '3.0'
|
||||
- '2.7'
|
||||
- '2.6'
|
||||
- '2.5'
|
||||
- '2.4'
|
||||
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo
|
||||
ports:
|
||||
- 27017:27017
|
||||
|
||||
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
|
28
.travis.yml
28
.travis.yml
|
@ -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
|
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -1,5 +1,16 @@
|
|||
# Draper Changelog
|
||||
|
||||
## 4.0.2 - 2021-05-27
|
||||
|
||||
### Fixes
|
||||
* Fix kwargs usage for Ruby 3 compatibility [#885](https://github.com/drapergem/draper/pull/885)
|
||||
* Fix ruby warnings for "ambiguous first argument" [#881](https://github.com/drapergem/draper/pull/881)
|
||||
* Fix rake warnings in CI [#897](https://github.com/drapergem/draper/pull/897)
|
||||
* Fix decoration spec [#895](https://github.com/drapergem/draper/pull/895)
|
||||
|
||||
### Other Changes
|
||||
* Migration from Travis CI to GitHub Actions [#893](https://github.com/drapergem/draper/pull/893), [#896](https://github.com/drapergem/draper/pull/896), [#903](https://github.com/drapergem/draper/pull/903)
|
||||
|
||||
## 4.0.1 - 2020-03-25
|
||||
|
||||
### Fixes
|
||||
|
|
8
Gemfile
8
Gemfile
|
@ -17,7 +17,13 @@ end
|
|||
|
||||
if RUBY_VERSION >= "2.5.0"
|
||||
gem "rails", "~> 6.0"
|
||||
gem 'webrick'
|
||||
else
|
||||
gem "rails", "~> 5.0"
|
||||
end
|
||||
gem "mongoid", github: "mongodb/mongoid"
|
||||
|
||||
if RUBY_VERSION >= "2.5.0"
|
||||
gem "mongoid", github: "mongodb/mongoid"
|
||||
else
|
||||
gem "mongoid", "~> 7.2"
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Draper: View Models for Rails
|
||||
|
||||
[![TravisCI Build Status](https://travis-ci.org/drapergem/draper.svg?branch=master)](http://travis-ci.org/drapergem/draper)
|
||||
[![Actions Status](https://github.com/drapergem/draper/workflows/CI/badge.svg?branch=master)](https://github.com/drapergem/draper/actions?query=workflow%3Aci+branch%3Amaster)
|
||||
[![Code Climate](https://codeclimate.com/github/drapergem/draper.svg)](https://codeclimate.com/github/drapergem/draper)
|
||||
[![Test Coverage](https://api.codeclimate.com/v1/badges/0d40c43951d516bf6985/test_coverage)](https://codeclimate.com/github/drapergem/draper/test_coverage)
|
||||
[![Inline docs](http://inch-ci.org/github/drapergem/draper.svg?branch=master)](http://inch-ci.org/github/drapergem/draper)
|
||||
|
|
|
@ -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
|
|
@ -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")
|
|
@ -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'
|
||||
|
@ -22,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'
|
||||
|
@ -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
|
||||
|
|
|
@ -8,6 +8,8 @@ require 'active_support/core_ext/hash/keys'
|
|||
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'
|
||||
|
|
|
@ -6,7 +6,7 @@ module Draper
|
|||
# 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 @@ module Draper
|
|||
|
||||
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)
|
||||
|
|
|
@ -8,7 +8,7 @@ module Draper
|
|||
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 @@ module Draper
|
|||
define_method name do |*args, &block|
|
||||
view_context.send(name, *args, &block)
|
||||
end
|
||||
ruby2_keywords name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,7 +3,7 @@ require_relative 'query_methods/load_strategy'
|
|||
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)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Draper
|
||||
VERSION = '4.0.1'
|
||||
VERSION = '4.0.2'
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ module Draper
|
|||
|
||||
# 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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -217,7 +218,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
|
||||
|
|
|
@ -439,7 +439,7 @@ module Draper
|
|||
it "returns a detailed description of the decorator" do
|
||||
decorator = ProductDecorator.new(double)
|
||||
|
||||
expect(decorator.inspect).to match /#<ProductDecorator:0x\h+ .+>/
|
||||
expect(decorator.inspect).to match(/#<ProductDecorator:0x\h+ .+>/)
|
||||
end
|
||||
|
||||
it "includes the object" do
|
||||
|
@ -693,7 +693,7 @@ module Draper
|
|||
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
|
||||
|
|
|
@ -30,4 +30,6 @@ Dummy::Application.configure do
|
|||
|
||||
# Expands the lines which load the assets
|
||||
# config.assets.debug = true
|
||||
|
||||
config.active_storage.service = :local
|
||||
end
|
||||
|
|
|
@ -54,4 +54,6 @@ Dummy::Application.configure do
|
|||
# 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
|
||||
|
|
|
@ -30,4 +30,6 @@ Dummy::Application.configure do
|
|||
config.eager_load = false
|
||||
|
||||
config.active_job.queue_adapter = :test
|
||||
|
||||
config.active_storage.service = :test
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
test:
|
||||
service: Disk
|
||||
root: <%= Rails.root.join("tmp/storage") %>
|
||||
|
||||
local:
|
||||
service: Disk
|
||||
root: <%= Rails.root.join("storage") %>
|
|
@ -40,7 +40,7 @@ describe Rails::Generators::DecoratorGenerator do
|
|||
|
||||
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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue