Skip to content

Commit

Permalink
start documenting.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 29, 2024
1 parent aa0dda8 commit ae82ee1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/docs/assertion_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "test_helper"

# Document {Assertion#asserr_pass} and friends.
class DocsAssertionTest < Minitest::Spec
Trailblazer::Test::Assertion.module!(self)

class Memo < Struct.new(:id, :title, :content, :persisted?, :errors)
def save
self[:persisted?] = true
self[:id] = 1
end

module Operation
class Create < Trailblazer::Operation
class Form < Reform::Form
require "reform/form/dry"
include Reform::Form::Dry

property :title
property :content

validation do
params do
required(:title).filled
required(:content).value(min_size?: 8)
end
end
end

step Model::Build(Memo, :new)
step Contract::Build(constant: Form)
step Contract::Validate(key: :memo)
step Contract::Persist()
end
end
end

it "what" do
assert_pass Memo::Operation::Create, {params: {memo: {title: "Todo", content: "Buy beer"}}},
title: "Todo",
persisted?: true,
id: ->(asserted:, **) { asserted.id > 0 }
end
end

0 comments on commit ae82ee1

Please sign in to comment.