spec/tram/policy_spec.rb in tram-policy-0.0.1 vs spec/tram/policy_spec.rb in tram-policy-0.0.2

- old
+ new

@@ -3,11 +3,13 @@ I18n.available_locales = %w[en] class Test::UserPolicy < Tram::Policy param :user - validate :name, "email", %w[email name] + validate :name + validate "email" + validate "name" private def name errors.add "No name", level: "warning" unless user.name @@ -50,9 +52,29 @@ expect(user).to receive(:name).once.ordered expect(user).to receive(:email).once.ordered expect(user).to receive(:login).once.ordered Test::AdminPolicy.new(user) + end + + context "when :stop_on_failure is set" do + before { Test::UserPolicy.validate :name, stop_on_failure: true } + + it "stops validation after failure" do + expect(user).to receive(:name).once + expect(user).not_to receive(:email) + + Test::UserPolicy.new(user) + end + + it "continues validation after success" do + user = double :user, name: "Andy", email: nil, login: nil + + expect(user).to receive(:name).once.ordered + expect(user).to receive(:email).once.ordered + + Test::UserPolicy.new(user) + end end end describe "#inspect" do subject { policy.inspect }