Select Git revision
text_policy_spec.rb 1.70 KiB
require "rails_helper"
RSpec.describe TextPolicy do
subject { described_class.new(user, text) }
let(:text) { FactoryBot.create(:text) }
context "for an applicant" do
let(:user) { FactoryBot.create(:user, :applicant) }
it { is_expected.to forbid_action(:index) }
it { is_expected.to forbid_action(:show) }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
it { is_expected.to forbid_action(:destroy) }
end
context "for an apprentice" do
let(:user) { FactoryBot.create(:user, :apprentice) }
it { is_expected.to forbid_action(:index) }
it { is_expected.to forbid_action(:show) }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
it { is_expected.to forbid_action(:destroy) }
end
context "for an editor" do
let(:user) { FactoryBot.create(:user, :editor) }
it { is_expected.to forbid_action(:index) }
it { is_expected.to forbid_action(:show) }
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
it { is_expected.to forbid_action(:destroy) }
end
context "for an admin" do
let(:user) { FactoryBot.create(:user, :admin) }
it { is_expected.to permit_action(:index) }
it { is_expected.to permit_action(:show) }
it { is_expected.to permit_new_and_create_actions }
it { is_expected.to permit_edit_and_update_actions }
it { is_expected.to permit_action(:destroy) }
end
describe "Scope" do
let(:user) { FactoryBot.create(:user) }
it "returns all texts" do
expect(described_class::Scope.new(user, Text.all).resolve).to eq(Text.all)
end
end
end