aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRobert2017-05-24 08:02:31 +0200
committerRobert2017-05-24 08:02:31 +0200
commit571ce311bb44e5042189529cfb63bd09106ddc22 (patch)
treea5efc848ed6cb21339468057ab9bb0871b075027 /spec
parentd5063b73ff1e794d32a73d85880c541113fe29c6 (diff)
downloadchouette-core-571ce311bb44e5042189529cfb63bd09106ddc22.tar.bz2
Refs: #3446; Applying to routes policy
Diffstat (limited to 'spec')
-rw-r--r--spec/policies/route_policy_spec.rb22
-rw-r--r--spec/support/pundit/shared_examples.rb22
2 files changed, 33 insertions, 11 deletions
diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb
new file mode 100644
index 000000000..706ead3a3
--- /dev/null
+++ b/spec/policies/route_policy_spec.rb
@@ -0,0 +1,22 @@
+RSpec.describe RoutePolicy, type: :policy do
+
+ permissions :create? do
+ it_behaves_like 'permitted policy', 'routes.create', restricted_ready: true
+ end
+
+ permissions :destroy? do
+ it_behaves_like 'permitted policy and same organisation', 'routes.destroy', restricted_ready: true
+ end
+
+ permissions :edit? do
+ it_behaves_like 'permitted policy and same organisation', 'routes.edit', restricted_ready: true
+ end
+
+ permissions :new? do
+ it_behaves_like 'permitted policy', 'routes.create', restricted_ready: true
+ end
+
+ permissions :update? do
+ it_behaves_like 'permitted policy and same organisation', 'routes.edit', restricted_ready: true
+ end
+end
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index a5ee5f758..51a25ba7a 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -1,32 +1,32 @@
-RSpec.shared_examples "permitted policy and same organisation" do
+RSpec.shared_examples 'permitted policy and same organisation' do
| permission, restricted_ready: false|
- context "permission absent → " do
+ context 'permission absent → ' do
it "denies a user with a different organisation" do
expect_it.not_to permit(user_context, referential)
end
- it "and also a user with the same organisation" do
+ it 'and also a user with the same organisation' do
user.update_attribute :organisation, referential.organisation
expect_it.not_to permit(user_context, referential)
end
end
- context "permission present → " do
+ context 'permission present → ' do
before do
add_permissions(permission, for_user: user)
end
- it "denies a user with a different organisation" do
+ it 'denies a user with a different organisation' do
expect_it.not_to permit(user_context, referential)
end
- it "but allows it for a user with the same organisation" do
+ it 'but allows it for a user with the same organisation' do
user.update_attribute :organisation, referential.organisation
expect_it.to permit(user_context, referential)
end
if restricted_ready
- it "removes the permission for archived referentials" do
+ it 'removes the permission for archived referentials' do
user.update_attribute :organisation, referential.organisation
referential.update_attribute :ready, true
expect_it.not_to permit(user_context, referential)
@@ -37,21 +37,21 @@ end
RSpec.shared_examples 'permitted policy' do
| permission, restricted_ready: false|
- context "permission absent → " do
+ context 'permission absent → ' do
it "denies a user with a different organisation" do
expect_it.not_to permit(user_context, referential)
end
end
- context "permission present → " do
+ context 'permission present → ' do
before do
add_permissions(permission, for_user: user)
end
- it "allows a user with a different organisation" do
+ it 'allows a user with a different organisation' do
expect_it.to permit(user_context, referential)
end
if restricted_ready
- it "removes the permission for archived referentials" do
+ it 'removes the permission for archived referentials' do
referential.update_attribute :ready, true
expect_it.not_to permit(user_context, referential)
end