Skip to content

Commit

Permalink
test :model_at.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jan 10, 2025
1 parent 1d9d857 commit bb1a8c4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/trailblazer/test/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ class Form < Reform::Form
step :parse_tag_list
step Contract::Persist()

def capture(ctx, **)
ctx[:captured] = CU.inspect(ctx.to_h)
module Capture
def capture(ctx, **)
ctx[:captured] = CU.inspect(ctx.to_h)
end
end
include Capture

def parse_tag_list(ctx, **)
tag_list = ctx["contract.default"].tag_list or return true
Expand Down
31 changes: 30 additions & 1 deletion test/suite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def call
# let(:default_ctx) { {params: {memo: {title: "Note to self", content: "Remember me!"}}} }
# let(:expected_attributes) { {content: "Remember me!", persisted?: true} }
# let(:key_in_params) { :memo }
# it "{#assert_pass} with {:model_at" do
# test = Class.new(Test) do
# Trailblazer::Test::Assertion.module!(self, suite: true)

# let(:operation) { Memo::Operation::Create }
# let(:default_ctx) { {params: {memo: {title: "Note to self", content: "Remember me!"}}} }
# let(:expected_attributes) { {title: "Note to self", content: "Remember me!"} }
# let(:key_in_params) { :memo }
# end
# end

it "#assert_pass" do
# FIXME: test that assert_* returns {ctx}
Expand Down Expand Up @@ -134,7 +144,24 @@ def call
)
end

vvvvvvvvv
Test_for_ModelAt = describe ":model_at" do
let(:operation) do
Class.new(Trailblazer::Operation) do
include Memo::Operation::Create::Capture
step :capture
step :model

def model(ctx, params:, **)
ctx[:record] = Memo.new(**params[:memo])
end
end
end

# 01
it do
@result = assert_pass({title: "Done"}, {title: "Done"}, model_at: :record)
end
end

# test_0006_anonymous
# We accept {:model_at} as a first level kw arg, currently.
Expand Down Expand Up @@ -208,6 +235,8 @@ def assert_test_case_fails(test, number, error_message)
assert_test_case_passes(test, "09", input)
assert_test_case_passes(test, "10", input)

assert_test_case_passes(Test_for_ModelAt, "01", %({:params=>{:memo=>{:title=>\"Done\", :content=>\"Remember me!\"}}}))




Expand Down

0 comments on commit bb1a8c4

Please sign in to comment.