From f830762747a85bc378fd473a1b33c19620c6854f Mon Sep 17 00:00:00 2001 From: phortx Date: Mon, 10 Oct 2022 10:12:03 +0200 Subject: [PATCH] fix: inline do --- lib/rails/use_case.rb | 2 +- spec/rails/use_case_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rails/use_case.rb b/lib/rails/use_case.rb index d359253..bc1bb7f 100644 --- a/lib/rails/use_case.rb +++ b/lib/rails/use_case.rb @@ -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" diff --git a/spec/rails/use_case_spec.rb b/spec/rails/use_case_spec.rb index ab5dc81..e154a60 100644 --- a/spec/rails/use_case_spec.rb +++ b/spec/rails/use_case_spec.rb @@ -26,6 +26,10 @@ def new_record? def bar true end + + def foo + true + end end # Test behavior @@ -46,6 +50,7 @@ class UseCaseTestImpl < Rails::UseCase record :order step :do_things + step :something, do: -> { record.foo } step { record.bar } def do_things @@ -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