From f1902bdf6deacbadc9638536f8e1e236895ca0a4 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Sat, 22 Jun 2024 10:19:07 +0200 Subject: [PATCH] more tests for Find(). --- lib/trailblazer/macro/model/find.rb | 2 +- test/docs/model/find_test.rb | 33 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/trailblazer/macro/model/find.rb b/lib/trailblazer/macro/model/find.rb index 3c29087..246c595 100644 --- a/lib/trailblazer/macro/model/find.rb +++ b/lib/trailblazer/macro/model/find.rb @@ -16,7 +16,7 @@ def self.Find(model_class, positional_method = nil, find_method: nil, id: "model params_key, block, finder_step_options = if positional_method - bla_explicit_positional(model_class, positional_method, **keyword_options, &block) # FIXME: test block + bla_explicit_positional(model_class, positional_method, **keyword_options, &block) elsif find_method.nil? && query.nil? # translate_from_shorthand bla_shorthand(model_class, **keyword_options, &block) else # options passed explicitly, kws. this still means we need to translate find_method to query, or use user's query. diff --git a/test/docs/model/find_test.rb b/test/docs/model/find_test.rb index c793f27..12136e6 100644 --- a/test/docs/model/find_test.rb +++ b/test/docs/model/find_test.rb @@ -454,6 +454,39 @@ class Update < Trailblazer::Activity::Railway #~ctx_to_result end end +# Positional with params_key block +# +# step Model::Find(Song, :find) { ... } +# +class DocsModelFindPositionalWithParamsBlockTest < Minitest::Spec + Song = Class.new(DocsModelFindPositionaTest::Song) + + module Song::Activity + class Update < Trailblazer::Activity::Railway + step Model::Find(Song, :find) { |ctx, params:, **| params[:params_slug] } + step :validate + step :save + #~meths + include T.def_steps(:validate, :save) + #~meths end + end + end + + #~ctx_to_result + it do + signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Update, {params: {params_slug: 1}, seq: []}) + ctx[:model] #=> # + + assert_equal ctx[:model].inspect, %{#} + end + #~ctx_to_result end + + it "fails" do + signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Update, params: {params_slug: nil}, seq: []) + assert_equal ctx[:model].inspect, %{nil} + end +end + # Positional with #[] # # step Model::Find(Song, :[])