aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRobert2017-07-10 21:06:07 +0200
committerRobert2017-07-10 21:06:07 +0200
commit1ab9c3364ffcd777dae39bd9154dca031cc00db0 (patch)
tree1df7737a3b03f8b58c36e032301de4aad9c31871 /spec
parent4c7f03108350bf540b6346f864b1ba022119507f (diff)
downloadchouette-core-1ab9c3364ffcd777dae39bd9154dca031cc00db0.tar.bz2
Refs: #4021@0.15h; Fixes Policy Tests
Diffstat (limited to 'spec')
-rw-r--r--spec/policies/calendar_policy_spec.rb4
-rw-r--r--spec/support/pundit/shared_examples.rb30
2 files changed, 31 insertions, 3 deletions
diff --git a/spec/policies/calendar_policy_spec.rb b/spec/policies/calendar_policy_spec.rb
index 57f771c54..294be8198 100644
--- a/spec/policies/calendar_policy_spec.rb
+++ b/spec/policies/calendar_policy_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe CalendarPolicy, type: :policy do
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'calendars.create', archived: true
+ it_behaves_like 'permitted policy', 'calendars.create', archived: true
end
permissions :destroy? do
it_behaves_like 'permitted policy and same organisation', 'calendars.destroy', archived: true
@@ -14,7 +14,7 @@ RSpec.describe CalendarPolicy, type: :policy do
it_behaves_like 'permitted policy and same organisation', 'calendars.update', archived: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'calendars.create', archived: true
+ it_behaves_like 'permitted policy', 'calendars.create', archived: true
end
permissions :update? do
it_behaves_like 'permitted policy and same organisation', 'calendars.update', archived: true
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index b91caa479..63a106759 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -64,7 +64,7 @@ RSpec.shared_examples 'always forbidden' do
end
end
end
-j
+
RSpec.shared_examples 'permitted policy and same organisation' do
| permission, archived: false|
@@ -101,3 +101,31 @@ RSpec.shared_examples 'permitted policy and same organisation' do
end
end
end
+
+RSpec.shared_examples 'permitted policy' do
+ | permission, archived: false|
+
+ context 'permission absent → ' do
+ it "denies user" do
+ expect_it.not_to permit(user_context, record)
+ end
+ end
+
+ context 'permission present → ' do
+ before do
+ add_permissions(permission, for_user: user)
+ end
+
+ it 'allows user' do
+ expect_it.to permit(user_context, record)
+ end
+
+ if archived
+ it 'removes the permission for archived referentials' do
+ user.organisation_id = referential.organisation_id
+ referential.archived_at = 42.seconds.ago
+ expect_it.not_to permit(user_context, record)
+ end
+ end
+ end
+end