Sha256: 64ac9bfb65e49d129f3ed470e9aa0d420b287952aa76a25e707b63dcdb81f7e0
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require "test_helper" class DocsOperationExampleTest < Minitest::Spec Song = Struct.new(:id, :title, :created_by) do def save; true; end end #:op class Song::Create < Trailblazer::Operation extend Contract::DSL contract do property :title validates :title, presence: true end step Model( Song, :new ) consider :assign_current_user! step Contract::Build() step Contract::Validate( ) failure :log_error! step Contract::Persist( ) def log_error!(options) # .. end def assign_current_user!(options) options["model"].created_by = options["current_user"] end end #:op end it { Song::Create.({ }).inspect("model").must_equal %{<Result:false [#<struct DocsOperationExampleTest::Song id=nil, title=nil, created_by=nil>] >} } it { Song::Create.({ title: "Nothin'" }, "current_user"=>Module).inspect("model").must_equal %{<Result:true [#<struct DocsOperationExampleTest::Song id=nil, title="Nothin'", created_by=Module>] >} } end class DndTest < Minitest::Spec class Create < Trailblazer::Operation consider :authorize! failure :auth_err! consider :save! self.< Wrap end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
trailblazer-2.0.0.beta2 | test/docs/operation_test.rb |