aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRobert2017-07-05 11:54:33 +0200
committerRobert2017-07-05 11:59:06 +0200
commite53aa88c442bd0057c4e0ae66e2684d62d3193ed (patch)
tree1ba7c8c082dde92ba215659fde9293e231e7c7df /spec
parent841bd65847066e92bf5a4d6de112fed1ada73c1c (diff)
downloadchouette-core-e53aa88c442bd0057c4e0ae66e2684d62d3193ed.tar.bz2
Refs: #3478@1h;
- All permissions tied to `!archived?` - Tests adapted - Policies refactored ? Is `create?` permission bound to `organisation_match?`
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/table_builder_helper/custom_links_spec.rb1
-rw-r--r--spec/helpers/table_builder_helper_spec.rb5
-rw-r--r--spec/policies/routing_constraint_zone_policy_spec.rb4
-rw-r--r--spec/policies/time_table_policy_spec.rb11
-rw-r--r--spec/support/apartment_stubbing.rb14
5 files changed, 24 insertions, 11 deletions
diff --git a/spec/helpers/table_builder_helper/custom_links_spec.rb b/spec/helpers/table_builder_helper/custom_links_spec.rb
index bd0bd4fcf..4b07922a7 100644
--- a/spec/helpers/table_builder_helper/custom_links_spec.rb
+++ b/spec/helpers/table_builder_helper/custom_links_spec.rb
@@ -10,6 +10,7 @@ describe TableBuilderHelper::CustomLinks do
referential: referential
)
+ stub_policy_scope(referential)
expect(
TableBuilderHelper::CustomLinks.new(
referential,
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 6b505c940..4afd0774c 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -27,6 +27,7 @@ describe TableBuilderHelper, type: :helper do
referentials = [referential]
allow(referentials).to receive(:model).and_return(Referential)
+ stub_policy_scope(referential)
allow(helper).to receive(:params).and_return({
controller: 'workbenches',
@@ -193,7 +194,7 @@ describe TableBuilderHelper, type: :helper do
companies,
with: CompanyDecorator
)
- allow(CompanyDecorator).to receive(:where).with(id: company.id).and_return double.as_null_object
+ stub_policy_scope(company)
expected = <<-HTML
<table class="table has-search">
@@ -303,7 +304,7 @@ describe TableBuilderHelper, type: :helper do
with: CompanyDecorator,
context: {line_referential: line_referential}
)
- allow(CompanyDecorator).to receive(:where).with(id: company.id).and_return double.as_null_object
+ stub_policy_scope(company)
expected = <<-HTML
<table class="table has-search">
diff --git a/spec/policies/routing_constraint_zone_policy_spec.rb b/spec/policies/routing_constraint_zone_policy_spec.rb
index 2508b49f9..f91313390 100644
--- a/spec/policies/routing_constraint_zone_policy_spec.rb
+++ b/spec/policies/routing_constraint_zone_policy_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe RoutingConstraintZonePolicy, type: :policy do
permissions :create? do
- it_behaves_like 'permitted policy', 'routing_constraint_zones.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived: true
end
permissions :destroy? do
@@ -16,7 +16,7 @@ RSpec.describe RoutingConstraintZonePolicy, type: :policy do
end
permissions :new? do
- it_behaves_like 'permitted policy', 'routing_constraint_zones.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived: true
end
permissions :update? do
diff --git a/spec/policies/time_table_policy_spec.rb b/spec/policies/time_table_policy_spec.rb
index 90e6600ea..6c19362d2 100644
--- a/spec/policies/time_table_policy_spec.rb
+++ b/spec/policies/time_table_policy_spec.rb
@@ -3,8 +3,10 @@ RSpec.describe TimeTablePolicy, type: :policy do
let( :record ){ build_stubbed :time_table }
- permissions :duplicate? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
+ %w{create duplicate}.each do | permission |
+ permissions "#{permission}?".to_sym do
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
+ end
end
%w{destroy edit}.each do | permission |
@@ -13,9 +15,4 @@ RSpec.describe TimeTablePolicy, type: :policy do
end
end
- permissions :create? do
- it_behaves_like 'permitted policy', 'time_tables.create', archived: true
- end
-
-
end
diff --git a/spec/support/apartment_stubbing.rb b/spec/support/apartment_stubbing.rb
new file mode 100644
index 000000000..408d3b878
--- /dev/null
+++ b/spec/support/apartment_stubbing.rb
@@ -0,0 +1,14 @@
+module Support
+ # This is needed for referentials that are stubbed with `build_stubbed`
+ # As one cannot switch to such referentials (obviously the schema does not exist)
+ # we provide a stub for `scope.where(...` needed in ApplicationPolicy#show
+ module ApartmentStubbing
+ def stub_policy_scope(model)
+ allow(model.class).to receive(:where).with(id: model.id).and_return double("instance of #{model.class}").as_null_object
+ end
+ end
+end
+
+RSpec.configure do | conf |
+ conf.include Support::ApartmentStubbing
+end