test/docs/pundit_test.rb in trailblazer-2.0.0 vs test/docs/pundit_test.rb in trailblazer-2.0.1

- old
+ new

@@ -1,22 +1,22 @@ require "test_helper" -#:policy -class MyPolicy - def initialize(user, model) - @user, @model = user, model - end + #:policy + class MyPolicy + def initialize(user, model) + @user, @model = user, model + end - def create? - @user == Module && @model.id.nil? - end + def create? + @user == Module && @model.id.nil? + end - def new? - @user == Class + def new? + @user == Class + end end -end -#:policy end + #:policy end #-- # with policy class DocsPunditProcTest < Minitest::Spec Song = Struct.new(:id) @@ -27,10 +27,11 @@ 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 do #:pundit-result @@ -43,14 +44,14 @@ end #--- #- override class New < Create - override Policy::Pundit( MyPolicy, :new? ) + step Policy::Pundit( MyPolicy, :new? ), override: true end - it { New["pipetree"].inspect.must_equal %{[>>operation.new,&model.build,&policy.default.eval]} } + 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>] >} } #--- #- override with :name @@ -58,15 +59,15 @@ step Policy::Pundit( MyPolicy, :create?, name: "first" ) step Policy::Pundit( MyPolicy, :new?, name: "second" ) end class Update < Edit - override Policy::Pundit( MyPolicy, :new?, name: "first" ) + 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["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["pipetree"].inspect.must_equal %{[>operation.new,>policy.first.eval,>policy.second.eval]} } it { Update.({}, "current_user" => Class).inspect("model").must_equal %{<Result:true [nil] >} } #--- # dependency injection class AnotherPolicy < MyPolicy