diff --git a/lib/macros/base.rb b/lib/macros/base.rb index 335a2de..3fba2dc 100644 --- a/lib/macros/base.rb +++ b/lib/macros/base.rb @@ -5,9 +5,10 @@ module Macros class Base include Uber::Callable - # @param args Any arguments that our macro operation supports + # @param args [Hash] Any arguments that our macro operation supports + # # @return Single step object that can be used in operation step - def initialize(*args) + def initialize(args = {}) self.args = args end diff --git a/lib/macros/contract/build.rb b/lib/macros/contract/build.rb index cd0c31b..ee407ec 100644 --- a/lib/macros/contract/build.rb +++ b/lib/macros/contract/build.rb @@ -8,7 +8,7 @@ class Contract class Build < Base # Builds a contract step def call - Trailblazer::Operation::Contract::Build(*args) + Trailblazer::Operation::Contract::Build(**args) end end end diff --git a/lib/macros/contract/persist.rb b/lib/macros/contract/persist.rb index 26a0191..4515668 100644 --- a/lib/macros/contract/persist.rb +++ b/lib/macros/contract/persist.rb @@ -8,7 +8,7 @@ class Contract class Persist < Base # Build and return persistance contract step def call - Trailblazer::Operation::Contract::Persist(*args) + Trailblazer::Operation::Contract::Persist(**args) end end end diff --git a/lib/macros/contract/validate.rb b/lib/macros/contract/validate.rb index 6c18cfd..759de1f 100644 --- a/lib/macros/contract/validate.rb +++ b/lib/macros/contract/validate.rb @@ -9,7 +9,7 @@ class Contract class Validate < Base # Creates a contact validation step def call - Trailblazer::Operation::Contract::Validate(*args) + Trailblazer::Operation::Contract::Validate(**args) end end end diff --git a/lib/macros/model/search.rb b/lib/macros/model/search.rb index 052f686..a06245b 100644 --- a/lib/macros/model/search.rb +++ b/lib/macros/model/search.rb @@ -26,7 +26,7 @@ def initialize(name: 'model', default_sort_order: nil) # @param ctx [Trailblazer::Skill] trbr context hash # @param current_search [Hash] hash with ransack search details def call(ctx, current_search:, **) - search = ctx[@name].search(current_search) + search = ctx[@name].ransack(current_search) search.sorts = @default_sort_order if search.sorts.empty? ctx["#{@name}_search"] = search diff --git a/spec/lib/macros/base_spec.rb b/spec/lib/macros/base_spec.rb index ee2461f..0270c7d 100644 --- a/spec/lib/macros/base_spec.rb +++ b/spec/lib/macros/base_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true RSpec.describe_current do - subject(:container) { described_class.new(*args) } + subject(:container) { described_class.new(args) } - let(:args) { [{ rand => rand }] } + let(:args) { { key: :value } } describe '.new' do it 'expect to store arguments' do diff --git a/spec/lib/macros/contract/build_spec.rb b/spec/lib/macros/contract/build_spec.rb index 6c24d0d..406cb0f 100644 --- a/spec/lib/macros/contract/build_spec.rb +++ b/spec/lib/macros/contract/build_spec.rb @@ -1,14 +1,11 @@ # frozen_string_literal: true RSpec.describe_current do - subject(:build_step) { described_class.new(*args) } + subject(:call) { instance.call } - let(:args) { { rand => rand } } + let(:instance) { described_class.new(args) } + let(:args) { { name: 'random_name' } } - it 'expect to delegate to trbr contract build' do - expect(Trailblazer::Operation::Contract).to receive(:Build) - .with(*args) - - build_step.call - end + it { expect { call }.not_to raise_error } + it { is_expected.to be_a(Hash) } end diff --git a/spec/lib/macros/contract/persist_spec.rb b/spec/lib/macros/contract/persist_spec.rb index cf34555..406cb0f 100644 --- a/spec/lib/macros/contract/persist_spec.rb +++ b/spec/lib/macros/contract/persist_spec.rb @@ -1,14 +1,11 @@ # frozen_string_literal: true RSpec.describe_current do - subject(:persist_step) { described_class.new(*args) } + subject(:call) { instance.call } - let(:args) { { rand => rand } } + let(:instance) { described_class.new(args) } + let(:args) { { name: 'random_name' } } - it 'expect to delegate to trbr contract build' do - expect(Trailblazer::Operation::Contract).to receive(:Persist) - .with(*args) - - persist_step.call - end + it { expect { call }.not_to raise_error } + it { is_expected.to be_a(Hash) } end diff --git a/spec/lib/macros/contract/validate_spec.rb b/spec/lib/macros/contract/validate_spec.rb index 71d1b0d..51a3674 100644 --- a/spec/lib/macros/contract/validate_spec.rb +++ b/spec/lib/macros/contract/validate_spec.rb @@ -1,14 +1,11 @@ # frozen_string_literal: true RSpec.describe_current do - subject(:validate_step) { described_class.new(*args) } + subject(:call) { instance.call } - let(:args) { { rand => rand } } + let(:instance) { described_class.new(args) } + let(:args) { { name: 'random_name', key: :value } } - it 'expect to delegate to trbr contract build' do - expect(Trailblazer::Operation::Contract).to receive(:Validate) - .with(*args) - - validate_step.call - end + it { expect { call }.not_to raise_error } + it { is_expected.to be_a(Hash) } end diff --git a/spec/lib/macros/model/search_spec.rb b/spec/lib/macros/model/search_spec.rb index 5cc3eec..8c2d21d 100644 --- a/spec/lib/macros/model/search_spec.rb +++ b/spec/lib/macros/model/search_spec.rb @@ -3,7 +3,7 @@ RSpec.describe_current do let(:klass) do Class.new do - def self.search(_current_search); end + def self.ransack(_current_search); end self end