Skip to content

Commit

Permalink
fix: update keyword args usage for Ruby 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Feb 24, 2021
1 parent 58522ac commit f8feb83
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 48 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: build

on: [push]

jobs:
build:
name: build
runs-on: ${{ matrix.os }}
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }}
env:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ruby: [
2.7,
3.0
]
gemfile: [
"gemfiles/Gemfile.rails-5.2.x",
"gemfiles/Gemfile.rails-6.1.x",
"gemfiles/Gemfile.rails-7.0.x"
]
experimental: [false]
exclude:
- ruby: "3.0"
gemfile: gemfiles/Gemfile.rails-5.2.x

steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /home/runner/bundle
key: bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }}
restore-keys: |
bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Bundle install
run: |
gem install bundler -v 2.1.4
bundle config path /home/runner/bundle
bundle config --global gemfile ${{ matrix.gemfile }}
bundle install --jobs 4 --retry 3
- name: RSpec
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
with:
coverageCommand: bundle exec rspec
debug: true
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Resourcerer 2.0.4 (2021-02-24) ##

* Update `ruby_version` requirement in gemspec to allow usage in Ruby 3.0.

## Resourcerer 2.0.3 (2017-04-03) ##

* Complete rewrite, embrace functions as first-class citizens for configuration.
35 changes: 18 additions & 17 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
Copyright (c) 2017 Máximo Mussini
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Copyright (c) 2021 Maximo Mussini

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<h1 align="center">
Resourcerer
<p align="center">
<a href="https://travis-ci.org/ElMassimo/resourcerer"><img alt="Build Status" src="https://travis-ci.org/ElMassimo/resourcerer.svg"/></a>
<a href="https://coveralls.io/github/ElMassimo/resourcerer?branch=master"><img alt="Coverage Status" src="https://coveralls.io/repos/github/ElMassimo/resourcerer/badge.svg?branch=master"/></a>
<a href="http://inch-ci.org/github/ElMassimo/resourcerer"><img alt="Inline docs" src="http://inch-ci.org/github/ElMassimo/resourcerer.svg"/></a>
<a href="https://rubygems.org/gems/resourcerer"><img alt="Gem Version" src="https://img.shields.io/gem/v/resourcerer.svg?colorB=e9573f"/></a>
<a href="https://github.com/ElMassimo/resourcerer/blob/master/LICENSE.txt"><img alt="License" src="https://img.shields.io/badge/license-MIT-428F7E.svg"/></a>
<a href="https://github.com/ElMassimo/resourcerer/actions">
<img alt="Build Status" src="https://github.com/ElMassimo/resourcerer/workflows/build/badge.svg"/>
</a>
<a href="https://codeclimate.com/github/ElMassimo/vite_ruby">
<img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/vite_ruby/badges/gpa.svg"/>
</a>
<a href="https://codeclimate.com/github/ElMassimo/resourcerer">
<img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/resourcerer/badges/coverage.svg"/>
</a>
<a href="https://rubygems.org/gems/resourcerer">
<img alt="Gem Version" src="https://img.shields.io/gem/v/resourcerer.svg?colorB=e9573f"/>
</a>
<a href="https://github.com/ElMassimo/resourcerer/blob/master/LICENSE.txt">
<img alt="License" src="https://img.shields.io/badge/license-MIT-428F7E.svg"/>
</a>
</p>
</h1>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gemspec path: ".."
gem 'rails', '4.2.7'
gem 'rails', '~> 5.2'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gemspec path: ".."
gem 'rails', '5.0.2'
gem 'rails', '~> 6.1'
4 changes: 4 additions & 0 deletions gemfiles/Gemfile.rails-7.0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gemspec path: ".."
gem "rails", github: "rails/rails", branch: 'main'
11 changes: 6 additions & 5 deletions lib/resourcerer/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ module Controller
instance_accessor: false, instance_predicate: false
end

def resource(*args)
Resource.new(self, *args).get(self)
def resource(name, **options)
Resource.new(self, name, **options).get(self)
end

module ClassMethods
# Public: Defines a Resource in a controller Class.
#
# *args - See Resource#initialize for details.
# name - The name of the method to define.
# **options - See Resource#initialize for details.
# block - If supplied, the block is executed to provide options.
#
# Returns the name of the defined resource.
def resource(*args, &block)
Resource.define(self, *args, &block)
def resource(name, **options, &block)
Resource.define(self, name, **options, &block)
end

# Public: Defines a Configuration preset that can be reused in different
Expand Down
2 changes: 1 addition & 1 deletion lib/resourcerer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Resourcerer
VERSION = '2.0.3'
VERSION = '2.0.4'
end
6 changes: 3 additions & 3 deletions resourcerer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/ElMassimo/resourcerer'
s.license = 'MIT'
s.extra_rdoc_files = ['README.md']
s.files = Dir.glob('{lib}/**/*.rb') + %w(README.md)
s.files = Dir.glob('{lib}/**/*.rb') + %w(README.md CHANGELOG.md)
s.test_files = Dir.glob('{spec}/**/*.rb')
s.require_path = 'lib'

s.required_ruby_version = '~> 2.2'
s.required_ruby_version = '>= 2.2'

s.add_dependency 'activesupport', '>= 4.0'
s.add_development_dependency 'activemodel'
s.add_development_dependency 'coveralls'
s.add_development_dependency 'simplecov', '< 0.18'
s.add_development_dependency 'pry-byebug'
s.add_development_dependency 'railties', '>= 4.0'
s.add_development_dependency 'rspec-given', '~> 3.0'
Expand Down
8 changes: 4 additions & 4 deletions spec/features/guitars_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
Given {
expect(Guitar).to receive(:find).with('ES-335').and_return(guitar)
}
When { get :show, request_params(id: 'ES-335') }
When { get :show, **request_params(id: 'ES-335') }
Then { controller.guitar == guitar }
end

context 'finds model by guitar_id' do
Given {
expect(Guitar).to receive(:find).with('ES-335').and_return(guitar)
}
When { get :new, request_params(guitar_id: 'ES-335') }
When { get :new, **request_params(guitar_id: 'ES-335') }
Then { controller.guitar == guitar }
end

Expand All @@ -37,15 +37,15 @@
end

context 'when build params are used' do
When { post :create, request_params(guitar: { name: 'strat' }) }
When { post :create, **request_params(guitar: { name: 'strat' }) }
Then { controller.guitar.name == 'strat' }
end

context 'when a guitar? with a question mark is exposed' do
Given {
expect(Guitar).to receive(:find).with('ES-335').and_return(guitar)
}
When { get :show, request_params(id: 'ES-335') }
When { get :show, **request_params(id: 'ES-335') }
Then { controller.guitar? == true }
end
end
6 changes: 6 additions & 0 deletions spec/resourcerer/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def controller_thing
And { controller.method(:thing=).parameters.size == 1 }
end

context 'incorrect proc options' do
Given { resource :thing, build: :thing }
When(:usage) { controller_thing }
Then { expect(usage).to have_failed(ArgumentError, /Can't handle :build => :thing option/) }
end

context 'memoization' do
Given { resource :thing, build: -> { SecureRandom.hex(32) } }
Then { controller_thing == controller_thing }
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require "simplecov"
require "coveralls"
SimpleCov.start { add_filter '/spec/' }
Coveralls.wear!

require "resourcerer"
require "rspec/given"
Expand Down
2 changes: 1 addition & 1 deletion spec/support/rails_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "rails"

def request_params(params)
{ params: params, **params }
{ params: params }
end

module Rails
Expand Down

0 comments on commit f8feb83

Please sign in to comment.