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