Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UW-2661: Add support for Ruby 3.x and Rails 7.x #16

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/publish-on-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Publish Ruby Gem (Pushed)

on:
push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and publish gem
uses: jstastny/publish-gem-to-github@v2.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
owner: acima-credit
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
/spec/reports/
/tmp/

.idea
*.gem
.ruby-version

# rspec failure tracking
.rspec_status

.tool-versions
.tool-versions
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AllCops:
TargetRubyVersion: 2.7
DisplayCopNames: true
Exclude:
- bin/*
Expand Down
10 changes: 6 additions & 4 deletions actionable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'actionable/version'

Gem::Specification.new do |spec|
spec.name = 'actionable'
spec.version = Actionable::VERSION
spec.name = 'actionable'
current_branch = `git branch --remote --contains | sed "s|[[:space:]]*origin/||"`.strip
branch_commit = `git rev-parse HEAD`.strip[0..6]
spec.version = current_branch == 'master' ? Actionable::VERSION : "#{Actionable::VERSION}-#{branch_commit}"
spec.authors = ['Adrian Esteban Madrid']
spec.email = ['aemadrid@gmail.com']

spec.summary = 'Simple and effective service objects.'
spec.description = 'Simple and effective Ruby service objects.'
spec.homepage = ''
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = '>= 2.7.0'

if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
spec.metadata['allowed_push_host'] = 'https://rubygems.pkg.github.com/acima-credit'
else
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
end
Expand Down
4 changes: 2 additions & 2 deletions lib/actionable/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def inherited(subclass)
Actionable.registry.add subclass
end

def run(*args, &blk)
ActionRunner.new(self).run(*args, &blk)
def run(*args, **kwargs, &blk)
ActionRunner.new(self).run(*args, **kwargs, &blk)
end

alias call run
Expand Down
6 changes: 3 additions & 3 deletions lib/actionable/action_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def initialize(klass)
@klass = klass
end

def run(*args, &blk)
@instance = @klass.new(*args)
def run(*args, **kwargs, &blk)
@instance = @klass.new(*args, **kwargs)

if @klass.model
@instance.log_action 'running with a transaction from %s', @klass.model
Expand All @@ -24,7 +24,7 @@ def run(*args, &blk)
private

def run_with_transaction(&blk)
@klass.model.transaction(@klass.transaction_options) { run_without_transaction(&blk) }
@klass.model.transaction(**@klass.transaction_options) { run_without_transaction(&blk) }
end

def run_without_transaction(&blk)
Expand Down
12 changes: 7 additions & 5 deletions lib/actionable/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

module Actionable
module RspecMatchers
def perform_actionable(*args)
PerformActionableMatcher.new(*args)
def perform_actionable(*args, **kwargs)
PerformActionableMatcher.new(*args, **kwargs)
end

# rubocop:disable Metrics/ClassLength
class PerformActionableMatcher
attr_reader :type, :matched

def initialize(*args)
def initialize(*args, **kwargs)
@args = args
@kwargs = kwargs
end

def and_succeed(message = Action::DEFAULT_SUCCESS_MESSAGE)
Expand All @@ -40,6 +41,7 @@ def matches?(klass)
return @matched unless @matched.nil?

@klass = klass

get_result_or_exception

case @type
Expand All @@ -64,12 +66,12 @@ def failure_message

private

attr_reader :klass, :args, :exception, :result
attr_reader :klass, :args, :kwargs, :exception, :result

# rubocop:disable Lint/RescueException
def get_result_or_exception
@exception = nil
@result = klass.run(*args)
@result = klass.run(*args, **kwargs)
rescue Exception => e
@result = nil
@exception = e
Expand Down
2 changes: 1 addition & 1 deletion lib/actionable/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Actionable
VERSION = '0.1.4'
VERSION = '0.1.5'
end
10 changes: 7 additions & 3 deletions spec/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ module Actionable
end
it do
msg = nil
expect(Invoice).to receive(:transaction).with({}).and_call_original
if RUBY_VERSION[0].to_i < 3
expect(Invoice).to receive(:transaction).with({}).and_call_original
else
expect(Invoice).to receive(:transaction).with(no_args).and_call_original
end
klass.run(number) { |x| msg = x.message }
expect(msg).to eq 'Completed successfully.'
end
Expand Down Expand Up @@ -104,7 +108,7 @@ module Actionable
it('section') { expect(subject.history.map(&:section)).to eq(%i[main main]) }
it('name ') { expect(subject.history.map(&:name)).to eq(%w[test_actionable/small_action add_five]) }
it('time ') { expect(subject.history.map { |x| x.start_time.to_s[0, 19] }.uniq).to eq([Time.now.to_s[0, 19]]) }
it('took-e ') { expect(subject.history.map(&:took).all? { |x| x > 0.0 && x < 0.0002 }).to eq true }
it('took-e ') { expect(subject.history.map(&:took).all? { |x| x > 0.0 && x < 0.0010 }).to eq true }
it('took ') { expect(subject.history.took).to be > 0 }
it('code ') { expect(subject.history.map(&:code)).to eq(%i[success na]) }
context 'nested' do
Expand Down Expand Up @@ -136,7 +140,7 @@ module Actionable
it('section') { expect(subject.history.map(&:section)).to eq(%i[main]) }
it('name ') { expect(subject.history.map(&:name)).to eq(%w[test_actionable/small_action]) }
it('time ') { expect(subject.history.map { |x| x.start_time.to_s[0, 19] }.uniq).to eq([Time.now.to_s[0, 19]]) }
it('took-e ') { expect(subject.history.map(&:took).all? { |x| x > 0.0 && x < 0.0002 }).to eq true }
it('took-e ') { expect(subject.history.map(&:took).all? { |x| x > 0.0 && x < 0.0010 }).to eq true }
it('took ') { expect(subject.history.took).to be > 0 }
it('code ') { expect(subject.history.map(&:code)).to eq([:fail]) }
context 'nested' do
Expand Down