From 751c820d80174ef06e3e11215e95f8bccc72e546 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Sat, 11 Apr 2015 01:40:11 +0300 Subject: [PATCH] #465: Added specs for KeyPairPolicy --- spec/policies/key_pair_policy_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/policies/key_pair_policy_spec.rb diff --git a/spec/policies/key_pair_policy_spec.rb b/spec/policies/key_pair_policy_spec.rb new file mode 100644 index 000000000..879d45e19 --- /dev/null +++ b/spec/policies/key_pair_policy_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +RSpec.describe KeyPairPolicy, type: :policy do + let(:key_pair) { FactoryGirl.build(:key_pair) } + subject { described_class } + + %i(create? destroy?).each do |perm| + permissions perm do + it "denies access to user" do + expect(subject).to_not permit(User.new, key_pair) + end + + it "grants access for admin of platform" do + allow_any_instance_of(KeyPairPolicy).to receive(:local_admin?). + with(key_pair.repository.platform).and_return(true) + expect(subject).to permit(User.new, key_pair) + end + + it "grants access for to global admin" do + expect(subject).to permit(FactoryGirl.build(:admin), key_pair) + end + end + end + +end