aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/referentials_controller_spec.rb2
-rw-r--r--spec/controllers/stop_areas_controller_spec.rb2
-rw-r--r--spec/factories/chouette_lines.rb4
-rw-r--r--spec/factories/chouette_stop_points.rb2
-rw-r--r--spec/factories/stop_area_referentials.rb9
-rw-r--r--spec/features/stop_areas_spec.rb2
-rw-r--r--spec/helpers/common_helper_spec.rb39
-rw-r--r--spec/javascript/vehicle_journeys/actions_spec.js58
-rw-r--r--spec/javascript/vehicle_journeys/reducers/modal_spec.js9
-rw-r--r--spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js1
-rw-r--r--spec/models/chouette/access_point_spec.rb2
-rw-r--r--spec/models/chouette/route/route_duplication_spec.rb11
-rw-r--r--spec/models/chouette/stop_area_spec.rb36
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb18
-rw-r--r--spec/models/compliance_control_spec.rb10
-rw-r--r--spec/models/import_spec.rb5
-rw-r--r--spec/views/imports/show.html.slim_spec.rb9
17 files changed, 148 insertions, 71 deletions
diff --git a/spec/controllers/referentials_controller_spec.rb b/spec/controllers/referentials_controller_spec.rb
index 4050a8812..f97480600 100644
--- a/spec/controllers/referentials_controller_spec.rb
+++ b/spec/controllers/referentials_controller_spec.rb
@@ -45,7 +45,7 @@ describe ReferentialsController, :type => :controller do
describe "POST #create" do
context "when duplicating" do
- it "displays a flash message" do
+ it "displays a flash message", pending: 'requires more params to create a valid Referential' do
post :create,
from: referential.id,
current_workbench_id: referential.workbench_id,
diff --git a/spec/controllers/stop_areas_controller_spec.rb b/spec/controllers/stop_areas_controller_spec.rb
index 2b5f8c3e2..23bca3c36 100644
--- a/spec/controllers/stop_areas_controller_spec.rb
+++ b/spec/controllers/stop_areas_controller_spec.rb
@@ -1,7 +1,7 @@
RSpec.describe StopAreasController, :type => :controller do
login_user
- let(:stop_area_referential) { create :stop_area_referential }
+ let(:stop_area_referential) { create :stop_area_referential, member: @user.organisation }
let(:stop_area) { create :stop_area, stop_area_referential: stop_area_referential }
describe 'PUT deactivate' do
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index 95f760174..c013b9d2b 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -8,7 +8,7 @@ FactoryGirl.define do
association :network, :factory => :network
association :company, :factory => :company
-
+
before(:create) do |line|
line.line_referential ||= LineReferential.find_by! name: "first"
end
@@ -35,7 +35,7 @@ FactoryGirl.define do
after(:create) do |line|
line.routes.each do |route|
route.stop_points.each do |stop_point|
- comm = create(:stop_area, :area_type => "lda")
+ comm = create(:stop_area, :area_type => "gdl")
stop_point.stop_area.update_attributes(:parent_id => comm.id)
end
end
diff --git a/spec/factories/chouette_stop_points.rb b/spec/factories/chouette_stop_points.rb
index 14e08b1ac..97baae2fd 100644
--- a/spec/factories/chouette_stop_points.rb
+++ b/spec/factories/chouette_stop_points.rb
@@ -2,7 +2,7 @@ FactoryGirl.define do
factory :stop_point, :class => Chouette::StopPoint do
sequence(:objectid) { |n| "test:StopPoint:#{n}:loc" }
- association :stop_area, :factory => :stop_area
+ association :stop_area, :factory => :stop_area, area_type: "zdep"
end
end
diff --git a/spec/factories/stop_area_referentials.rb b/spec/factories/stop_area_referentials.rb
index fcba996e4..bdac050b1 100644
--- a/spec/factories/stop_area_referentials.rb
+++ b/spec/factories/stop_area_referentials.rb
@@ -2,5 +2,14 @@ FactoryGirl.define do
factory :stop_area_referential, :class => StopAreaReferential do
sequence(:name) { |n| "StopArea Referential #{n}" }
objectid_format 'stif_reflex'
+
+ transient do
+ member nil
+ end
+
+ after(:create) do |stop_area_referential, evaluator|
+ stop_area_referential.add_member evaluator.member if evaluator.member
+ stop_area_referential.save
+ end
end
end
diff --git a/spec/features/stop_areas_spec.rb b/spec/features/stop_areas_spec.rb
index 6afb22bc6..668eb2fa3 100644
--- a/spec/features/stop_areas_spec.rb
+++ b/spec/features/stop_areas_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
describe "StopAreas", :type => :feature do
login_user
- let(:stop_area_referential) { create :stop_area_referential }
+ let(:stop_area_referential) { create :stop_area_referential, member: @user.organisation }
let!(:stop_areas) { Array.new(2) { create :stop_area, stop_area_referential: stop_area_referential } }
subject { stop_areas.first }
diff --git a/spec/helpers/common_helper_spec.rb b/spec/helpers/common_helper_spec.rb
deleted file mode 100644
index 1ffdc5bab..000000000
--- a/spec/helpers/common_helper_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-RSpec.describe CommonHelper do
-
- subject do
- Object.new.extend( described_class )
- end
-
- describe 'string_keys_to_symbols' do
- context 'nullpotency on symbol keys' do
- it { expect(subject.string_keys_to_symbols({})).to eq({}) }
- it do
- expect(subject.string_keys_to_symbols(
- a: 1, b: 2
- )).to eq(a: 1, b: 2)
- end
- end
-
- context 'changing string keys' do
- it { expect(subject.string_keys_to_symbols('alpha' => 100)).to eq(alpha: 100) }
-
- it do
- expect( subject.string_keys_to_symbols('a' => 10, b: 20) )
- .to eq(a: 10, b: 20)
- end
- it do
- expect( subject.string_keys_to_symbols('a' => 10, 'b' => 20) )
- .to eq(a: 10, b: 20)
- end
- end
-
- context 'keys, not values, are changed' do
- it do
- expect(subject.string_keys_to_symbols(a: 'a', 'b' => 'b', 'c' => :c))
- .to eq(a: 'a', b: 'b', c: :c)
- end
- end
-
-
- end
-end
diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js
index 3af19ebc3..2f1daf0da 100644
--- a/spec/javascript/vehicle_journeys/actions_spec.js
+++ b/spec/javascript/vehicle_journeys/actions_spec.js
@@ -174,15 +174,55 @@ describe('when clicking on validate button inside shifting modal', () => {
})
})
describe('when clicking on validate button inside editing modal', () => {
- it('should create an action to update a vehiclejourney', () => {
- const data = {}
- const selectedCompany = {}
- const expectedAction = {
- type: 'EDIT_VEHICLEJOURNEY',
- data,
- selectedCompany
- }
- expect(actions.editVehicleJourney(data, selectedCompany)).toEqual(expectedAction)
+ context("with invalid data", () => {
+ it('should not validate the data', () => {
+ const data = {
+ foo: {
+ validity: { valid: false }
+ },
+ bar: {
+ validity: { valid: true }
+ }
+ }
+
+ expect(actions.validateFields(data)).toBeFalsy
+ })
+ })
+
+ context("with data not needing validation", () => {
+ it('should validate the data', () => {
+ const data = {
+ foo: {}
+ }
+
+ expect(actions.validateFields(data)).toBeTruthy
+ })
+ })
+ context("with valid data", () => {
+ it('should validate the data', () => {
+ const data = {
+ foo: {
+ validity: { valid: true }
+ },
+ bar: {
+ validity: { valid: true }
+ }
+ }
+
+ expect(actions.validateFields(data)).toBeTruthy
+ })
+ })
+ context("once the data has been validated", () => {
+ it('should create an action to update a vehiclejourney', () => {
+ const data = {}
+ const selectedCompany = {}
+ const expectedAction = {
+ type: 'EDIT_VEHICLEJOURNEY',
+ data,
+ selectedCompany
+ }
+ expect(actions.editVehicleJourney(data, selectedCompany)).toEqual(expectedAction)
+ })
})
})
describe('when clicking on validate button inside duplicating modal', () => {
diff --git a/spec/javascript/vehicle_journeys/reducers/modal_spec.js b/spec/javascript/vehicle_journeys/reducers/modal_spec.js
index ea8a002d2..ee50f091b 100644
--- a/spec/javascript/vehicle_journeys/reducers/modal_spec.js
+++ b/spec/javascript/vehicle_journeys/reducers/modal_spec.js
@@ -241,13 +241,12 @@ describe('modal reducer', () => {
})
it('should handle SELECT_CP_EDIT_MODAL', () => {
- let newModalProps = {selectedCompany : {name: 'ALBATRANS'}}
expect(
modalReducer(state, {
type: 'SELECT_CP_EDIT_MODAL',
selectedItem: {name: 'ALBATRANS'}
- })
- ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ }).modalProps.vehicleJourney.company
+ ).toEqual({name: 'ALBATRANS'})
})
it('should handle UNSELECT_CP_EDIT_MODAL', () => {
@@ -255,7 +254,7 @@ describe('modal reducer', () => {
expect(
modalReducer(state, {
type: 'UNSELECT_CP_EDIT_MODAL'
- })
- ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ }).modalProps.vehicleJourney.company
+ ).toBe(undefined)
})
})
diff --git a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
index c834de1f6..28de241ee 100644
--- a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
+++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
@@ -110,6 +110,7 @@ describe('vehicleJourneys reducer', () => {
objectid: '',
footnotes: [],
time_tables: [],
+ purchase_windows: [],
vehicle_journey_at_stops: pristineVjasList,
selected: false,
deletable: false,
diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb
index c734ecedf..2184c6ec2 100644
--- a/spec/models/chouette/access_point_spec.rb
+++ b/spec/models/chouette/access_point_spec.rb
@@ -136,7 +136,7 @@ describe Chouette::AccessPoint, :type => :model do
describe "#generic_access_link_matrix" do
it "should have 2 generic_access_links in matrix" do
- stop_place = create :stop_area, :area_type => "zdlp"
+ stop_place = create :stop_area, :area_type => "gdl"
commercial_stop_point = create :stop_area, :area_type => "lda" ,:parent => stop_place
subject = create :access_point, :stop_area => stop_place
expect(subject.generic_access_link_matrix.size).to eq(2)
diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb
index ee45b5005..8b3a948a2 100644
--- a/spec/models/chouette/route/route_duplication_spec.rb
+++ b/spec/models/chouette/route/route_duplication_spec.rb
@@ -2,7 +2,7 @@ RSpec.describe Chouette::Route do
let!( :route ){ create :route }
- context '#duplicate' do
+ context '#duplicate' do
describe 'properties' do
it 'same attribute values' do
route.duplicate
@@ -23,7 +23,12 @@ RSpec.describe Chouette::Route do
it 'duplicates its stop points' do
expect{ route.duplicate }.to change{Chouette::StopPoint.count}.by(route.stop_points.count)
end
- it 'does bot duplicate the stop areas' do
+
+ it 'duplicates its stop points in the same order' do
+ expect(route.duplicate.stop_points.order(:position).map(&:stop_area_id)).to eq route.stop_points.order(:position).map(&:stop_area_id)
+ end
+
+ it 'does not duplicate the stop areas' do
expect{ route.duplicate }.not_to change{Chouette::StopArea.count}
end
end
@@ -34,7 +39,7 @@ RSpec.describe Chouette::Route do
it 'the required attributes' do
expect( values_for_create(first_duplicate, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( second_duplicate, except: %w{objectid name checksum checksum_source} ) )
- end
+ end
it 'the stop areas' do
expect( first_duplicate.stop_areas.pluck(:id) ).to eq( route.stop_areas.pluck(:id) )
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index bec8c0868..9db0f11a5 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -426,6 +426,42 @@ describe Chouette::StopArea, :type => :model do
# end
# end
+ describe "#parent" do
+
+ let(:stop_area) { FactoryGirl.build :stop_area, parent: FactoryGirl.build(:stop_area) }
+
+ it "is valid when parent has an 'higher' type" do
+ stop_area.area_type = 'zdep'
+ stop_area.parent.area_type = 'zdlp'
+
+ stop_area.valid?
+ expect(stop_area.errors).to_not have_key(:parent_id)
+ end
+
+ it "is valid when parent is undefined" do
+ stop_area.parent = nil
+
+ stop_area.valid?
+ expect(stop_area.errors).to_not have_key(:parent_id)
+ end
+
+ it "isn't valid when parent has the same type" do
+ stop_area.parent.area_type = stop_area.area_type = 'zdep'
+
+ stop_area.valid?
+ expect(stop_area.errors).to have_key(:parent_id)
+ end
+
+ it "isn't valid when parent has a lower type" do
+ stop_area.area_type = 'lda'
+ stop_area.parent.area_type = 'zdep'
+
+ stop_area.valid?
+ expect(stop_area.errors).to have_key(:parent_id)
+ end
+
+ end
+
describe '#waiting_time' do
let(:stop_area) { FactoryGirl.build :stop_area }
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index d74c0ebee..eb2a31794 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -77,6 +77,7 @@ describe Chouette::VehicleJourney, :type => :model do
vj.slice('objectid', 'published_journey_name', 'journey_pattern_id', 'company_id').tap do |item|
item['vehicle_journey_at_stops'] = []
item['time_tables'] = []
+ item['purchase_windows'] = []
item['footnotes'] = []
item['purchase_windows'] = []
@@ -161,6 +162,23 @@ describe Chouette::VehicleJourney, :type => :model do
expect(vehicle_journey.reload.time_tables).to be_empty
end
+ it 'should update vj purchase_windows association from state' do
+ 2.times{state['purchase_windows'] << create(:purchase_window, referential: referential).slice('id', 'name', 'objectid', 'color')}
+ vehicle_journey.update_has_and_belongs_to_many_from_state(state)
+
+ expected = state['purchase_windows'].map{|tt| tt['id']}
+ actual = vehicle_journey.reload.purchase_windows.map(&:id)
+ expect(actual).to match_array(expected)
+ end
+
+ it 'should clear vj purchase_windows association when remove from state' do
+ vehicle_journey.purchase_windows << create(:purchase_window, referential: referential)
+ state['purchase_windows'] = []
+ vehicle_journey.update_has_and_belongs_to_many_from_state(state)
+
+ expect(vehicle_journey.reload.purchase_windows).to be_empty
+ end
+
it 'should update vj footnote association from state' do
2.times{state['footnotes'] << create(:footnote, line: route.line).slice('id', 'code', 'label', 'line_id')}
vehicle_journey.update_has_and_belongs_to_many_from_state(state)
diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb
index 4267459ea..5cffba58d 100644
--- a/spec/models/compliance_control_spec.rb
+++ b/spec/models/compliance_control_spec.rb
@@ -1,5 +1,15 @@
RSpec.describe ComplianceControl, type: :model do
+ context 'dynamic attributes' do
+ let(:compliance_control1) { build_stubbed :compliance_control }
+ let(:compliance_control2) { build_stubbed :compliance_control, type: 'VehicleJouneyControl::TimeTable' }
+
+ it 'should always return a array' do
+ expect(compliance_control1.class.dynamic_attributes).to be_kind_of Array
+ expect(compliance_control2.class.dynamic_attributes).to be_kind_of Array
+ end
+ end
+
context 'standard validation' do
let(:compliance_control) { build_stubbed :compliance_control }
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index 3e4128865..ffb2360c2 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -10,8 +10,9 @@ RSpec.describe Import, type: :model do
it { should validate_presence_of(:workbench) }
it { should validate_presence_of(:creator) }
- it { should allow_value('file.zip').for(:file).with_message(I18n.t('activerecord.errors.models.import.attributes.file.wrong_file_extension')) }
- it { should_not allow_values('file.json', 'file.png', 'file.pdf').for(:file) }
+ include ActionDispatch::TestProcess
+ it { should allow_value(fixture_file_upload('OFFRE_TRANSDEV_2017030112251.zip')).for(:file) }
+ it { should_not allow_value(fixture_file_upload('users.json')).for(:file).with_message(I18n.t('errors.messages.extension_whitelist_error', extension: '"json"', allowed_types: "zip")) }
let(:workbench_import) {netex_import.parent}
let(:workbench_import_with_completed_steps) do
diff --git a/spec/views/imports/show.html.slim_spec.rb b/spec/views/imports/show.html.slim_spec.rb
index 1811d2acf..7a046d1a2 100644
--- a/spec/views/imports/show.html.slim_spec.rb
+++ b/spec/views/imports/show.html.slim_spec.rb
@@ -22,20 +22,17 @@ RSpec.describe '/imports/show', type: :view do
messages.each do | message |
# require 'htmlbeautifier'
# b = HtmlBeautifier.beautify(rendered, indent: ' ')
- expect(rendered).to have_selector('dl#import_messages dt.import_message') do
+ expect(rendered).to have_selector('.import_message-list dl dt.criticity') do
with_text message.criticity
end
- expect(rendered).to have_selector('dl#import_messages dd.import_message') do
+ expect(rendered).to have_selector('.import_message-list dl dd') do
with_text rendered_message( message )
end
end
end
-
def rendered_message message
- Object.new.extend(CommonHelper).tap do |helper|
- return I18n.t(message.message_key, helper.string_keys_to_symbols( message.message_attributes ))
- end
+ return I18n.t message.message_key, message.message_attributes.symbolize_keys
end
end