aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/stop_area_controller_spec.rb9
-rw-r--r--spec/controllers/autocomplete_stop_areas_controller_spec.rb14
-rw-r--r--spec/controllers/statuses_controller_spec.rb50
-rw-r--r--spec/controllers/vehicle_journeys_controller_spec.rb24
-rw-r--r--spec/factories/calendars.rb1
-rw-r--r--spec/factories/chouette_stop_areas.rb8
-rw-r--r--spec/factories/compliance_controls/vehicle_journey_control_factories.rb2
-rw-r--r--spec/features/access_points_spec.rb2
-rw-r--r--spec/features/calendars_permissions_spec.rb7
-rw-r--r--spec/features/referential_stop_areas_spec.rb2
-rw-r--r--spec/javascript/preprocessor.js15
-rw-r--r--spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js7
-rw-r--r--spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap20
-rw-r--r--spec/mailers/calendar_mailer_spec.rb2
-rw-r--r--spec/models/calendar_spec.rb2
-rw-r--r--spec/models/compliance_check_spec.rb32
-rw-r--r--spec/models/import_spec.rb52
-rw-r--r--spec/services/parent_notifier_spec.rb (renamed from spec/services/parent_import_notifier_spec.rb)16
-rw-r--r--spec/support/integration_spec_helper.rb15
-rw-r--r--spec/support/pundit/pundit_view_policy.rb13
-rw-r--r--spec/support/referential.rb4
-rw-r--r--spec/support/snapshot_support.rb60
-rw-r--r--spec/views/companies/__snapshots__/companies/index.snap4
-rw-r--r--spec/views/companies/__snapshots__/companies/index_create.snap4
-rw-r--r--spec/views/companies/__snapshots__/companies/index_destroy.snap4
-rw-r--r--spec/views/companies/__snapshots__/companies/index_update.snap4
-rw-r--r--spec/views/companies/__snapshots__/companies/show.snap4
-rw-r--r--spec/views/companies/__snapshots__/companies/show_create.snap4
-rw-r--r--spec/views/companies/__snapshots__/companies/show_destroy.snap7
-rw-r--r--spec/views/companies/__snapshots__/companies/show_update.snap7
-rw-r--r--spec/views/companies/index.html.erb_spec.rb29
-rw-r--r--spec/views/companies/show.html.erb_spec.rb29
-rw-r--r--spec/views/lines/__snapshots__/lines/index.snap4
-rw-r--r--spec/views/lines/__snapshots__/lines/index_create.snap4
-rw-r--r--spec/views/lines/__snapshots__/lines/index_destroy.snap4
-rw-r--r--spec/views/lines/__snapshots__/lines/index_update.snap4
-rw-r--r--spec/views/lines/__snapshots__/lines/show.snap9
-rw-r--r--spec/views/lines/__snapshots__/lines/show_create.snap9
-rw-r--r--spec/views/lines/__snapshots__/lines/show_destroy.snap9
-rw-r--r--spec/views/lines/__snapshots__/lines/show_update.snap9
-rw-r--r--spec/views/lines/index.html.slim_spec.rb84
-rw-r--r--spec/views/lines/show.html.erb_spec.rb26
-rw-r--r--spec/views/networks/__snapshots__/networks/index.snap4
-rw-r--r--spec/views/networks/__snapshots__/networks/index_create.snap4
-rw-r--r--spec/views/networks/__snapshots__/networks/index_destroy.snap4
-rw-r--r--spec/views/networks/__snapshots__/networks/index_update.snap4
-rw-r--r--spec/views/networks/__snapshots__/networks/show.snap4
-rw-r--r--spec/views/networks/__snapshots__/networks/show_create.snap4
-rw-r--r--spec/views/networks/__snapshots__/networks/show_destroy.snap7
-rw-r--r--spec/views/networks/__snapshots__/networks/show_update.snap7
-rw-r--r--spec/views/networks/index.html.erb_spec.rb28
-rw-r--r--spec/views/networks/show.html.erb_spec.rb30
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_create.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_destroy.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap12
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_readonly.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap9
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap12
-rw-r--r--spec/views/referentials/__snapshots__/referentials/show_update.snap12
-rw-r--r--spec/views/referentials/show.html.erb_spec.rb54
69 files changed, 822 insertions, 96 deletions
diff --git a/spec/controllers/api/v1/stop_area_controller_spec.rb b/spec/controllers/api/v1/stop_area_controller_spec.rb
index eb0c87661..1ad71a95a 100644
--- a/spec/controllers/api/v1/stop_area_controller_spec.rb
+++ b/spec/controllers/api/v1/stop_area_controller_spec.rb
@@ -18,16 +18,15 @@ describe Api::V1::StopAreasController, :type => :controller do
end
end
describe "GET #index, :q => { :name_cont => 'aa'}" do
- let!(:sa1) { create(:stop_area, :name => "aaa") }
- let!(:sa2) { create(:stop_area, :name => "aab") }
- let!(:sa3) { create(:stop_area, :name => "abb") }
+ let!(:sa1) { create(:stop_area, :name => "aaa", stop_area_referential: referential.stop_area_referential) }
+ let!(:sa2) { create(:stop_area, :name => "aab", stop_area_referential: referential.stop_area_referential) }
+ let!(:sa3) { create(:stop_area, :name => "abb", stop_area_referential: referential.stop_area_referential) }
before :each do
config_formatted_request_with_authorization( "application/json")
- get :index, :q => { :name_cont => "aa"}
+ get :index, :q => { :name_cont => "aa"}
end
it "should assign expected stop_areas" do
expect(assigns[:stop_areas].map(&:name).sort).to eq([ sa1.name, sa2.name])
end
end
end
-
diff --git a/spec/controllers/autocomplete_stop_areas_controller_spec.rb b/spec/controllers/autocomplete_stop_areas_controller_spec.rb
index 2af471361..e0d1cd714 100644
--- a/spec/controllers/autocomplete_stop_areas_controller_spec.rb
+++ b/spec/controllers/autocomplete_stop_areas_controller_spec.rb
@@ -4,9 +4,11 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do
login_user
let(:referential) { Referential.first }
- let!(:stop_area) { create :stop_area, name: 'écolà militaire' }
- let!(:zdep_stop_area) { create :stop_area, area_type: "zdep" }
- let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda" }
+ let(:other_referential) { create :referential }
+ let!(:stop_area) { create :stop_area, name: 'écolà militaire', referential: referential }
+ let!(:other_referential_stop_area) { create :stop_area, name: 'écolà militaire', referential: other_referential }
+ let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", referential: referential }
+ let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", referential: referential }
describe 'GET #index' do
it 'should be successful' do
@@ -14,6 +16,12 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do
expect(response).to be_success
end
+ it "should filter stop areas based on referential" do
+ get :index, referential_id: referential.id
+ expect(assigns(:stop_areas)).to include(stop_area)
+ expect(assigns(:stop_areas)).to_not include(other_referential_stop_area)
+ end
+
context 'search by name' do
it 'should be successful' do
get :index, referential_id: referential.id, q: 'écolà', :format => :json
diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb
new file mode 100644
index 000000000..8a6db8e28
--- /dev/null
+++ b/spec/controllers/statuses_controller_spec.rb
@@ -0,0 +1,50 @@
+RSpec.describe StatusesController, :type => :controller do
+
+ describe "GET index" do
+ login_user
+ render_views
+
+
+ let(:request){ get :index}
+ let(:parsed_response){ JSON.parse response.body }
+ it "should be ok" do
+ request
+ expect(response).to have_http_status 200
+ expect(parsed_response["status"]).to eq "ok"
+ end
+ context "without blocked object" do
+ before do
+ create :referential
+ create :import
+ create :compliance_check_set
+ request
+ end
+
+ it "should be ok" do
+ expect(response).to have_http_status 200
+ expect(parsed_response["status"]).to eq "ok"
+ expect(parsed_response["referentials_blocked"]).to eq 0
+ expect(parsed_response["imports_blocked"]).to eq 0
+ expect(parsed_response["imports_blocked"]).to eq 0
+ end
+ end
+
+ context "with a blocked object" do
+ before do
+ create :referential, created_at: 5.hours.ago, ready: false
+ create :import
+ create :compliance_check_set
+ request
+ end
+
+ it "should be ko" do
+ expect(Referential.blocked.count).to eq 1
+ expect(response).to have_http_status 200
+ expect(parsed_response["status"]).to eq "ko"
+ expect(parsed_response["referentials_blocked"]).to eq 1
+ expect(parsed_response["imports_blocked"]).to eq 0
+ expect(parsed_response["imports_blocked"]).to eq 0
+ end
+ end
+ end
+end
diff --git a/spec/controllers/vehicle_journeys_controller_spec.rb b/spec/controllers/vehicle_journeys_controller_spec.rb
index 416450c21..300684532 100644
--- a/spec/controllers/vehicle_journeys_controller_spec.rb
+++ b/spec/controllers/vehicle_journeys_controller_spec.rb
@@ -26,4 +26,28 @@ RSpec.describe VehicleJourneysController, :type => :controller do
end
end
+ describe "GET index" do
+ login_user
+ render_views
+
+ context "in JSON" do
+ let(:vehicle_journey){ create :vehicle_journey }
+ let(:route){ vehicle_journey.route }
+ let(:line){ route.line }
+ let!(:request){ get :index, referential_id: referential.id, line_id: line.id, route_id: route.id, format: :json}
+ let(:parsed_response){ JSON.parse response.body }
+ it "should have all the attributes" do
+ expect(response).to have_http_status 200
+ vehicle_journey = parsed_response["vehicle_journeys"].first
+ vehicle_journey_at_stops_matrix = vehicle_journey["vehicle_journey_at_stops"]
+ vehicle_journey_at_stops_matrix.each do |received_vjas|
+ expect(received_vjas).to have_key("id")
+ vjas = Chouette::VehicleJourneyAtStop.find received_vjas["id"]
+ [:connecting_service_id, :boarding_alighting_possibility].each do |att|
+ expect(received_vjas[att]).to eq vjas.send(att)
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/factories/calendars.rb b/spec/factories/calendars.rb
index 5f3188bee..d9fd242d1 100644
--- a/spec/factories/calendars.rb
+++ b/spec/factories/calendars.rb
@@ -6,6 +6,7 @@ FactoryGirl.define do
sequence(:dates) { |n| [ Date.yesterday - n, Date.yesterday - 2*n ] }
shared false
organisation
+ workgroup
end
sequence :date_range do |n|
diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb
index 9b4764781..dab135ca6 100644
--- a/spec/factories/chouette_stop_areas.rb
+++ b/spec/factories/chouette_stop_areas.rb
@@ -10,6 +10,14 @@ FactoryGirl.define do
association :stop_area_referential
+ transient do
+ referential nil
+ end
+
+ before(:create) do |stop_area, evaluator|
+ stop_area.stop_area_referential = evaluator.referential.stop_area_referential if evaluator.referential
+ end
+
trait :deactivated do
deleted_at { 1.hour.ago }
end
diff --git a/spec/factories/compliance_controls/vehicle_journey_control_factories.rb b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb
index e8f68cbdf..86a335aba 100644
--- a/spec/factories/compliance_controls/vehicle_journey_control_factories.rb
+++ b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb
@@ -1,10 +1,12 @@
FactoryGirl.define do
factory :vehicle_journey_control_wating_time, class: 'VehicleJourneyControl::WaitingTime' do
+ maximum 10
association :compliance_control_set
end
factory :vehicle_journey_control_delta, class: 'VehicleJourneyControl::Delta' do
+ maximum 10
association :compliance_control_set
end
diff --git a/spec/features/access_points_spec.rb b/spec/features/access_points_spec.rb
index c16039d67..890906de7 100644
--- a/spec/features/access_points_spec.rb
+++ b/spec/features/access_points_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
describe "Access points", :type => :feature do
login_user
- let!(:stop_area) { create(:stop_area) }
+ let!(:stop_area) { create(:stop_area, stop_area_referential: referential.stop_area_referential) }
let!(:access_points) { Array.new(2) { create(:access_point, :stop_area => stop_area) } }
subject { access_points.first }
diff --git a/spec/features/calendars_permissions_spec.rb b/spec/features/calendars_permissions_spec.rb
index 9b47ab2bb..4857592d5 100644
--- a/spec/features/calendars_permissions_spec.rb
+++ b/spec/features/calendars_permissions_spec.rb
@@ -2,6 +2,7 @@ RSpec.describe 'Calendars', type: :feature do
login_user
let(:calendar) { create :calendar, organisation_id: 1 }
+ let(:workgroup) { calendar.workgroup }
describe 'permissions' do
before do
@@ -13,7 +14,7 @@ RSpec.describe 'Calendars', type: :feature do
end
context 'on show view' do
- let( :path ){ calendar_path(calendar) }
+ let( :path ){ workgroup_calendar_path(workgroup, calendar) }
context 'if present → ' do
let( :permission ){ true }
@@ -33,7 +34,7 @@ RSpec.describe 'Calendars', type: :feature do
end
context 'on edit view' do
- let( :path ){ edit_calendar_path(calendar) }
+ let( :path ){ edit_workgroup_calendar_path(workgroup, calendar) }
context 'if present → ' do
let( :permission ){ true }
@@ -51,7 +52,7 @@ RSpec.describe 'Calendars', type: :feature do
end
context 'on index view' do
- let( :path ){ calendars_path }
+ let( :path ){ workgroup_calendars_path(workgroup) }
context 'if present → ' do
let( :permission ){ true }
diff --git a/spec/features/referential_stop_areas_spec.rb b/spec/features/referential_stop_areas_spec.rb
index 0dc7951a7..5e70857e7 100644
--- a/spec/features/referential_stop_areas_spec.rb
+++ b/spec/features/referential_stop_areas_spec.rb
@@ -5,7 +5,7 @@ describe 'ReferentialStopAreas', type: :feature do
login_user
let(:referential) { Referential.first }
- let(:stop_area_referential) { create :stop_area_referential }
+ let(:stop_area_referential) { referential.stop_area_referential }
let!(:stop_areas) { Array.new(2) { create :stop_area, stop_area_referential: stop_area_referential } }
describe 'index' do
diff --git a/spec/javascript/preprocessor.js b/spec/javascript/preprocessor.js
new file mode 100644
index 000000000..a2de8e4be
--- /dev/null
+++ b/spec/javascript/preprocessor.js
@@ -0,0 +1,15 @@
+'use strict';
+
+var coffee = require('coffeescript');
+
+module.exports = {
+ process: function(src, filename) {
+ if (coffee.helpers.isCoffee(filename)) {
+ return coffee.compile(src, {
+ 'bare': false,
+ 'inlineMap': true
+ })
+ }
+ return src;
+ }
+};
diff --git a/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
index 87151c64b..2a84cb9ca 100644
--- a/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
+++ b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
@@ -1,6 +1,13 @@
import React, { Component } from 'react'
import VehicleJourneys from '../../../../app/javascript/vehicle_journeys/components/VehicleJourneys'
import renderer from 'react-test-renderer'
+import fs from 'fs'
+
+import I18n from '../../../../public/javascripts/i18n'
+import decorateI18n from '../../../../app/assets/javascripts/i18n/extended.coffee'
+window.I18n = decorateI18n(I18n)
+I18n.locale = "fr"
+eval(fs.readFileSync('./public/javascripts/translations.js')+'')
describe('stopPointHeader', () => {
set('features', () => {
diff --git a/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
index 703f727d7..cdd34cbbd 100644
--- a/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
+++ b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
@@ -19,19 +19,19 @@ exports[`stopPointHeader should display the city name 1`] = `
<div
className="strong mb-xs"
>
- ID course
+ ID Course
</div>
<div>
- Nom course
+ Nom Course
</div>
<div>
- ID mission
+ ID Mission
</div>
<div>
- Transporteur
+ transporteur
</div>
<div>
- Calendriers
+ calendrier
</div>
</div>
<div
@@ -109,19 +109,19 @@ exports[`stopPointHeader with the "long_distance_routes" feature should display
<div
className="strong mb-xs"
>
- ID course
+ ID Course
</div>
<div>
- Nom course
+ Nom Course
</div>
<div>
- ID mission
+ ID Mission
</div>
<div>
- Transporteur
+ transporteur
</div>
<div>
- Calendriers
+ calendrier
</div>
</div>
<div
diff --git a/spec/mailers/calendar_mailer_spec.rb b/spec/mailers/calendar_mailer_spec.rb
index 9a2076f64..00d73a58b 100644
--- a/spec/mailers/calendar_mailer_spec.rb
+++ b/spec/mailers/calendar_mailer_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe CalendarMailer, type: :mailer do
end
it 'should have correct body' do
- key = I18n.t("mailers.calendar_mailer.#{type}.body", cal_name: calendar.name, cal_index_url: calendars_url)
+ key = I18n.t("mailers.calendar_mailer.#{type}.body", cal_name: calendar.name, cal_index_url: workgroup_calendars_url(calendar.workgroup))
expect(email).to have_body_text /#{key}/
end
end
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 3cffd0f8a..a5c0a7471 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe Calendar, :type => :model do
end
it 'validates that dates and date_ranges do not overlap but allow for days not in the list' do
- expect(build(:calendar, dates: [Date.today.beginning_of_week], date_ranges: [Date.today.beginning_of_week..Date.today], int_day_types: Calendar::THURSDAY)).to be_valid
+ expect(build(:calendar, dates: [Date.today.beginning_of_week - 1.week], date_ranges: [(Date.today.beginning_of_week - 1.week)..Date.today], int_day_types: Calendar::THURSDAY)).to be_valid
end
it 'validates that there are no duplicates in dates' do
diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb
index f83d78c29..ffa59245c 100644
--- a/spec/models/compliance_check_spec.rb
+++ b/spec/models/compliance_check_spec.rb
@@ -15,4 +15,36 @@ RSpec.describe ComplianceCheck, type: :model do
it { should validate_presence_of :name }
it { should validate_presence_of :code }
it { should validate_presence_of :origin_code }
+
+ describe ".abort_old" do
+ it "changes check sets older than 4 hours to aborted" do
+ Timecop.freeze(Time.now) do
+ old_check_set = create(
+ :compliance_check_set,
+ status: 'pending',
+ created_at: 4.hours.ago - 1.minute
+ )
+ current_check_set = create(:compliance_check_set, status: 'pending')
+
+ ComplianceCheckSet.abort_old
+
+ expect(current_check_set.reload.status).to eq('pending')
+ expect(old_check_set.reload.status).to eq('aborted')
+ end
+ end
+
+ it "doesn't work on check sets with a `finished_status`" do
+ Timecop.freeze(Time.now) do
+ check_set = create(
+ :compliance_check_set,
+ status: 'successful',
+ created_at: 4.hours.ago - 1.minute
+ )
+
+ ComplianceCheckSet.abort_old
+
+ expect(check_set.reload.status).to eq('successful')
+ end
+ end
+ end
end
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index ffb2360c2..8b85f151b 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -29,6 +29,58 @@ RSpec.describe Import, type: :model do
)
end
+ describe ".abort_old" do
+ it "changes imports older than 4 hours to aborted" do
+ Timecop.freeze(Time.now) do
+ old_import = create(
+ :workbench_import,
+ status: 'pending',
+ created_at: 4.hours.ago - 1.minute
+ )
+ current_import = create(:workbench_import, status: 'pending')
+
+ Import.abort_old
+
+ expect(current_import.reload.status).to eq('pending')
+ expect(old_import.reload.status).to eq('aborted')
+ end
+ end
+
+ it "doesn't work on imports with a `finished_status`" do
+ Timecop.freeze(Time.now) do
+ import = create(
+ :workbench_import,
+ status: 'successful',
+ created_at: 4.hours.ago - 1.minute
+ )
+
+ Import.abort_old
+
+ expect(import.reload.status).to eq('successful')
+ end
+ end
+
+ it "only works on the caller type" do
+ Timecop.freeze(Time.now) do
+ workbench_import = create(
+ :workbench_import,
+ status: 'pending',
+ created_at: 4.hours.ago - 1.minute
+ )
+ netex_import = create(
+ :netex_import,
+ status: 'pending',
+ created_at: 4.hours.ago - 1.minute
+ )
+
+ NetexImport.abort_old
+
+ expect(workbench_import.reload.status).to eq('pending')
+ expect(netex_import.reload.status).to eq('aborted')
+ end
+ end
+ end
+
describe "#destroy" do
it "must destroy all child imports" do
netex_import = create(:netex_import)
diff --git a/spec/services/parent_import_notifier_spec.rb b/spec/services/parent_notifier_spec.rb
index 3ab505f88..ecf508fcd 100644
--- a/spec/services/parent_import_notifier_spec.rb
+++ b/spec/services/parent_notifier_spec.rb
@@ -1,4 +1,4 @@
-RSpec.describe ParentImportNotifier do
+RSpec.describe ParentNotifier do
let(:workbench_import) { create(:workbench_import) }
describe ".notify_when_finished" do
@@ -20,7 +20,7 @@ RSpec.describe ParentImportNotifier do
expect(netex_import).to receive(:notify_parent)
end
- ParentImportNotifier.notify_when_finished(netex_imports)
+ ParentNotifier.new(Import).notify_when_finished(netex_imports)
end
it "doesn't call #notify_parent if its `notified_parent_at` is set" do
@@ -33,11 +33,11 @@ RSpec.describe ParentImportNotifier do
expect(netex_import).not_to receive(:notify_parent)
- ParentImportNotifier.notify_when_finished
+ ParentNotifier.new(Import).notify_when_finished
end
end
- describe ".imports_pending_notification" do
+ describe ".objects_pending_notification" do
it "includes imports with a parent and `notified_parent_at` unset" do
netex_import = create(
:netex_import,
@@ -47,7 +47,7 @@ RSpec.describe ParentImportNotifier do
)
expect(
- ParentImportNotifier.imports_pending_notification
+ ParentNotifier.new(Import).objects_pending_notification
).to eq([netex_import])
end
@@ -55,7 +55,7 @@ RSpec.describe ParentImportNotifier do
create(:import, parent: nil)
expect(
- ParentImportNotifier.imports_pending_notification
+ ParentNotifier.new(Import).objects_pending_notification
).to be_empty
end
@@ -70,7 +70,7 @@ RSpec.describe ParentImportNotifier do
end
expect(
- ParentImportNotifier.imports_pending_notification
+ ParentNotifier.new(Import).objects_pending_notification
).to be_empty
end
@@ -83,7 +83,7 @@ RSpec.describe ParentImportNotifier do
)
expect(
- ParentImportNotifier.imports_pending_notification
+ ParentNotifier.new(Import).objects_pending_notification
).to be_empty
end
end
diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb
index 36306559d..7ba7e9f92 100644
--- a/spec/support/integration_spec_helper.rb
+++ b/spec/support/integration_spec_helper.rb
@@ -3,7 +3,11 @@ module IntegrationSpecHelper
def paginate_collection klass, decorator, page=1, context={}
collection = klass.page(page)
if decorator
- collection = ModelDecorator.decorate(collection, with: decorator, context: context)
+ if decorator < AF83::Decorator
+ collection = decorator.decorate(collection, context: context)
+ else
+ collection = ModelDecorator.decorate(collection, with: decorator, context: context)
+ end
end
collection
end
@@ -24,6 +28,13 @@ module IntegrationSpecHelper
context('', &block) if block_given?
end
end
+
+ def with_feature feature, &block
+ context "with feature #{feature}" do
+ let(:features){ [feature] }
+ context('', &block) if block_given?
+ end
+ end
end
def self.included into
@@ -48,7 +59,7 @@ RSpec::Matchers.define :have_link_for_each_item do |collection, name, opts|
end
description { "have #{name} link for each item" }
failure_message do
- "expected view to have #{name} link for each item, failed with selector: \"#{@selector}\""
+ "expected view to have one #{name} link for each item, failed with selector: \"#{@selector}\""
end
end
diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb
index 91be0624c..63970de02 100644
--- a/spec/support/pundit/pundit_view_policy.rb
+++ b/spec/support/pundit/pundit_view_policy.rb
@@ -2,13 +2,18 @@ module Pundit
module PunditViewPolicy
def self.included into
into.let(:permissions){ nil }
- into.let(:organisation){ referential.try(:organisation) }
- into.let(:current_referential){ referential || build_stubbed(:referential) }
- into.let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation }
+ into.let(:current_referential){ referential || build_stubbed(:referential, organisation: organisation) }
+ into.let(:current_user){ create :user, permissions: permissions, organisation: organisation }
into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) }
+ into.let(:current_offer_workbench) { create :workbench, organisation: organisation}
into.before do
allow(view).to receive(:pundit_user) { pundit_user }
-
+ allow(view).to receive(:current_user) { current_user }
+ allow(view).to receive(:current_organisation).and_return(organisation)
+ allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench)
+ allow(view).to receive(:current_workgroup).and_return(current_offer_workbench.workgroup)
+ allow(view).to receive(:has_feature?){ |f| features.include?(f)}
+ allow(view).to receive(:user_signed_in?).and_return true
allow(view).to receive(:policy) do |instance|
::Pundit.policy pundit_user, instance
end
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index 497ff47a8..9acdce73a 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -11,8 +11,8 @@ module ReferentialHelper
def self.included(base)
base.class_eval do
extend ClassMethods
- alias_method :referential, :first_referential
- alias_method :organisation, :first_organisation
+ base.let(:referential){ first_referential }
+ base.let(:organisation){ first_organisation }
end
end
diff --git a/spec/support/snapshot_support.rb b/spec/support/snapshot_support.rb
new file mode 100644
index 000000000..b1ade5288
--- /dev/null
+++ b/spec/support/snapshot_support.rb
@@ -0,0 +1,60 @@
+module SnaphostSpecHelper
+
+ module Methods
+ def set_invariant expr, val=nil
+ val ||= expr
+ chain = expr.split(".")
+ method = chain.pop
+
+ before(:each) do
+ allow(eval(chain.join('.'))).to receive(method){ val }
+ end
+ end
+ end
+
+ def self.included into
+ into.extend Methods
+ end
+end
+
+RSpec.configure do |config|
+ config.include SnaphostSpecHelper, type: :view
+end
+
+
+RSpec::Matchers.define :match_actions_links_snapshot do |name|
+ match do |actual|
+ @content = Capybara::Node::Simple.new(rendered).find('.page_header').native.inner_html
+ expect(@content).to match_snapshot(name)
+ end
+
+ failure_message do |actual|
+ out = ["Snapshots did not match."]
+ snap_path = File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap"
+ temp_path = Pathname.new "#{Rails.root}/tmp/__snapshots__/#{name}.failed.snap"
+ FileUtils.mkdir_p temp_path.dirname
+ tmp = File.new temp_path, "w"
+ tmp.write @content
+ tmp.close()
+ expected = File.read snap_path
+ out << "Expected: #{expected}"
+ out << "Actual: #{@content}"
+ out << "\n\n --- DIFF ---"
+ out << differ.diff_as_string(@content, expected)
+ out << "\n\n --- Previews : ---"
+ out << "Expected: \n" + snapshot_url(snap: snap_path, layout: :actions_links)
+ out << " \nActual: \n" + snapshot_url(snap: tmp.path, layout: :actions_links)
+ out.join("\n")
+ end
+
+ def snapshot_url snap:, layout:
+ "http://localhost:3000/snap/?snap=#{URI.encode(snap.to_s)}&layout=#{URI.encode(layout.to_s)}"
+ end
+
+ def differ
+ RSpec::Support::Differ.new(
+ :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) },
+ :color => RSpec::Matchers.configuration.color?
+ )
+ end
+end
diff --git a/spec/views/companies/__snapshots__/companies/index.snap b/spec/views/companies/__snapshots__/companies/index.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/index.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/index_create.snap b/spec/views/companies/__snapshots__/companies/index_create.snap
new file mode 100644
index 000000000..df36d5f49
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/index_create.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><a class="btn btn-default" href="/line_referentials/99/companies/new">Ajouter un transporteur</a></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/index_destroy.snap b/spec/views/companies/__snapshots__/companies/index_destroy.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/index_destroy.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/index_update.snap b/spec/views/companies/__snapshots__/companies/index_update.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/index_update.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/show.snap b/spec/views/companies/__snapshots__/companies/show.snap
new file mode 100644
index 000000000..8fe847427
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/show.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Transporteur Company Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/show_create.snap b/spec/views/companies/__snapshots__/companies/show_create.snap
new file mode 100644
index 000000000..8fe847427
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/show_create.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Transporteur Company Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/show_destroy.snap b/spec/views/companies/__snapshots__/companies/show_destroy.snap
new file mode 100644
index 000000000..5d574e460
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/show_destroy.snap
@@ -0,0 +1,7 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Transporteur Company Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right"><a data-confirm="Etes vous sûr de supprimer ce transporteur ?" class="btn btn-primary" rel="nofollow" data-method="delete" href="/line_referentials/99/companies/909"><span class="fa fa-trash mr-xs"></span>Supprimer ce transporteur</a></div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/companies/__snapshots__/companies/show_update.snap b/spec/views/companies/__snapshots__/companies/show_update.snap
new file mode 100644
index 000000000..c2fbd3297
--- /dev/null
+++ b/spec/views/companies/__snapshots__/companies/show_update.snap
@@ -0,0 +1,7 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Transporteur Company Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action">
+<div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div>
+<a class="btn btn-default" href="/line_referentials/99/companies/909/edit">Editer ce transporteur</a>
+</div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/companies/index.html.erb_spec.rb b/spec/views/companies/index.html.erb_spec.rb
index 9db689ba6..8ed5f2c21 100644
--- a/spec/views/companies/index.html.erb_spec.rb
+++ b/spec/views/companies/index.html.erb_spec.rb
@@ -3,7 +3,10 @@ require 'spec_helper'
RSpec.describe "/companies/index", :type => :view do
let!(:line_referential) { assign :line_referential, create(:line_referential) }
- let!(:companies) { assign :companies, CompanyDecorator.decorate_collection(Array.new(2) { create(:company, line_referential: line_referential) }.paginate) }
+ let(:context){{referential: line_referential}}
+ let!(:companies) do
+ assign :companies, build_paginated_collection(:company, CompanyDecorator, line_referential: line_referential, context: context)
+ end
let!(:search) { assign :q, Ransack::Search.new(Chouette::Company) }
# Fixme #1795
@@ -22,4 +25,28 @@ RSpec.describe "/companies/index", :type => :view do
# expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_company_path(line_referential)}']")
# end
+ before(:each) do
+ allow(view).to receive(:collection).and_return(companies)
+ allow(view).to receive(:decorated_collection).and_return(companies)
+ allow(view).to receive(:current_referential).and_return(line_referential)
+ controller.request.path_parameters[:line_referential_id] = line_referential.id
+ allow(view).to receive(:params).and_return({action: :index})
+ end
+
+ describe "action links" do
+ set_invariant "line_referential.id", "99"
+
+ before(:each){
+ render template: "companies/index", layout: "layouts/application"
+ }
+
+ it { should match_actions_links_snapshot "companies/index" }
+
+ %w(create update destroy).each do |p|
+ with_permission "companies.#{p}" do
+ it { should match_actions_links_snapshot "companies/index_#{p}" }
+ end
+ end
+ end
+
end
diff --git a/spec/views/companies/show.html.erb_spec.rb b/spec/views/companies/show.html.erb_spec.rb
index aeb93aebb..b127bdf44 100644
--- a/spec/views/companies/show.html.erb_spec.rb
+++ b/spec/views/companies/show.html.erb_spec.rb
@@ -2,11 +2,38 @@ require 'spec_helper'
describe "/companies/show", :type => :view do
- let!(:company) { assign(:company, create(:company)) }
+ let!(:company) { c = create(:company); assign(:company, c.decorate(context: {referential: c.line_referential})) }
let!(:line_referential) { assign :line_referential, company.line_referential }
# it "should display a map with class 'company'" do
# render
# expect(rendered).to have_selector("#map", :class => 'company')
# end
+
+ before(:each) do
+ allow(view).to receive(:current_referential).and_return(line_referential)
+ allow(view).to receive(:resource).and_return(company)
+ controller.request.path_parameters[:line_referential_id] = line_referential.id
+ controller.request.path_parameters[:id] = company.id
+ allow(view).to receive(:params).and_return({action: :show})
+ end
+
+ describe "action links" do
+ set_invariant "line_referential.id", "99"
+ set_invariant "company.object.id", "909"
+ set_invariant "company.object.name", "Company Name"
+ set_invariant "company.object.updated_at", "2018/01/23".to_time
+
+ before(:each){
+ render template: "companies/show", layout: "layouts/application"
+ }
+
+ it { should match_actions_links_snapshot "companies/show" }
+
+ %w(create update destroy).each do |p|
+ with_permission "companies.#{p}" do
+ it { should match_actions_links_snapshot "companies/show_#{p}" }
+ end
+ end
+ end
end
diff --git a/spec/views/lines/__snapshots__/lines/index.snap b/spec/views/lines/__snapshots__/lines/index.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/index.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/index_create.snap b/spec/views/lines/__snapshots__/lines/index_create.snap
new file mode 100644
index 000000000..4e4f54e7f
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/index_create.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><a class="btn btn-default" href="/line_referentials/99/lines/new">Ajouter une ligne</a></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/index_destroy.snap b/spec/views/lines/__snapshots__/lines/index_destroy.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/index_destroy.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/index_update.snap b/spec/views/lines/__snapshots__/lines/index_update.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/index_update.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/show.snap b/spec/views/lines/__snapshots__/lines/show.snap
new file mode 100644
index 000000000..30eb6786e
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/show.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Ligne Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/line_referentials/99/networks/99">Voir le réseau</a><a class="btn btn-primary" href="/line_referentials/99/companies/99">Voir le transporteur principal</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/show_create.snap b/spec/views/lines/__snapshots__/lines/show_create.snap
new file mode 100644
index 000000000..30eb6786e
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/show_create.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Ligne Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/line_referentials/99/networks/99">Voir le réseau</a><a class="btn btn-primary" href="/line_referentials/99/companies/99">Voir le transporteur principal</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/show_destroy.snap b/spec/views/lines/__snapshots__/lines/show_destroy.snap
new file mode 100644
index 000000000..8ed08a90d
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/show_destroy.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Ligne Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/line_referentials/99/networks/99">Voir le réseau</a><a class="btn btn-primary" href="/line_referentials/99/companies/99">Voir le transporteur principal</a><a data-confirm="Etes vous sûr de supprimer cette ligne ?" class="btn btn-primary" rel="nofollow" data-method="delete" href="/line_referentials/99/lines/99"><span class="fa fa-trash mr-xs"></span>Supprimer cette ligne</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/lines/__snapshots__/lines/show_update.snap b/spec/views/lines/__snapshots__/lines/show_update.snap
new file mode 100644
index 000000000..30eb6786e
--- /dev/null
+++ b/spec/views/lines/__snapshots__/lines/show_update.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Ligne Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/line_referentials/99/networks/99">Voir le réseau</a><a class="btn btn-primary" href="/line_referentials/99/companies/99">Voir le transporteur principal</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/lines/index.html.slim_spec.rb b/spec/views/lines/index.html.slim_spec.rb
index fb436c545..20e1783e3 100644
--- a/spec/views/lines/index.html.slim_spec.rb
+++ b/spec/views/lines/index.html.slim_spec.rb
@@ -13,11 +13,12 @@ describe "/lines/index", :type => :view do
let(:lines) do
assign :lines, build_paginated_collection(:line, LineDecorator, line_referential: line_referential, context: context)
end
- let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }
+ let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }
before :each do
deactivated_line
allow(view).to receive(:collection).and_return(lines)
+ allow(view).to receive(:decorated_collection).and_return(lines)
allow(view).to receive(:current_referential).and_return(line_referential)
allow(view).to receive(:params).and_return({action: :index})
controller.request.path_parameters[:line_referential_id] = line_referential.id
@@ -25,49 +26,68 @@ describe "/lines/index", :type => :view do
render
end
- common_items = ->{
- it { should have_link_for_each_item(lines, "show", -> (line){ view.line_referential_line_path(line_referential, line) }) }
- it { should have_link_for_each_item(lines, "network", -> (line){ view.line_referential_network_path(line_referential, line.network) }) }
- it { should have_link_for_each_item(lines, "company", -> (line){ view.line_referential_company_path(line_referential, line.company) }) }
- }
+ describe "action links" do
+ set_invariant "line_referential.id", "99"
+ set_invariant "line_referential.name", "Name"
- common_items.call()
- it { should have_the_right_number_of_links(lines, 3) }
+ before(:each){
+ render template: "lines/index", layout: "layouts/application"
+ }
- with_permission "lines.change_status" do
- common_items.call()
- it { should have_link_for_each_item(lines, "deactivate", -> (line){ view.deactivate_line_referential_line_path(line_referential, line) }) }
- it { should have_the_right_number_of_links(lines, 4) }
+ it { should match_actions_links_snapshot "lines/index" }
+
+ %w(create update destroy).each do |p|
+ with_permission "lines.#{p}" do
+ it { should match_actions_links_snapshot "lines/index_#{p}" }
+ end
+ end
end
- with_permission "lines.destroy" do
- common_items.call()
- it {
- should have_link_for_each_item(lines, "destroy", {
- href: ->(line){ view.line_referential_line_path(line_referential, line)},
- method: :delete
- })
+ context "links" do
+ common_items = ->{
+ it { should have_link_for_each_item(lines, "show", -> (line){ view.line_referential_line_path(line_referential, line) }) }
+ it { should have_link_for_each_item(lines, "network", -> (line){ view.line_referential_network_path(line_referential, line.network) }) }
+ it { should have_link_for_each_item(lines, "company", -> (line){ view.line_referential_company_path(line_referential, line.company) }) }
}
- it { should have_the_right_number_of_links(lines, 4) }
- end
- context "with a deactivated item" do
+ common_items.call()
+ it { should have_the_right_number_of_links(lines, 3) }
+
with_permission "lines.change_status" do
- let(:deactivated_line){ create :line, deactivated: true }
+ common_items.call()
+ it { should have_link_for_each_item(lines, "deactivate", -> (line){ view.deactivate_line_referential_line_path(line_referential, line) }) }
+ it { should have_the_right_number_of_links(lines, 4) }
+ end
+ with_permission "lines.destroy" do
common_items.call()
- it "should display an activate link for the deactivated one" do
- lines.each do |line|
- if line == deactivated_line
- href = view.activate_line_referential_line_path(line_referential, line)
- else
- href = view.deactivate_line_referential_line_path(line_referential, line)
+ it {
+ should have_link_for_each_item(lines, "destroy", {
+ href: ->(line){ view.line_referential_line_path(line_referential, line)},
+ method: :delete
+ })
+ }
+ it { should have_the_right_number_of_links(lines, 4) }
+ end
+
+ context "with a deactivated item" do
+ with_permission "lines.change_status" do
+ let(:deactivated_line){ create :line, deactivated: true }
+
+ common_items.call()
+ it "should display an activate link for the deactivated one" do
+ lines.each do |line|
+ if line == deactivated_line
+ href = view.activate_line_referential_line_path(line_referential, line)
+ else
+ href = view.deactivate_line_referential_line_path(line_referential, line)
+ end
+ selector = "tr.#{TableBuilderHelper.item_row_class_name(lines)}-#{line.id} .actions a[href='#{href}']"
+ expect(rendered).to have_selector(selector, count: 1)
end
- selector = "tr.#{TableBuilderHelper.item_row_class_name(lines)}-#{line.id} .actions a[href='#{href}']"
- expect(rendered).to have_selector(selector, count: 1)
end
+ it { should have_the_right_number_of_links(lines, 4) }
end
- it { should have_the_right_number_of_links(lines, 4) }
end
end
end
diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb
index 9649d9c8e..effdcd014 100644
--- a/spec/views/lines/show.html.erb_spec.rb
+++ b/spec/views/lines/show.html.erb_spec.rb
@@ -15,6 +15,30 @@ describe "/lines/show", :type => :view do
let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) }
before do
- allow(view).to receive_messages(current_organisation: referential.organisation)
+ allow(view).to receive_messages(current_organisation: referential.organisation, resource: line)
+ controller.request.path_parameters[:line_referential_id] = line_referential.id
+ controller.request.path_parameters[:id] = line.id
+ allow(view).to receive(:params).and_return({action: :show})
+ end
+
+ describe "action links" do
+ set_invariant "line_referential.id", "99"
+ set_invariant "line.object.id", "99"
+ set_invariant "line.object.name", "Name"
+ set_invariant "line.company.id", "99"
+ set_invariant "line.network.id", "99"
+ set_invariant "line.updated_at", "2018/01/23".to_time
+
+ before(:each){
+ render template: "lines/show", layout: "layouts/application"
+ }
+
+ it { should match_actions_links_snapshot "lines/show" }
+
+ %w(create update destroy).each do |p|
+ with_permission "lines.#{p}" do
+ it { should match_actions_links_snapshot "lines/show_#{p}" }
+ end
+ end
end
end
diff --git a/spec/views/networks/__snapshots__/networks/index.snap b/spec/views/networks/__snapshots__/networks/index.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/index.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/index_create.snap b/spec/views/networks/__snapshots__/networks/index_create.snap
new file mode 100644
index 000000000..afd4aa41b
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/index_create.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><a class="btn btn-default" href="/line_referentials/99/networks/new">Ajouter un réseau</a></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/index_destroy.snap b/spec/views/networks/__snapshots__/networks/index_destroy.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/index_destroy.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/index_update.snap b/spec/views/networks/__snapshots__/networks/index_update.snap
new file mode 100644
index 000000000..2c5c23400
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/index_update.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/show.snap b/spec/views/networks/__snapshots__/networks/show.snap
new file mode 100644
index 000000000..8f2992065
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/show.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Réseau Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/show_create.snap b/spec/views/networks/__snapshots__/networks/show_create.snap
new file mode 100644
index 000000000..8f2992065
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/show_create.snap
@@ -0,0 +1,4 @@
+<div class="container-fluid"><div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Réseau Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div></div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/show_destroy.snap b/spec/views/networks/__snapshots__/networks/show_destroy.snap
new file mode 100644
index 000000000..c525c05b7
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/show_destroy.snap
@@ -0,0 +1,7 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Réseau Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right"><a data-confirm="Etes vous sûr de supprimer ce réseau ?" class="btn btn-primary" rel="nofollow" data-method="delete" href="/line_referentials/99/networks/909"><span class="fa fa-trash mr-xs"></span>Supprimer ce réseau</a></div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/networks/__snapshots__/networks/show_update.snap b/spec/views/networks/__snapshots__/networks/show_update.snap
new file mode 100644
index 000000000..35f8ee9ac
--- /dev/null
+++ b/spec/views/networks/__snapshots__/networks/show_update.snap
@@ -0,0 +1,7 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>Réseau Name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 23/01/2018 <br> Par web service</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right"><a class="btn btn-primary" href="/line_referentials/99/networks/909/edit">Editer ce réseau</a></div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/networks/index.html.erb_spec.rb b/spec/views/networks/index.html.erb_spec.rb
index d2dde7f87..80e755163 100644
--- a/spec/views/networks/index.html.erb_spec.rb
+++ b/spec/views/networks/index.html.erb_spec.rb
@@ -3,7 +3,11 @@ require 'spec_helper'
describe "/networks/index", :type => :view do
let!(:line_referential) { assign :line_referential, create(:line_referential) }
- let!(:networks) { assign :networks, Array.new(2){ create(:network, line_referential: line_referential) }.paginate }
+ let(:context){{line_referential: line_referential}}
+ let!(:networks) do
+ assign :networks, build_paginated_collection(:network, NetworkDecorator, line_referential: line_referential, context: context)
+ end
+
let!(:search) { assign :q, Ransack::Search.new(Chouette::Network) }
# it "should render a show link for each group" do
@@ -18,5 +22,27 @@ describe "/networks/index", :type => :view do
# render
# expect(view.content_for(:sidebar)).to have_selector("a[href='#{new_line_referential_network_path(line_referential)}']")
# end
+ before(:each) do
+ allow(view).to receive(:collection).and_return(networks)
+ allow(view).to receive(:decorated_collection).and_return(networks)
+ allow(view).to receive(:current_referential).and_return(line_referential)
+ controller.request.path_parameters[:line_referential_id] = line_referential.id
+ allow(view).to receive(:params).and_return({action: :index})
+ end
+
+ describe "action links" do
+ set_invariant "line_referential.id", "99"
+
+ before(:each){
+ render template: "networks/index", layout: "layouts/application"
+ }
+
+ it { should match_actions_links_snapshot "networks/index" }
+ %w(create update destroy).each do |p|
+ with_permission "networks.#{p}" do
+ it { should match_actions_links_snapshot "networks/index_#{p}" }
+ end
+ end
+ end
end
diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb
index 3926ead14..998e8ac44 100644
--- a/spec/views/networks/show.html.erb_spec.rb
+++ b/spec/views/networks/show.html.erb_spec.rb
@@ -11,8 +11,30 @@ describe "/networks/show", :type => :view do
let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) }
let!(:line_referential) { assign :line_referential, network.line_referential }
- # it "should display a map with class 'network'" do
- # render
- # expect(rendered).to have_selector("#map")
- # end
+ before(:each) do
+ allow(view).to receive(:current_referential).and_return(line_referential)
+ allow(view).to receive(:resource).and_return(network)
+ controller.request.path_parameters[:line_referential_id] = line_referential.id
+ controller.request.path_parameters[:id] = network.id
+ allow(view).to receive(:params).and_return({action: :show})
+ end
+
+ describe "action links" do
+ set_invariant "line_referential.id", "99"
+ set_invariant "network.object.id", "909"
+ set_invariant "network.object.updated_at", "2018/01/23".to_time
+ set_invariant "network.object.name", "Name"
+
+ before(:each){
+ render template: "networks/show", layout: "layouts/application"
+ }
+
+ it { should match_actions_links_snapshot "networks/show" }
+
+ %w(create update destroy).each do |p|
+ with_permission "networks.#{p}" do
+ it { should match_actions_links_snapshot "networks/show_#{p}" }
+ end
+ end
+ end
end
diff --git a/spec/views/referentials/__snapshots__/referentials/show.snap b/spec/views/referentials/__snapshots__/referentials/show.snap
new file mode 100644
index 000000000..83531ac0e
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_create.snap b/spec/views/referentials/__snapshots__/referentials/show_create.snap
new file mode 100644
index 000000000..e5d309b96
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_create.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" href="/referentials/new?from=99">Dupliquer</a><a class="btn btn-primary" href="/referentials/99/select_compliance_control_set">Valider</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap
new file mode 100644
index 000000000..d90198391
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" class="btn btn-primary" rel="nofollow" data-method="delete" href="/referentials/99"><span class="fa fa-trash mr-xs"></span>Supprimer</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap
new file mode 100644
index 000000000..83531ac0e
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap
new file mode 100644
index 000000000..e5d309b96
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" href="/referentials/new?from=99">Dupliquer</a><a class="btn btn-primary" href="/referentials/99/select_compliance_control_set">Valider</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap
new file mode 100644
index 000000000..d90198391
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" class="btn btn-primary" rel="nofollow" data-method="delete" href="/referentials/99"><span class="fa fa-trash mr-xs"></span>Supprimer</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap
new file mode 100644
index 000000000..32d46beda
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap
@@ -0,0 +1,12 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action">
+<div class="small last-update">Dernière mise à jour le 01/01/2000</div>
+<a class="btn btn-default" href="/referentials/99/edit">Editer</a>
+</div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" rel="nofollow" data-method="put" href="/referentials/99/archive">Conserver</a><button type="button" data-toggle="modal" data-target="#purgeModal" class="btn btn-primary">Purger</button>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap
new file mode 100644
index 000000000..83531ac0e
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap
new file mode 100644
index 000000000..82a77521a
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" href="/referentials/new?from=99">Dupliquer</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap
new file mode 100644
index 000000000..83531ac0e
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap
new file mode 100644
index 000000000..83531ac0e
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap
new file mode 100644
index 000000000..83531ac0e
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap
new file mode 100644
index 000000000..e5d309b96
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" href="/referentials/new?from=99">Dupliquer</a><a class="btn btn-primary" href="/referentials/99/select_compliance_control_set">Valider</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap
new file mode 100644
index 000000000..d90198391
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap
@@ -0,0 +1,9 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action"><div class="small last-update">Dernière mise à jour le 01/01/2000</div></div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" class="btn btn-primary" rel="nofollow" data-method="delete" href="/referentials/99"><span class="fa fa-trash mr-xs"></span>Supprimer</a>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap
new file mode 100644
index 000000000..32d46beda
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap
@@ -0,0 +1,12 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action">
+<div class="small last-update">Dernière mise à jour le 01/01/2000</div>
+<a class="btn btn-default" href="/referentials/99/edit">Editer</a>
+</div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" rel="nofollow" data-method="put" href="/referentials/99/archive">Conserver</a><button type="button" data-toggle="modal" data-target="#purgeModal" class="btn btn-primary">Purger</button>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/__snapshots__/referentials/show_update.snap b/spec/views/referentials/__snapshots__/referentials/show_update.snap
new file mode 100644
index 000000000..32d46beda
--- /dev/null
+++ b/spec/views/referentials/__snapshots__/referentials/show_update.snap
@@ -0,0 +1,12 @@
+<div class="container-fluid">
+<div class="row">
+<div class="col-lg-9 col-md-8 col-sm-7 col-xs-7"><div class="page-title"><h1>referential_full_name</h1></div></div>
+<div class="col-lg-3 col-md-4 col-sm-5 col-xs-5 text-right"><div class="page-action">
+<div class="small last-update">Dernière mise à jour le 01/01/2000</div>
+<a class="btn btn-default" href="/referentials/99/edit">Editer</a>
+</div></div>
+</div>
+<div class="row mb-sm"><div class="col-lg-12 text-right">
+<a class="btn btn-primary" href="/referentials/99/vehicle_journeys">Courses</a><a class="btn btn-primary" href="/referentials/99/purchase_windows">Calendriers commerciaux</a><a class="btn btn-primary" href="/referentials/99/time_tables">Calendriers</a><a class="btn btn-primary" rel="nofollow" data-method="put" href="/referentials/99/archive">Conserver</a><button type="button" data-toggle="modal" data-target="#purgeModal" class="btn btn-primary">Purger</button>
+</div></div>
+</div> \ No newline at end of file
diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb
index 4a2afe2ca..ea3bc1fe1 100644
--- a/spec/views/referentials/show.html.erb_spec.rb
+++ b/spec/views/referentials/show.html.erb_spec.rb
@@ -1,22 +1,23 @@
require 'spec_helper'
describe "referentials/show", type: :view do
-
let!(:referential) do
- referential = create(:referential)
+ referential = create(:referential, organisation: organisation)
assign :referential, referential.decorate(context: {
current_organisation: referential.organisation
})
end
let(:permissions){ [] }
let(:current_organisation) { organisation }
- let(:current_offer_workbench) { create :workbench, organisation: current_organisation}
+ let(:current_offer_workbench) { create :workbench, organisation: organisation}
+ let(:current_workgroup) { current_offer_workbench.workgroup }
let(:readonly){ false }
before :each do
assign :reflines, []
allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench)
allow(view).to receive(:current_organisation).and_return(current_organisation)
+ allow(view).to receive(:current_workgroup).and_return(current_workgroup)
allow(view).to receive(:current_user).and_return(current_user)
allow(view).to receive(:resource).and_return(referential)
@@ -26,24 +27,47 @@ describe "referentials/show", type: :view do
allow(view).to receive(:params).and_return({action: :show})
allow(referential).to receive(:referential_read_only?){ readonly }
- render template: "referentials/show", layout: "layouts/application"
- end
-
- it "should not present edit button" do
- expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
end
- with_permission "referentials.update" do
- it "should present edit button" do
- expect(rendered).to have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
- end
+ describe "action links" do
+ set_invariant "referential.object.full_name", "referential_full_name"
+ set_invariant "referential.object.updated_at", "01/01/2000 00:00".to_time
+ set_invariant "referential.object.id", "99"
+ before(:each){
+ render template: "referentials/show", layout: "layouts/application"
+ }
context "with a readonly referential" do
let(:readonly){ true }
- it "should not present edit button" do
- expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
+ it { should match_actions_links_snapshot "referentials/show_readonly" }
+
+ %w(create destroy update).each do |p|
+ with_permission "referentials.#{p}" do
+ it { should match_actions_links_snapshot "referentials/show_readonly_#{p}" }
+ end
end
end
- end
+ context "with a non-readonly referential" do
+ it { should match_actions_links_snapshot "referentials/show" }
+
+ %w(create destroy update).each do |p|
+ with_permission "referentials.#{p}" do
+ it { should match_actions_links_snapshot "referentials/show_#{p}" }
+ end
+ end
+ end
+
+ %w(purchase_windows referential_vehicle_journeys).each do |f|
+ with_feature f do
+ it { should match_actions_links_snapshot "referentials/show_#{f}" }
+
+ %w(create update destroy).each do |p|
+ with_permission "referentials.#{p}" do
+ it { should match_actions_links_snapshot "referentials/show_#{f}_#{p}" }
+ end
+ end
+ end
+ end
+ end
end