diff --git a/.github/workflows/publish-on-push.yaml b/.github/workflows/publish-on-push.yaml new file mode 100644 index 0000000..eda8996 --- /dev/null +++ b/.github/workflows/publish-on-push.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 2d3e7b3..f18445c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,10 @@ /spec/reports/ /tmp/ +.idea +*.gem +.ruby-version + # rspec failure tracking .rspec_status - -.tool-versions \ No newline at end of file +.tool-versions diff --git a/.rubocop.yml b/.rubocop.yml index 1809297..6aa7465 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ AllCops: + TargetRubyVersion: 2.7 DisplayCopNames: true Exclude: - bin/* diff --git a/actionable.gemspec b/actionable.gemspec index be22c77..2d2efbf 100644 --- a/actionable.gemspec +++ b/actionable.gemspec @@ -6,8 +6,10 @@ $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'] @@ -15,10 +17,10 @@ Gem::Specification.new do |spec| 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 diff --git a/lib/actionable/action.rb b/lib/actionable/action.rb index b92534d..481f305 100644 --- a/lib/actionable/action.rb +++ b/lib/actionable/action.rb @@ -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 diff --git a/lib/actionable/action_runner.rb b/lib/actionable/action_runner.rb index 560fb5a..4483a7e 100644 --- a/lib/actionable/action_runner.rb +++ b/lib/actionable/action_runner.rb @@ -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 @@ -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) diff --git a/lib/actionable/rspec/matchers.rb b/lib/actionable/rspec/matchers.rb index 9f32fb0..0707d28 100644 --- a/lib/actionable/rspec/matchers.rb +++ b/lib/actionable/rspec/matchers.rb @@ -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) @@ -40,6 +41,7 @@ def matches?(klass) return @matched unless @matched.nil? @klass = klass + get_result_or_exception case @type @@ -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 diff --git a/lib/actionable/version.rb b/lib/actionable/version.rb index 24641a8..f9c6f91 100644 --- a/lib/actionable/version.rb +++ b/lib/actionable/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Actionable - VERSION = '0.1.4' + VERSION = '0.1.5' end diff --git a/spec/action_spec.rb b/spec/action_spec.rb index 08ec885..697a300 100644 --- a/spec/action_spec.rb +++ b/spec/action_spec.rb @@ -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 @@ -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 @@ -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