Skip to content

Commit

Permalink
more tests for Find().
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jun 22, 2024
1 parent 21ef2ad commit f1902bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/trailblazer/macro/model/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions test/docs/model/find_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] #=> #<struct Song id=1, title="Roxanne">

assert_equal ctx[:model].inspect, %{#<struct #{Song} id=1>}
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, :[])
Expand Down

0 comments on commit f1902bd

Please sign in to comment.