Skip to content

Commit

Permalink
Merge pull request #44 from phortx/fix/inline-do
Browse files Browse the repository at this point in the history
fix: inline do
  • Loading branch information
phortx authored Oct 10, 2022
2 parents 00f1b82 + f830762 commit 1dabba9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails/use_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run_steps
fail!(code: opts[:code], message: opts[:message]) if name == :failure

# Run the lambda, when :do is set. Otherwise call the method.
next if opts[:do] ? instance_eval(&opts[:do]) : send(name)
next if opts[:do] ? instance_exec(&opts[:do]) : send(name)

# result is false, so we have a failure.
fail! code: :step_false, message: "Step '#{name}' returned false"
Expand Down
8 changes: 8 additions & 0 deletions spec/rails/use_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def new_record?
def bar
true
end

def foo
true
end
end

# Test behavior
Expand All @@ -46,6 +50,7 @@ class UseCaseTestImpl < Rails::UseCase
record :order

step :do_things
step :something, do: -> { record.foo }
step { record.bar }

def do_things
Expand Down Expand Up @@ -165,6 +170,9 @@ def do_things
expect_any_instance_of(Order).to \
receive(:bar).and_call_original

expect_any_instance_of(Order).to \
receive(:foo).and_call_original

UseCaseTestImpl.call order: order
end

Expand Down

0 comments on commit 1dabba9

Please sign in to comment.