Skip to content

Commit

Permalink
Permit Operation.call even if responder plugin is not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloh committed Feb 4, 2019
1 parent 400536d commit cb755e0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
### Changed
- Changed behavior for `:after_commit` step wrapper, on `:sequel_models` plugin, to capture current state and reuse it later when executing.

### Fixed
- Allow invoking `call` directly on an operation class even if the `:responder` plugin is not loaded.

## [0.8.0] - 2018-10-01
### Changed
- Added support for `dry-validation` 0.12.x
Expand All @@ -17,7 +20,7 @@
- Allow `authorization` block to take multiple parameters on `simple_auth` plugin.

## [0.6.2] - 2018-05-19
### Fixes
### Fixed
- Allow `:error_message` option for `sequel_models` plugin to propagate down inherited classes

## [0.6.1] - 2018-03-16
Expand Down
5 changes: 4 additions & 1 deletion lib/pathway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module Plugins
module Base
module ClassMethods
attr_accessor :result_key
alias :result_at :result_key=

def process(&bl)
dsl = self::DSL
Expand All @@ -87,7 +88,9 @@ def process(&bl)
end
end

alias :result_at :result_key=
def call(ctx, *params)
new(ctx).call(*params)
end

def inherited(subclass)
super
Expand Down
2 changes: 1 addition & 1 deletion lib/pathway/plugins/responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Plugins
module Responder
module ClassMethods
def call(ctx, *params, &bl)
result = new(ctx).call(*params)
result = super(ctx, *params)
block_given? ? Responder.respond(result, &bl) : result
end
end
Expand Down
16 changes: 13 additions & 3 deletions spec/plugins/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Pathway
module Plugins
describe Base do

class OperationWithSteps < Operation
context :validator, :back_end, :notifier, :cond
result_at :result_value
Expand Down Expand Up @@ -61,9 +62,8 @@ def notify(state)
let(:notifier) { double }
let(:cond) { double }

subject(:operation) do
OperationWithSteps.new(validator: validator, back_end: back_end, notifier: notifier, cond: cond)
end
let(:ctx) { { validator: validator, back_end: back_end, notifier: notifier, cond: cond } }
subject(:operation) { OperationWithSteps.new(ctx) }

before do
allow(validator).to receive(:call) do |input:, **|
Expand Down Expand Up @@ -99,6 +99,16 @@ def notify(state)
end
end

describe ".call" do
let(:result) { OperationWithSteps.call(ctx, input) }
it "creates a new instance an invokes the 'call' method on it" do
expect(back_end).to receive(:call).and_return(:SOME_RETURN_VALUE)

expect(result).to be_a_success
expect(result.value).to eq(:SOME_RETURN_VALUE)
end
end

describe "#set" do
it "defines an updating step which sets the result key if no key is specified" do
expect(back_end).to receive(:call).and_return(:SOME_VALUE)
Expand Down
3 changes: 1 addition & 2 deletions spec/plugins/sequel_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class ChainedOperation < MyOperation
end

def chain_operation(input:,**)
opr = MailerOperation.new(mailer: @mailer)
opr.call(input)
MailerOperation.call(context, input)
end
end

Expand Down

0 comments on commit cb755e0

Please sign in to comment.