From 15e1621566d29d61dcc24642a47beba1257c87b1 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Sat, 11 Apr 2015 01:26:32 +0300 Subject: [PATCH] #465: Added specs for HookPolicy --- spec/policies/hook_policy_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/policies/hook_policy_spec.rb diff --git a/spec/policies/hook_policy_spec.rb b/spec/policies/hook_policy_spec.rb new file mode 100644 index 000000000..dc98c2dd7 --- /dev/null +++ b/spec/policies/hook_policy_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +RSpec.describe HookPolicy, type: :policy do + let(:hook) { FactoryGirl.build(:hook) } + subject { described_class } + + %i(show? read? create? destroy? update?).each do |perm| + permissions perm do + it "denies access to anonymous user" do + expect(subject).to_not permit(User.new, hook) + end + + it "denies access if user can not update a project" do + allow_any_instance_of(ProjectPolicy).to receive(:update?).and_return(false) + expect(subject).to_not permit(User.new, hook) + end + + it "grants access if user can update a project" do + allow_any_instance_of(ProjectPolicy).to receive(:update?).and_return(true) + expect(subject).to permit(User.new, hook) + end + end + end + +end