test/docs/pundit_test.rb in trailblazer-2.0.7 vs test/docs/pundit_test.rb in trailblazer-2.1.0.beta1

- old
+ new

@@ -27,17 +27,17 @@ step Policy::Pundit( MyPolicy, :create? ) # ... end #:pundit end - it { Create["pipetree"].inspect.must_equal %{[>operation.new,>model.build,>policy.default.eval]} } - it { Create.({}, "current_user" => Module).inspect("model").must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} } - it { Create.({} ).inspect("model").must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} } + it { Trailblazer::Operation::Inspect.(Create).must_equal %{[>model.build,>policy.default.eval]} } + it { Create.(params: {}, current_user: Module).inspect(:model).must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} } + it { Create.(params: {} ).inspect(:model).must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} } it do #:pundit-result - result = Create.({}, "current_user" => Module) + result = Create.(params: {}, current_user: Module) result["result.policy.default"].success? #=> true result["result.policy.default"]["policy"] #=> #<MyPolicy ...> #:pundit-result end result["result.policy.default"].success?.must_equal true result["result.policy.default"]["policy"].is_a?(MyPolicy).must_equal true @@ -47,13 +47,13 @@ #- override class New < Create step Policy::Pundit( MyPolicy, :new? ), override: true end - it { New["pipetree"].inspect.must_equal %{[>operation.new,>model.build,>policy.default.eval]} } - it { New.({}, "current_user" => Class ).inspect("model").must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} } - it { New.({}, "current_user" => nil ).inspect("model").must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} } + it { Trailblazer::Operation::Inspect.(New).must_equal %{[>model.build,>policy.default.eval]} } + it { New.(params: {}, current_user: Class ).inspect(:model).must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} } + it { New.(params: {}, current_user: nil ).inspect(:model).must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} } #--- #- override with :name class Edit < Trailblazer::Operation step Policy::Pundit( MyPolicy, :create?, name: "first" ) @@ -62,14 +62,14 @@ class Update < Edit step Policy::Pundit( MyPolicy, :new?, name: "first" ), override: true end - it { Edit["pipetree"].inspect.must_equal %{[>operation.new,>policy.first.eval,>policy.second.eval]} } - it { Edit.({}, "current_user" => Class).inspect("model").must_equal %{<Result:false [nil] >} } - it { Update["pipetree"].inspect.must_equal %{[>operation.new,>policy.first.eval,>policy.second.eval]} } - it { Update.({}, "current_user" => Class).inspect("model").must_equal %{<Result:true [nil] >} } + it { Trailblazer::Operation::Inspect.(Edit).must_equal %{[>policy.first.eval,>policy.second.eval]} } + it { Edit.(params: {}, current_user: Class).inspect(:model).must_equal %{<Result:false [nil] >} } + it { Trailblazer::Operation::Inspect.(Update).must_equal %{[>policy.first.eval,>policy.second.eval]} } + it { Update.(params: {}, current_user: Class).inspect(:model).must_equal %{<Result:true [nil] >} } #--- # dependency injection class AnotherPolicy < MyPolicy def create? @@ -78,12 +78,12 @@ end it { result = #:di-call - Create.({}, - "current_user" => Module, + Create.(params: {}, + current_user: Module, "policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?) ) #:di-call end result.inspect("").must_equal %{<Result:true [nil] >} } end @@ -101,11 +101,11 @@ end #:name end it { #:name-call - result = Create.({}, "current_user" => Module) + result = Create.(params: {}, current_user: Module) result["result.policy.after_model"].success? #=> true #:name-call end result["result.policy.after_model"].success?.must_equal true } end @@ -121,11 +121,11 @@ # #~pipe--only end # end # #:class-level end # it { Create.(); Create["result.policy"].must_equal nil } -# it { Create.({}, "current_user" => Module)["x"].must_equal true } -# it { Create.({} )["x"].must_equal nil } +# it { Create.(params: {}, current_user: Module)["x"].must_equal true } +# it { Create.(params: {} )["x"].must_equal nil } # end # TODO: