Skip to content

Commit

Permalink
add more docs tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Nov 9, 2023
1 parent 8f4d3f0 commit ea4616c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/docs/mechanics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,65 @@ def validate(ctx, params:, **)

result = Memo::Operation::Create.call(params: {memo: nil})
assert_equal result.success?, true

user = Object
assert_raises ArgumentError do
#:kwargs-error
result = Memo::Operation::Create.call(current_user: user)
#=> ArgumentError: missing keyword: :params
# memo/operation/create.rb:9:in `validate'
#:kwargs-error end
end
end
end

class WriteToCtx_DocsMechanicsTest < Minitest::Spec
Memo = Class.new do
def initialize(*); end
end
it "what" do
#:ctx-write-read
module Memo::Operation
class Create < Trailblazer::Operation
step :validate
step :save # sets ctx[:model]
step :notify
#~body
#~meths
def validate(ctx, params:, **)
true
end

def send_email(*)
true
end
#~meths end
#:ctx-write
def save(ctx, params:, **)
ctx[:model] = Memo.new(params[:memo])
end
#~body end
#:ctx-write end
def notify(ctx, model:, **)
send_email(model)
end
end
end
#:ctx-write-read end

result = Memo::Operation::Create.call(params: {memo: nil})
assert_equal result.success?, true

user = Object
assert_raises ArgumentError do
#:kwargs-error
result = Memo::Operation::Create.call(current_user: user)
#=> ArgumentError: missing keyword: :params
# memo/operation/create.rb:9:in `validate'
#:kwargs-error end
end
end
end

class Classmethod_DocsMechanicsTest < Minitest::Spec
Memo = Module.new
Expand Down

0 comments on commit ea4616c

Please sign in to comment.