|
3 | 3 | require "rails_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe EventProcedurePolicy do |
6 | | - subject(:policy) { described_class } |
7 | | - |
8 | 6 | let(:user) { create(:user) } |
9 | 7 | let(:event_procedure) { create(:event_procedure, user: user) } |
10 | 8 | let(:other_event_procedure) { create(:event_procedure) } |
|
42 | 40 | end |
43 | 41 | end |
44 | 42 |
|
45 | | - permissions :index?, :create? do |
46 | | - context "when user is nil" do |
47 | | - it { is_expected.not_to permit(nil, event_procedure) } |
| 43 | + describe "permissions" do |
| 44 | + context "when has no user" do |
| 45 | + subject { described_class.new(nil, event_procedure) } |
| 46 | + |
| 47 | + it { is_expected.to forbid_all_actions } |
48 | 48 | end |
49 | 49 |
|
50 | 50 | context "when user is present" do |
51 | | - it { is_expected.to permit(user, event_procedure) } |
| 51 | + subject { described_class.new(user, event_procedure) } |
| 52 | + |
| 53 | + it { is_expected.to permit_actions(%i[index create]) } |
52 | 54 | end |
53 | | - end |
54 | 55 |
|
55 | | - permissions :update?, :destroy? do |
56 | | - it { is_expected.to permit(user, event_procedure) } |
57 | | - it { is_expected.not_to permit(user, other_event_procedure) } |
| 56 | + context "when user is owner" do |
| 57 | + subject { described_class.new(user, event_procedure) } |
| 58 | + |
| 59 | + it { is_expected.to permit_actions(%i[index create update destroy]) } |
| 60 | + end |
| 61 | + |
| 62 | + context "when user is not owner" do |
| 63 | + subject { described_class.new(user, other_event_procedure) } |
| 64 | + |
| 65 | + it { is_expected.to forbid_actions(%i[update destroy]) } |
| 66 | + end |
58 | 67 | end |
59 | 68 | end |
0 commit comments