#465: Added specs for TokenPolicy

This commit is contained in:
Vokhmin Alexey V 2015-04-14 00:22:41 +03:00
parent 4a5610983d
commit 13de6b93c7
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
require 'spec_helper'
RSpec.describe TokenPolicy, type: :policy do
let(:token) { FactoryGirl.build(:platform_token) }
subject { described_class }
%i(show? create? read? withdraw?).each do |perm|
permissions perm do
it "denies access to user" do
expect(subject).to_not permit(User.new, token)
end
it "grants access to owner of platform" do
allow_any_instance_of(TokenPolicy).to receive(:owner?).and_return(true)
expect(subject).to permit(User.new, token)
end
it "grants access to admin of platform" do
allow_any_instance_of(TokenPolicy).to receive(:local_admin?).and_return(true)
expect(subject).to permit(User.new, token)
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.build(:admin), token)
end
end
end
end