Initial commit
This commit is contained in:
60
spec/policies/video_policy_spec.rb
Normal file
60
spec/policies/video_policy_spec.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe VideoPolicy do
|
||||
let(:user) { build(:user) }
|
||||
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
|
||||
|
||||
subject { described_class }
|
||||
|
||||
permissions :create? do
|
||||
it { is_expected.to permit(:create) }
|
||||
end
|
||||
|
||||
permissions :show? do
|
||||
it { is_expected.to permit(:show) }
|
||||
end
|
||||
|
||||
permissions :update? do
|
||||
it { is_expected.to permit(:update) }
|
||||
end
|
||||
|
||||
permissions ".scope" do
|
||||
let!(:member_video) { create(:video, project: build(:project, name: "Member Project", account: user.primary_account)) }
|
||||
let!(:non_member_video) { create(:video, project: build(:project, name: "Non-Member Project", account: user.primary_account)) }
|
||||
let!(:outside_video) { create(:video, project: build(:project, name: "Outside Project", account: build(:account))) }
|
||||
|
||||
subject { Pundit.policy_scope!(user_context, Video) }
|
||||
|
||||
context "for an associate" do
|
||||
let(:user) { create(:user, :associate) }
|
||||
|
||||
before do
|
||||
create(:project_membership, project: member_video.project, user: user)
|
||||
end
|
||||
|
||||
it { is_expected.to include(member_video) }
|
||||
it { is_expected.not_to include(non_member_video) }
|
||||
it { is_expected.not_to include(outside_video) }
|
||||
end
|
||||
|
||||
context "for a manager" do
|
||||
let(:user) { create(:user, :manager) }
|
||||
|
||||
before do
|
||||
create(:project_membership, project: member_video.project, user: user)
|
||||
end
|
||||
|
||||
it { is_expected.to include(member_video) }
|
||||
it { is_expected.not_to include(non_member_video) }
|
||||
it { is_expected.not_to include(outside_video) }
|
||||
end
|
||||
|
||||
context "for an account manager" do
|
||||
let(:user) { create(:user, :account_manager) }
|
||||
|
||||
it { is_expected.to include(member_video) }
|
||||
it { is_expected.to include(non_member_video) }
|
||||
it { is_expected.not_to include(outside_video) }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user