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/factories/chouette_lines.rb4
-rw-r--r--spec/factories/chouette_stop_points.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/models/chouette/access_point_spec.rb2
-rw-r--r--spec/models/chouette/stop_area_spec.rb36
-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
11 files changed, 110 insertions, 66 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/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/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/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/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/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