test/docs/model_test.rb in trailblazer-2.0.6 vs test/docs/model_test.rb in trailblazer-2.0.7
- old
+ new
@@ -3,10 +3,14 @@
class DocsModelTest < Minitest::Spec
Song = Struct.new(:id, :title) do
def self.find_by(id:nil)
id.nil? ? nil : new(id)
end
+
+ def self.[](id)
+ id.nil? ? nil : new(id+99)
+ end
end
#:op
class Create < Trailblazer::Operation
step Model( Song, :new )
@@ -44,9 +48,28 @@
result = Update.({})
result["model"] #=> nil
result.success? #=> false
#:update-fail end
- result["model"].must_equal nil
+ result["model"].must_be_nil
result.success?.must_equal false
+ end
+
+ #:show
+ class Show < Trailblazer::Operation
+ step Model( Song, :[] )
+ # ..
+ end
+ #:show end
+
+ it do
+ result = Show.({ id: 1 })
+
+ #:show-ok
+ result = Show.({ id: 1 })
+ result["model"] #=> #<struct Song id=1, title="Roxanne">
+ #:show-ok end
+
+ result.success?.must_equal true
+ result["model"].inspect.must_equal %{#<struct DocsModelTest::Song id=100, title=nil>}
end
end