aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/custom_fields.rb9
-rw-r--r--spec/factories/workbenches.rb1
-rw-r--r--spec/factories/workgroups.rb7
-rw-r--r--spec/features/safe_submit_spec.rb9
-rw-r--r--spec/helpers/table_builder_helper_spec.rb3
-rw-r--r--spec/javascript/journey_patterns/components/JourneyPatterns_spec.js77
-rw-r--r--spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap169
-rw-r--r--spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js80
-rw-r--r--spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap181
-rw-r--r--spec/models/chouette/stop_area_spec.rb9
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb5
-rw-r--r--spec/models/custom_field_spec.rb27
-rw-r--r--spec/models/referential_spec.rb38
-rw-r--r--spec/models/workbench_spec.rb1
-rw-r--r--spec/models/workgroup_spec.rb30
-rw-r--r--spec/policies/access_link_policy_spec.rb10
-rw-r--r--spec/policies/access_point_policy_spec.rb10
-rw-r--r--spec/policies/company_policy_spec.rb5
-rw-r--r--spec/policies/connection_link_policy_spec.rb10
-rw-r--r--spec/policies/group_of_line_policy_spec.rb14
-rw-r--r--spec/policies/journey_pattern_policy_spec.rb10
-rw-r--r--spec/policies/line_policy_spec.rb11
-rw-r--r--spec/policies/network_policy_spec.rb14
-rw-r--r--spec/policies/purchase_window_policy_spec.rb6
-rw-r--r--spec/policies/referential_policy_spec.rb8
-rw-r--r--spec/policies/route_policy_spec.rb12
-rw-r--r--spec/policies/routing_constraint_zone_policy_spec.rb10
-rw-r--r--spec/policies/stop_area_policy_spec.rb4
-rw-r--r--spec/policies/time_table_policy_spec.rb10
-rw-r--r--spec/support/pundit/policies.rb5
-rw-r--r--spec/support/pundit/shared_examples.rb51
31 files changed, 742 insertions, 94 deletions
diff --git a/spec/factories/custom_fields.rb b/spec/factories/custom_fields.rb
new file mode 100644
index 000000000..2f5fae555
--- /dev/null
+++ b/spec/factories/custom_fields.rb
@@ -0,0 +1,9 @@
+FactoryGirl.define do
+ factory :custom_field do
+ code "code"
+ resource_type "VehicleJourney"
+ sequence(:name){|n| "custom field ##{n}"}
+ field_type "list"
+ options( { "capacity" => "0" } )
+ end
+end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index 0f26559d8..98fdd6ad9 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -7,5 +7,6 @@ FactoryGirl.define do
association :line_referential
association :stop_area_referential
association :output, factory: :referential_suite
+ association :workgroup
end
end
diff --git a/spec/factories/workgroups.rb b/spec/factories/workgroups.rb
new file mode 100644
index 000000000..792deddf8
--- /dev/null
+++ b/spec/factories/workgroups.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :workgroup do
+ sequence(:name) { |n| "Workgroup ##{n}" }
+ association :line_referential
+ association :stop_area_referential
+ end
+end
diff --git a/spec/features/safe_submit_spec.rb b/spec/features/safe_submit_spec.rb
new file mode 100644
index 000000000..9968d4310
--- /dev/null
+++ b/spec/features/safe_submit_spec.rb
@@ -0,0 +1,9 @@
+RSpec.describe 'SafeSubmit', type: :feature do
+ login_user
+
+ let( :path ){ new_api_key_path() }
+ it 'view shows the corresponding buttons' do
+ visit path
+ expect(page).to have_css('input[type=submit][data-disable-with]')
+ end
+end
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 83b746d4b..e82697b0a 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'htmlbeautifier'
module TableBuilderHelper
@@ -105,7 +106,7 @@ describe TableBuilderHelper, type: :helper do
TableBuilderHelper::Column.new(
key: :status,
attribute: Proc.new do |w|
- if w.archived?
+ if w.referential_read_only?
("<div class='td-block'><span class='fa fa-archive'></span><span>Conservé</span></div>").html_safe
else
("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div>").html_safe
diff --git a/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js b/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js
new file mode 100644
index 000000000..0c852deff
--- /dev/null
+++ b/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js
@@ -0,0 +1,77 @@
+import React, { Component } from 'react'
+import JourneyPatterns from '../../../../app/javascript/journey_patterns/components/JourneyPatterns'
+import renderer from 'react-test-renderer'
+
+describe('stopPointHeader', () => {
+ set('features', () => {
+ return {}
+ })
+ set('component', () => {
+ let props = {
+ status: {
+ features: features
+ },
+ onCheckboxChange: ()=>{},
+ onLoadFirstPage: ()=>{},
+ onOpenEditModal: ()=>{},
+ stopPointsList: [stop_point, same_city_stop_point, other_country_stop_point],
+ journeyPatterns: []
+ }
+ let list = renderer.create(
+ <JourneyPatterns
+ status={props.status}
+ journeyPatterns={props.journeyPatterns}
+ stopPointsList={props.stopPointsList}
+ onCheckboxChange={props.onCheckboxChange}
+ onLoadFirstPage={props.onLoadFirstPage}
+ onOpenEditModal={props.onOpenEditModal}
+ />
+ ).toJSON()
+
+ return list
+ })
+
+ set('stop_point', () => {
+ return {
+ name: "Stop point",
+ city_name: "City Name",
+ zip_code: "12345",
+ country_code: "FR",
+ country_name: "france",
+ object_id: "sp-FR"
+ }
+ })
+
+ set('same_city_stop_point', () => {
+ return {
+ name: "Antother stop point",
+ city_name: stop_point.city_name,
+ zip_code: stop_point.zip_code,
+ country_code: stop_point.country_code,
+ country_name: stop_point.country_name,
+ object_id: stop_point.object_id + "-2"
+ }
+ })
+
+ set('other_country_stop_point', () => {
+ return {
+ name: "Antother stop point",
+ city_name: "New York",
+ zip_code: "232323",
+ country_code: "US",
+ country_name: "USA",
+ object_id: "sp-USA"
+ }
+ })
+ it('should display the city name', () => {
+ expect(component).toMatchSnapshot()
+ })
+ context('with the "long_distance_routes" feature', () => {
+ set('features', () => {
+ return { long_distance_routes: true }
+ })
+ it('should display the country name', () => {
+ expect(component).toMatchSnapshot()
+ })
+ })
+})
diff --git a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap
new file mode 100644
index 000000000..a332e7d80
--- /dev/null
+++ b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap
@@ -0,0 +1,169 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`stopPointHeader should display the city name 1`] = `
+<div
+ className="row"
+>
+ <div
+ className="col-lg-12"
+ >
+ <div
+ className="table table-2entries mt-sm mb-sm no_result"
+ >
+ <div
+ className="t2e-head w20"
+ >
+ <div
+ className="th"
+ >
+ <div
+ className="strong mb-xs"
+ >
+ ID Mission
+ </div>
+ <div>
+ Code mission
+ </div>
+ <div>
+ Nb arrêts
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="City Name"
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className=""
+ data-headline=""
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="New York"
+ title="New York (232323)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div
+ className="t2e-item-list w80"
+ >
+ <div />
+ </div>
+ </div>
+ </div>
+</div>
+`;
+
+exports[`stopPointHeader with the "long_distance_routes" feature should display the country name 1`] = `
+<div
+ className="row"
+>
+ <div
+ className="col-lg-12"
+ >
+ <div
+ className="table table-2entries mt-sm mb-sm no_result"
+ >
+ <div
+ className="t2e-head w20"
+ >
+ <div
+ className="th"
+ >
+ <div
+ className="strong mb-xs"
+ >
+ ID Mission
+ </div>
+ <div>
+ Code mission
+ </div>
+ <div>
+ Nb arrêts
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="france"
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className=""
+ data-headline=""
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="USA"
+ title="New York (232323)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div
+ className="t2e-item-list w80"
+ >
+ <div />
+ </div>
+ </div>
+ </div>
+</div>
+`;
diff --git a/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
new file mode 100644
index 000000000..87151c64b
--- /dev/null
+++ b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
@@ -0,0 +1,80 @@
+import React, { Component } from 'react'
+import VehicleJourneys from '../../../../app/javascript/vehicle_journeys/components/VehicleJourneys'
+import renderer from 'react-test-renderer'
+
+describe('stopPointHeader', () => {
+ set('features', () => {
+ return {}
+ })
+ set('component', () => {
+ let props = {
+ status: {},
+ filters: {
+ permissions: {},
+ features: features
+ },
+ onLoadFirstPage: ()=>{},
+ onUpdateTime: ()=>{},
+ onSelectVehicleJourney: ()=>{},
+ stopPointsList: [stop_point, same_city_stop_point, other_country_stop_point],
+ vehicleJourneys: []
+ }
+ let list = renderer.create(
+ <VehicleJourneys
+ status={props.status}
+ filters={props.filters}
+ onLoadFirstPage={props.onLoadFirstPage}
+ onUpdateTime={props.onUpdateTime}
+ onSelectVehicleJourney={props.onSelectVehicleJourney}
+ stopPointsList={props.stopPointsList}
+ vehicleJourneys={props.vehicleJourneys}
+ />
+ ).toJSON()
+
+ return list
+ })
+
+ set('stop_point', () => {
+ return {
+ name: "Stop point",
+ city_name: "City Name",
+ zip_code: "12345",
+ country_code: "FR",
+ country_name: "france",
+ object_id: "sp-FR"
+ }
+ })
+
+ set('same_city_stop_point', () => {
+ return {
+ name: "Antother stop point",
+ city_name: stop_point.city_name,
+ zip_code: stop_point.zip_code,
+ country_code: stop_point.country_code,
+ country_name: stop_point.country_name,
+ object_id: stop_point.object_id + "-2"
+ }
+ })
+
+ set('other_country_stop_point', () => {
+ return {
+ name: "Antother stop point",
+ city_name: "New York",
+ zip_code: "232323",
+ country_code: "US",
+ country_name: "USA",
+ object_id: "sp-USA"
+ }
+ })
+ it('should display the city name', () => {
+ expect(component).toMatchSnapshot()
+ })
+ context('with the "long_distance_routes" feature', () => {
+ set('features', () => {
+ return { long_distance_routes: true }
+ })
+ it('should display the country name', () => {
+ expect(component).toMatchSnapshot()
+ })
+ })
+})
diff --git a/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
new file mode 100644
index 000000000..703f727d7
--- /dev/null
+++ b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
@@ -0,0 +1,181 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`stopPointHeader should display the city name 1`] = `
+<div
+ className="row"
+>
+ <div
+ className="col-lg-12"
+ >
+ <div
+ className="table table-2entries mt-sm mb-sm no_result"
+ >
+ <div
+ className="t2e-head w20"
+ >
+ <div
+ className="th"
+ >
+ <div
+ className="strong mb-xs"
+ >
+ ID course
+ </div>
+ <div>
+ Nom course
+ </div>
+ <div>
+ ID mission
+ </div>
+ <div>
+ Transporteur
+ </div>
+ <div>
+ Calendriers
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="City Name"
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className=""
+ data-headline=""
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="New York"
+ title="New York (232323)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div
+ className="t2e-item-list w80"
+ >
+ <div />
+ </div>
+ </div>
+ </div>
+</div>
+`;
+
+exports[`stopPointHeader with the "long_distance_routes" feature should display the country name 1`] = `
+<div
+ className="row"
+>
+ <div
+ className="col-lg-12"
+ >
+ <div
+ className="table table-2entries mt-sm mb-sm no_result"
+ >
+ <div
+ className="t2e-head w20"
+ >
+ <div
+ className="th"
+ >
+ <div
+ className="strong mb-xs"
+ >
+ ID course
+ </div>
+ <div>
+ Nom course
+ </div>
+ <div>
+ ID mission
+ </div>
+ <div>
+ Transporteur
+ </div>
+ <div>
+ Calendriers
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="france"
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className=""
+ data-headline=""
+ title="City Name (12345)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ <div
+ className="td"
+ >
+ <div
+ className="headlined"
+ data-headline="USA"
+ title="New York (232323)"
+ >
+ <span>
+ <span>
+ Antother stop point
+ </span>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div
+ className="t2e-item-list w80"
+ >
+ <div />
+ </div>
+ </div>
+ </div>
+</div>
+`;
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index 9db0f11a5..a90e5d816 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'spec_helper'
describe Chouette::StopArea, :type => :model do
@@ -460,6 +461,14 @@ describe Chouette::StopArea, :type => :model do
expect(stop_area.errors).to have_key(:parent_id)
end
+ it "use parent area type label in validation error message" do
+ stop_area.area_type = 'zdep'
+ stop_area.parent.area_type = 'zdep'
+
+ stop_area.valid?
+ expect(stop_area.errors[:parent_id].first).to include(Chouette::AreaType.find(stop_area.parent.area_type).label)
+ end
+
end
describe '#waiting_time' do
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index eb2a31794..3ec2387e5 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -399,8 +399,7 @@ describe Chouette::VehicleJourney, :type => :model do
end
describe ".where_departure_time_between" do
- it "selects vehicle journeys whose departure times are between the
- specified range" do
+ it "selects vehicle journeys whose departure times are between the specified range" do
journey_early = create(
:vehicle_journey,
stop_departure_time: '02:00:00'
@@ -415,7 +414,7 @@ describe Chouette::VehicleJourney, :type => :model do
journey_pattern: journey_pattern,
stop_departure_time: '03:00:00'
)
- journey_late = create(
+ create(
:vehicle_journey,
route: route,
journey_pattern: journey_pattern,
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
new file mode 100644
index 000000000..80873683c
--- /dev/null
+++ b/spec/models/custom_field_spec.rb
@@ -0,0 +1,27 @@
+require 'rails_helper'
+
+RSpec.describe CustomField, type: :model do
+ let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
+
+ context "validates" do
+ it { should validate_uniqueness_of(:name).scoped_to(:resource_type) }
+ end
+
+ context "field access" do
+ let( :custom_field ){ build_stubbed :custom_field }
+
+ it "option's values can be accessed by a key" do
+ expect( custom_field.options['capacity'] ).to eq("0")
+ end
+ end
+
+
+ context "custom fields for a resource" do
+ let!( :fields ){ (1..2).map{ create :custom_field } }
+ it { expect(vj.custom_fields).to eq(fields) }
+ end
+
+ context "custom field_values for a resource" do
+ it { expect(vj.custom_field_value("energy")).to eq(99) }
+ end
+end
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index 45881333f..6d699f759 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -125,19 +125,39 @@ describe Referential, :type => :model do
end
end
- context "used in a ReferentialSuite" do
- before do
- ref.referential_suite_id = 42
+ context "to be referential_read_only or not to be referential_read_only" do
+ let( :referential ){ build_stubbed( :referential ) }
+
+ context "in the beginning" do
+ it{ expect( referential ).not_to be_referential_read_only }
+ end
+
+ context "after archivation" do
+ before{ referential.archived_at = 1.day.ago }
+ it{ expect( referential ).to be_referential_read_only }
end
- it "return true to in_referential_suite?" do
- expect(ref.in_referential_suite?).to be(true)
+ context "used in a ReferentialSuite" do
+ before { referential.referential_suite_id = 42 }
+
+ it{ expect( referential ).to be_referential_read_only }
+
+ it "return true to in_referential_suite?" do
+ expect(referential).to be_in_referential_suite
+ end
+
+ it "don't use detect_overlapped_referentials in validation" do
+ expect(referential).to_not receive(:detect_overlapped_referentials)
+ expect(referential).to be_valid
+ end
end
- it "don't use detect_overlapped_referentials in validation" do
- expect(ref).to_not receive(:detect_overlapped_referentials)
- ref.valid?
+ context "archived and finalised" do
+ before do
+ referential.archived_at = 1.month.ago
+ referential.referential_suite_id = 53
+ end
+ it{ expect( referential ).to be_referential_read_only }
end
end
-
end
diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb
index caff00ae4..2f1fe39da 100644
--- a/spec/models/workbench_spec.rb
+++ b/spec/models/workbench_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe Workbench, :type => :model do
it { should belong_to(:organisation) }
it { should belong_to(:line_referential) }
it { should belong_to(:stop_area_referential) }
+ it { should belong_to(:workgroup) }
it { should belong_to(:output).class_name('ReferentialSuite') }
it { should have_many(:lines).through(:line_referential) }
diff --git a/spec/models/workgroup_spec.rb b/spec/models/workgroup_spec.rb
new file mode 100644
index 000000000..ac8d3fc98
--- /dev/null
+++ b/spec/models/workgroup_spec.rb
@@ -0,0 +1,30 @@
+require 'rails_helper'
+
+RSpec.describe Workgroup, type: :model do
+ context "associations" do
+ let( :workgroup ){ build_stubbed :workgroup, line_referential_id: 53, stop_area_referential_id: 42 }
+
+ it{ should have_many(:workbenches) }
+ it{ should validate_uniqueness_of(:name) }
+
+ it 'is not valid without a stop_area_referential' do
+ workgroup.stop_area_referential_id = nil
+ expect( workgroup ).not_to be_valid
+ end
+ it 'is not valid without a line_referential' do
+ workgroup.line_referential_id = nil
+ expect( workgroup ).not_to be_valid
+ end
+ it 'is valid with both assoications' do
+ expect( workgroup ).to be_valid
+ end
+ end
+
+ context "find organisations" do
+ let( :workgroup ){ create :workgroup }
+ let!( :workbench1 ){ create :workbench, workgroup: workgroup }
+ let!( :workbench2 ){ create :workbench, workgroup: workgroup }
+
+ it{ expect( Set.new(workgroup.organisations) ).to eq(Set.new([ workbench1.organisation, workbench2.organisation ])) }
+ end
+end
diff --git a/spec/policies/access_link_policy_spec.rb b/spec/policies/access_link_policy_spec.rb
index 6194ae55c..9ba3ffa45 100644
--- a/spec/policies/access_link_policy_spec.rb
+++ b/spec/policies/access_link_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe AccessLinkPolicy, type: :policy do
let( :record ){ build_stubbed :access_link }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "access_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "access_links.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "access_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "access_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "access_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/access_point_policy_spec.rb b/spec/policies/access_point_policy_spec.rb
index b6bc46eb4..ec7bf1486 100644
--- a/spec/policies/access_point_policy_spec.rb
+++ b/spec/policies/access_point_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe AccessPointPolicy, type: :policy do
let( :record ){ build_stubbed :access_point }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "access_points.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "access_points.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "access_points.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "access_points.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "access_points.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/company_policy_spec.rb b/spec/policies/company_policy_spec.rb
index e018902ca..16225c441 100644
--- a/spec/policies/company_policy_spec.rb
+++ b/spec/policies/company_policy_spec.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
RSpec.describe CompanyPolicy, type: :policy do
let( :record ){ build_stubbed :company }
@@ -11,10 +10,10 @@ RSpec.describe CompanyPolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
diff --git a/spec/policies/connection_link_policy_spec.rb b/spec/policies/connection_link_policy_spec.rb
index 23e40abe3..6fc9f95df 100644
--- a/spec/policies/connection_link_policy_spec.rb
+++ b/spec/policies/connection_link_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe ConnectionLinkPolicy, type: :policy do
let( :record ){ build_stubbed :connection_link }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/group_of_line_policy_spec.rb b/spec/policies/group_of_line_policy_spec.rb
index 29fbb1bfb..0aeab97bd 100644
--- a/spec/policies/group_of_line_policy_spec.rb
+++ b/spec/policies/group_of_line_policy_spec.rb
@@ -10,10 +10,10 @@ RSpec.describe GroupOfLinePolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
@@ -24,19 +24,19 @@ RSpec.describe GroupOfLinePolicy, type: :policy do
context 'Destructive actions →' do
permissions :create? do
- it_behaves_like 'always forbidden', 'group_of_lines.create', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'always forbidden', 'group_of_lines.destroy', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'always forbidden', 'group_of_lines.update', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'always forbidden', 'group_of_lines.create', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'always forbidden', 'group_of_lines.update', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.update', archived_and_finalised: true
end
end
end
diff --git a/spec/policies/journey_pattern_policy_spec.rb b/spec/policies/journey_pattern_policy_spec.rb
index 39f849277..b5e72d813 100644
--- a/spec/policies/journey_pattern_policy_spec.rb
+++ b/spec/policies/journey_pattern_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe JourneyPatternPolicy, type: :policy do
let( :record ){ build_stubbed :journey_pattern }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/line_policy_spec.rb b/spec/policies/line_policy_spec.rb
index 452606bcf..555008abf 100644
--- a/spec/policies/line_policy_spec.rb
+++ b/spec/policies/line_policy_spec.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
RSpec.describe LinePolicy, type: :policy do
let( :record ){ build_stubbed :line }
@@ -11,10 +10,10 @@ RSpec.describe LinePolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
@@ -47,14 +46,14 @@ RSpec.describe LinePolicy, type: :policy do
# ---------------------------
permissions :create_footnote? do
- it_behaves_like 'permitted policy and same organisation', 'footnotes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'footnotes.create', archived_and_finalised: true
end
permissions :destroy_footnote? do
- it_behaves_like 'permitted policy and same organisation', 'footnotes.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'footnotes.destroy', archived_and_finalised: true
end
permissions :update_footnote? do
- it_behaves_like 'permitted policy and same organisation', 'footnotes.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'footnotes.update', archived_and_finalised: true
end
end
diff --git a/spec/policies/network_policy_spec.rb b/spec/policies/network_policy_spec.rb
index c09546c22..6dc3f0d46 100644
--- a/spec/policies/network_policy_spec.rb
+++ b/spec/policies/network_policy_spec.rb
@@ -10,10 +10,10 @@ RSpec.describe Chouette::NetworkPolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
@@ -24,19 +24,19 @@ RSpec.describe Chouette::NetworkPolicy, type: :policy do
context 'Destructive actions →' do
permissions :create? do
- it_behaves_like 'always forbidden', 'networks.create', archived: true
+ it_behaves_like 'always forbidden', 'networks.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'always forbidden', 'networks.destroy', archived: true
+ it_behaves_like 'always forbidden', 'networks.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'always forbidden', 'networks.update', archived: true
+ it_behaves_like 'always forbidden', 'networks.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'always forbidden', 'networks.create', archived: true
+ it_behaves_like 'always forbidden', 'networks.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'always forbidden', 'networks.update', archived: true
+ it_behaves_like 'always forbidden', 'networks.update', archived_and_finalised: true
end
end
end
diff --git a/spec/policies/purchase_window_policy_spec.rb b/spec/policies/purchase_window_policy_spec.rb
index f078bf288..184152cec 100644
--- a/spec/policies/purchase_window_policy_spec.rb
+++ b/spec/policies/purchase_window_policy_spec.rb
@@ -4,12 +4,12 @@ RSpec.describe PurchaseWindowPolicy, type: :policy do
before { stub_policy_scope(record) }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "purchase_windows.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "purchase_windows.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "purchase_windows.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "purchase_windows.destroy", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "purchase_windows.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "purchase_windows.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb
index d00415fc6..8540d3ce9 100644
--- a/spec/policies/referential_policy_spec.rb
+++ b/spec/policies/referential_policy_spec.rb
@@ -32,13 +32,13 @@ RSpec.describe ReferentialPolicy, type: :policy do
# ---------------------------------------
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'referentials.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'referentials.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true
end
#
@@ -46,7 +46,7 @@ RSpec.describe ReferentialPolicy, type: :policy do
# ------------------
permissions :clone? do
- it_behaves_like 'permitted policy', 'referentials.create', archived: true
+ it_behaves_like 'permitted policy', 'referentials.create', archived_and_finalised: true
end
permissions :archive? do
diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb
index df2e41a89..5dc8be76f 100644
--- a/spec/policies/route_policy_spec.rb
+++ b/spec/policies/route_policy_spec.rb
@@ -3,26 +3,26 @@ RSpec.describe Chouette::RoutePolicy, type: :policy do
let( :record ){ build_stubbed :route }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived_and_finalised: true
end
permissions :duplicate? do
- it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'routes.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'routes.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'routes.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.update', archived_and_finalised: true
end
end
diff --git a/spec/policies/routing_constraint_zone_policy_spec.rb b/spec/policies/routing_constraint_zone_policy_spec.rb
index 2ef15fa95..d619649d3 100644
--- a/spec/policies/routing_constraint_zone_policy_spec.rb
+++ b/spec/policies/routing_constraint_zone_policy_spec.rb
@@ -4,22 +4,22 @@ RSpec.describe RoutingConstraintZonePolicy, type: :policy do
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived_and_finalised: true
end
end
diff --git a/spec/policies/stop_area_policy_spec.rb b/spec/policies/stop_area_policy_spec.rb
index 90835d1d8..8144c16e2 100644
--- a/spec/policies/stop_area_policy_spec.rb
+++ b/spec/policies/stop_area_policy_spec.rb
@@ -11,10 +11,10 @@ RSpec.describe StopAreaPolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
diff --git a/spec/policies/time_table_policy_spec.rb b/spec/policies/time_table_policy_spec.rb
index dad3c13bc..5a2abc61d 100644
--- a/spec/policies/time_table_policy_spec.rb
+++ b/spec/policies/time_table_policy_spec.rb
@@ -3,22 +3,22 @@ RSpec.describe TimeTablePolicy, type: :policy do
let( :record ){ build_stubbed :time_table }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived_and_finalised: true
end
end
diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb
index a3489d9db..d8d12d735 100644
--- a/spec/support/pundit/policies.rb
+++ b/spec/support/pundit/policies.rb
@@ -12,11 +12,14 @@ module Support
UserContext.new(user, referential: referential)
end
+ def finalise_referential
+ referential.referential_suite_id = random_int
+ end
+
def remove_permissions(*permissions, from_user:, save: false)
from_user.permissions -= permissions.flatten
from_user.save! if save
end
-
end
module PoliciesMacros
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index 49f915626..13f537c6d 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -1,6 +1,6 @@
RSpec.shared_examples 'always allowed' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false |
context 'same organisation →' do
before do
user.organisation_id = referential.organisation_id
@@ -8,11 +8,16 @@ RSpec.shared_examples 'always allowed' do
it "allows a user with the same organisation" do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'does not remove permission for archived referentials' do
referential.archived_at = 42.seconds.ago
expect_it.to permit(user_context, record)
end
+
+ it 'does not remove permission for finalised referentials' do
+ finalise_referential
+ expect_it.to permit(user_context, record)
+ end
end
end
@@ -23,27 +28,33 @@ RSpec.shared_examples 'always allowed' do
it "allows a user with a different organisation" do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'does not remove permission for archived referentials' do
referential.archived_at = 42.seconds.ago
expect_it.to permit(user_context, record)
end
+ it 'does not remove permission for finalised referentials' do
+ finalise_referential
+ expect_it.to permit(user_context, record)
+ end
end
end
end
RSpec.shared_examples 'always forbidden' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false|
context 'same organisation →' do
before do
user.organisation_id = referential.organisation_id
end
+
it "allows a user with the same organisation" do
expect_it.not_to permit(user_context, record)
end
- if archived
+
+ if archived_and_finalised
it 'still no permission for archived referentials' do
- referential.archived_at = 42.seconds.ago
+ finalise_referential
expect_it.not_to permit(user_context, record)
end
end
@@ -56,17 +67,22 @@ RSpec.shared_examples 'always forbidden' do
it "denies a user with a different organisation" do
expect_it.not_to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'still no permission for archived referentials' do
referential.archived_at = 42.seconds.ago
expect_it.not_to permit(user_context, record)
end
+
+ it 'still no permission for finalised referentials' do
+ finalise_referential
+ expect_it.not_to permit(user_context, record)
+ end
end
end
end
RSpec.shared_examples 'permitted policy and same organisation' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false |
context 'permission absent → ' do
it "denies a user with a different organisation" do
@@ -92,18 +108,24 @@ RSpec.shared_examples 'permitted policy and same organisation' do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
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
+
+ it 'removes the permission for finalised referentials' do
+ user.organisation_id = referential.organisation_id
+ finalise_referential
+ expect_it.not_to permit(user_context, record)
+ end
end
end
end
RSpec.shared_examples 'permitted policy' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false|
context 'permission absent → ' do
it "denies user" do
@@ -120,12 +142,17 @@ RSpec.shared_examples 'permitted policy' do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
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
+ it 'removes the permission for finalised referentials' do
+ user.organisation_id = referential.organisation_id
+ finalise_referential
+ expect_it.not_to permit(user_context, record)
+ end
end
end
end
@@ -148,4 +175,4 @@ RSpec.shared_examples 'permitted policy outside referential' do
expect_it.to permit(user_context, record)
end
end
-end \ No newline at end of file
+end