aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/exports_controller_spec.rb2
-rw-r--r--spec/controllers/routes_controller_spec.rb44
-rw-r--r--spec/factories/custom_fields.rb2
-rw-r--r--spec/features/calendars_permissions_spec.rb4
-rw-r--r--spec/features/compliance_control_sets_spec.rb2
-rw-r--r--spec/fixtures/tom_tom_matrix.json123
-rw-r--r--spec/lib/compliance_control_set_cloner_spec.rb2
-rw-r--r--spec/lib/compliance_control_set_copier_spec.rb2
-rw-r--r--spec/lib/route_way_cost_unit_converter_spec.rb28
-rw-r--r--spec/lib/tom_tom/matrix/request_json_serializer_spec.rb39
-rw-r--r--spec/lib/tom_tom/matrix_spec.rb228
-rw-r--r--spec/models/api/v1/api_key_spec.rb2
-rw-r--r--spec/models/calendar_spec.rb2
-rw-r--r--spec/models/chouette/access_link_spec.rb2
-rw-r--r--spec/models/chouette/access_point_spec.rb2
-rw-r--r--spec/models/chouette/company_spec.rb2
-rw-r--r--spec/models/chouette/connection_link_spec.rb2
-rw-r--r--spec/models/chouette/group_of_line_spec.rb2
-rw-r--r--spec/models/chouette/journey_pattern_spec.rb2
-rw-r--r--spec/models/chouette/line_spec.rb2
-rw-r--r--spec/models/chouette/network_spec.rb2
-rw-r--r--spec/models/chouette/route/route_base_spec.rb3
-rw-r--r--spec/models/chouette/route/route_duplication_spec.rb3
-rw-r--r--spec/models/chouette/routing_constraint_zone_spec.rb2
-rw-r--r--spec/models/chouette/stop_area_spec.rb2
-rw-r--r--spec/models/chouette/stop_point_spec.rb2
-rw-r--r--spec/models/chouette/time_table_spec.rb2
-rw-r--r--spec/models/chouette/timeband_spec.rb2
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb54
-rw-r--r--spec/models/compliance_check_set_spec.rb2
-rw-r--r--spec/models/compliance_control_block_spec.rb12
-rw-r--r--spec/models/compliance_control_set_spec.rb2
-rw-r--r--spec/models/custom_field_spec.rb67
-rw-r--r--spec/models/referential_metadata_spec.rb19
-rw-r--r--spec/models/referential_spec.rb2
-rw-r--r--spec/models/route_spec.rb68
-rw-r--r--spec/services/route_way_cost_calculator_spec.rb10
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/referential.rb12
-rw-r--r--spec/views/companies/edit.html.erb_spec.rb5
-rw-r--r--spec/views/companies/new.html.erb_spec.rb5
-rw-r--r--spec/views/stop_areas/edit.html.erb_spec.rb1
-rw-r--r--spec/views/stop_areas/new.html.erb_spec.rb1
43 files changed, 728 insertions, 45 deletions
diff --git a/spec/controllers/exports_controller_spec.rb b/spec/controllers/exports_controller_spec.rb
index 9d8dde4ff..e2b89fc26 100644
--- a/spec/controllers/exports_controller_spec.rb
+++ b/spec/controllers/exports_controller_spec.rb
@@ -85,7 +85,7 @@ RSpec.describe ExportsController, :type => :controller do
context "with the token" do
it 'should be successful' do
post :upload, workbench_id: workbench.id, id: export.id, token: export.token_upload
- expect(response).to be_redirect
+ expect(response).to be_success
end
end
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb
index e4dc6bc23..b7cb66b46 100644
--- a/spec/controllers/routes_controller_spec.rb
+++ b/spec/controllers/routes_controller_spec.rb
@@ -42,11 +42,14 @@ RSpec.describe RoutesController, type: :controller do
before(:each) do
post :create, line_id: route.line_id,
referential_id: referential.id,
- route: { name: "changed"}
+ route: { name: "changed", published_name: "published_name"}
end
it_behaves_like "line and referential linked"
it_behaves_like "redirected to referential_line_path(referential,line)"
+ it "sets metadata" do
+ expect(Chouette::Route.last.metadata.creator_username).to eq @user.username
+ end
end
describe "PUT /update" do
@@ -58,6 +61,9 @@ RSpec.describe RoutesController, type: :controller do
it_behaves_like "route, line and referential linked"
it_behaves_like "redirected to referential_line_path(referential,line)"
+ it "sets metadata" do
+ expect(Chouette::Route.last.metadata.modifier_username).to eq @user.username
+ end
end
describe "GET /show" do
@@ -83,6 +89,42 @@ RSpec.describe RoutesController, type: :controller do
expect(Chouette::Route.last.name).to eq(I18n.t('activerecord.copy', name: route.name))
expect(Chouette::Route.last.published_name).to eq(route.published_name)
+ expect(Chouette::Route.last.stop_area_ids).to eq route.stop_area_ids
+ end
+
+ context "when opposite = true" do
+ it "creates a new route on the opposite way " do
+ expect do
+ post :duplicate,
+ referential_id: route.line.line_referential_id,
+ line_id: route.line_id,
+ id: route.id,
+ opposite: TRUE
+ end.to change { Chouette::Route.count }.by(1)
+
+ expect(Chouette::Route.last.name).to eq(I18n.t('routes.opposite', name: route.name))
+ expect(Chouette::Route.last.published_name).to eq(Chouette::Route.last.name)
+ expect(Chouette::Route.last.opposite_route).to eq(route)
+ expect(Chouette::Route.last.stop_area_ids).to eq route.stop_area_ids.reverse
+ end
+ end
+
+ context "on a duplicated route" do
+ let!(:duplicated){ route.duplicate }
+ it "creates a new route on the opposite way " do
+ expect do
+ post :duplicate,
+ referential_id: duplicated.line.line_referential_id,
+ line_id: duplicated.line_id,
+ id: duplicated.id,
+ opposite: TRUE
+ end.to change { Chouette::Route.count }.by(1)
+
+ expect(Chouette::Route.last.name).to eq(I18n.t('routes.opposite', name: duplicated.name))
+ expect(Chouette::Route.last.published_name).to eq(Chouette::Route.last.name)
+ expect(Chouette::Route.last.opposite_route).to eq(duplicated)
+ expect(Chouette::Route.last.stop_area_ids).to eq duplicated.stop_area_ids.reverse
+ end
end
end
end
diff --git a/spec/factories/custom_fields.rb b/spec/factories/custom_fields.rb
index 7c43a6147..db7a3823e 100644
--- a/spec/factories/custom_fields.rb
+++ b/spec/factories/custom_fields.rb
@@ -3,7 +3,7 @@ FactoryGirl.define do
code "code"
resource_type "VehicleJourney"
sequence(:name){|n| "custom field ##{n}"}
- field_type "list"
+ field_type "integer"
options( { capacity: "0" } )
end
end
diff --git a/spec/features/calendars_permissions_spec.rb b/spec/features/calendars_permissions_spec.rb
index 4857592d5..656c0dd78 100644
--- a/spec/features/calendars_permissions_spec.rb
+++ b/spec/features/calendars_permissions_spec.rb
@@ -1,8 +1,8 @@
RSpec.describe 'Calendars', type: :feature do
login_user
- let(:calendar) { create :calendar, organisation_id: 1 }
- let(:workgroup) { calendar.workgroup }
+ let(:calendar) { create :calendar, organisation: first_organisation, workgroup: first_workgroup }
+ let(:workgroup) { first_workgroup }
describe 'permissions' do
before do
diff --git a/spec/features/compliance_control_sets_spec.rb b/spec/features/compliance_control_sets_spec.rb
index 0f4597db3..306f363a5 100644
--- a/spec/features/compliance_control_sets_spec.rb
+++ b/spec/features/compliance_control_sets_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe "ComplianceControlSets", type: :feature do
let(:other_control_cset) { create :compliance_control_set, organisation: other_orga }
let(:blox){
- 2.times.map{ | _ | create :compliance_control_block, compliance_control_set: control_set }
+ 2.times.map{ |n| create :compliance_control_block, compliance_control_set: control_set, transport_mode: StifTransportModeEnumerations.transport_modes[n], transport_submode: StifTransportSubmodeEnumerations.transport_submodes[n] }
}
before do
diff --git a/spec/fixtures/tom_tom_matrix.json b/spec/fixtures/tom_tom_matrix.json
new file mode 100644
index 000000000..30048576c
--- /dev/null
+++ b/spec/fixtures/tom_tom_matrix.json
@@ -0,0 +1,123 @@
+{
+ "formatVersion": "0.0.1",
+ "matrix": [
+ [
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 0,
+ "travelTimeInSeconds": 0,
+ "trafficDelayInSeconds": 0,
+ "departureTime": "2018-03-23T11:20:17+01:00",
+ "arrivalTime": "2018-03-23T11:20:17+01:00"
+ }
+ }
+ },
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 117947,
+ "travelTimeInSeconds": 8356,
+ "trafficDelayInSeconds": 0,
+ "departureTime": "2018-03-23T11:20:17+01:00",
+ "arrivalTime": "2018-03-23T13:39:32+01:00"
+ }
+ }
+ },
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 999088,
+ "travelTimeInSeconds": 62653,
+ "trafficDelayInSeconds": 298,
+ "departureTime": "2018-03-23T11:20:17+01:00",
+ "arrivalTime": "2018-03-24T04:44:30+01:00"
+ }
+ }
+ }
+ ],
+ [
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 117231,
+ "travelTimeInSeconds": 9729,
+ "trafficDelayInSeconds": 0,
+ "departureTime": "2018-03-23T11:20:17+01:00",
+ "arrivalTime": "2018-03-23T14:02:25+01:00"
+ }
+ }
+ },
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 0,
+ "travelTimeInSeconds": 0,
+ "trafficDelayInSeconds": 0,
+ "departureTime": "2018-03-23T11:20:17+01:00",
+ "arrivalTime": "2018-03-23T11:20:17+01:00"
+ }
+ }
+ },
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 1114635,
+ "travelTimeInSeconds": 72079,
+ "trafficDelayInSeconds": 298,
+ "departureTime": "2018-03-23T11:20:18+01:00",
+ "arrivalTime": "2018-03-24T07:21:36+01:00"
+ }
+ }
+ }
+ ],
+ [
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 997232,
+ "travelTimeInSeconds": 63245,
+ "trafficDelayInSeconds": 179,
+ "departureTime": "2018-03-23T11:20:18+01:00",
+ "arrivalTime": "2018-03-24T04:54:23+01:00"
+ }
+ }
+ },
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 1113108,
+ "travelTimeInSeconds": 68485,
+ "trafficDelayInSeconds": 52,
+ "departureTime": "2018-03-23T11:20:18+01:00",
+ "arrivalTime": "2018-03-24T06:21:43+01:00"
+ }
+ }
+ },
+ {
+ "statusCode": 200,
+ "response": {
+ "routeSummary": {
+ "lengthInMeters": 344,
+ "travelTimeInSeconds": 109,
+ "trafficDelayInSeconds": 0,
+ "departureTime": "2018-03-23T11:20:18+01:00",
+ "arrivalTime": "2018-03-23T11:22:07+01:00"
+ }
+ }
+ }
+ ]
+ ],
+ "summary": {
+ "successfulRoutes": 9,
+ "totalRoutes": 9
+ }
+}
diff --git a/spec/lib/compliance_control_set_cloner_spec.rb b/spec/lib/compliance_control_set_cloner_spec.rb
index 7efe27659..0d3561e0e 100644
--- a/spec/lib/compliance_control_set_cloner_spec.rb
+++ b/spec/lib/compliance_control_set_cloner_spec.rb
@@ -49,7 +49,7 @@ RSpec.describe ComplianceControlSetCloner do
context 'Directed Acyclic Graph is copied correctly' do
let(:source_blox){
- 3.times.map{ |_| create :compliance_control_block, compliance_control_set: source_set }
+ 3.times.map{ |n| create :compliance_control_block, compliance_control_set: source_set, transport_mode: StifTransportModeEnumerations.transport_modes[n], transport_submode: StifTransportSubmodeEnumerations.transport_submodes[n] }
}
let(:direct_ccs){
3.times.map{ |n| create :generic_attribute_control_min_max, compliance_control_set: source_set, name: "direct #{n.succ}", code: "direct-#{n.succ}" }
diff --git a/spec/lib/compliance_control_set_copier_spec.rb b/spec/lib/compliance_control_set_copier_spec.rb
index 0f15d86d0..d1a56cd7f 100644
--- a/spec/lib/compliance_control_set_copier_spec.rb
+++ b/spec/lib/compliance_control_set_copier_spec.rb
@@ -23,7 +23,7 @@ RSpec.describe ComplianceControlSetCopier do
context 'Directed Acyclic Graph is copied correctly' do
let(:cc_blox){
- 3.times.map{ |_| create :compliance_control_block, compliance_control_set: cc_set }
+ 3.times.map{ |n| create :compliance_control_block, compliance_control_set: cc_set, transport_mode: StifTransportModeEnumerations.transport_modes[n], transport_submode: StifTransportSubmodeEnumerations.transport_submodes[n] }
}
let!(:direct_ccs){
3.times.map{ |n| create :compliance_control, compliance_control_set: cc_set, name: "direct #{n.succ}", code: "direct-#{n.succ}" }
diff --git a/spec/lib/route_way_cost_unit_converter_spec.rb b/spec/lib/route_way_cost_unit_converter_spec.rb
index 3c5e51710..aa25d57d2 100644
--- a/spec/lib/route_way_cost_unit_converter_spec.rb
+++ b/spec/lib/route_way_cost_unit_converter_spec.rb
@@ -35,4 +35,32 @@ RSpec.describe RouteWayCostUnitConverter do
})
end
end
+
+ describe ".meters_to_kilometers" do
+ it "converts meters to integer kilometres" do
+ expect(
+ RouteWayCostUnitConverter.meters_to_kilometers(6350)
+ ).to eq(6)
+ end
+
+ it "snaps values between 0 and 1 to 1" do
+ expect(
+ RouteWayCostUnitConverter.meters_to_kilometers(50)
+ ).to eq(1)
+ end
+ end
+
+ describe ".seconds_to_minutes" do
+ it "converts seconds to minutes" do
+ expect(
+ RouteWayCostUnitConverter.seconds_to_minutes(300)
+ ).to eq(5)
+ end
+
+ it "snaps values between 0 and 1 to 1" do
+ expect(
+ RouteWayCostUnitConverter.seconds_to_minutes(3)
+ ).to eq(1)
+ end
+ end
end
diff --git a/spec/lib/tom_tom/matrix/request_json_serializer_spec.rb b/spec/lib/tom_tom/matrix/request_json_serializer_spec.rb
new file mode 100644
index 000000000..1fafad302
--- /dev/null
+++ b/spec/lib/tom_tom/matrix/request_json_serializer_spec.rb
@@ -0,0 +1,39 @@
+RSpec.describe TomTom::Matrix::RequestJSONSerializer do
+ describe ".dump" do
+ it "serializes BigDecimal values to floats" do
+ points = [{
+ point: {
+ latitude: 52.50867.to_d,
+ longitude: 13.42879.to_d
+ },
+ }]
+ data = {
+ origins: points,
+ destinations: points
+ }
+
+ expect(
+ TomTom::Matrix::RequestJSONSerializer.dump(data)
+ ).to eq(<<-JSON.delete(" \n"))
+ {
+ "origins": [
+ {
+ "point": {
+ "latitude": 52.50867,
+ "longitude": 13.42879
+ }
+ }
+ ],
+ "destinations": [
+ {
+ "point": {
+ "latitude": 52.50867,
+ "longitude": 13.42879
+ }
+ }
+ ]
+ }
+ JSON
+ end
+ end
+end
diff --git a/spec/lib/tom_tom/matrix_spec.rb b/spec/lib/tom_tom/matrix_spec.rb
new file mode 100644
index 000000000..605f1d254
--- /dev/null
+++ b/spec/lib/tom_tom/matrix_spec.rb
@@ -0,0 +1,228 @@
+RSpec.describe TomTom::Matrix do
+ let(:matrix) { TomTom::Matrix.new(nil) }
+
+ describe "#points_from_way_costs" do
+ it "extracts a set of lat/lng coordinates from a list of WayCosts" do
+ way_costs = [
+ WayCost.new(
+ departure: Geokit::LatLng.new(48.85086, 2.36143),
+ arrival: Geokit::LatLng.new(47.91231, 1.87606),
+ id: '44-77'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(47.91231, 1.87606),
+ arrival: Geokit::LatLng.new(52.50867, 13.42879),
+ id: '77-88'
+ )
+ ]
+
+ expect(
+ matrix.points_from_way_costs(way_costs)
+ ).to eq([
+ TomTom::Matrix::Point.new(
+ Geokit::LatLng.new(48.85086, 2.36143),
+ '44'
+ ),
+ TomTom::Matrix::Point.new(
+ Geokit::LatLng.new(47.91231, 1.87606),
+ '77'
+ ),
+ TomTom::Matrix::Point.new(
+ Geokit::LatLng.new(52.50867, 13.42879),
+ '88'
+ )
+ ])
+ end
+ end
+
+ describe "#points_as_params" do
+ it "transforms a set of LatLng points into a hash for use by TomTom Matrix" do
+ points = [
+ TomTom::Matrix::Point.new(
+ Geokit::LatLng.new(48.85086, 2.36143),
+ '44'
+ ),
+ TomTom::Matrix::Point.new(
+ Geokit::LatLng.new(47.91231, 1.87606),
+ '77'
+ ),
+ TomTom::Matrix::Point.new(
+ Geokit::LatLng.new(52.50867, 13.42879),
+ '88'
+ )
+ ]
+
+ expect(
+ matrix.points_as_params(points)
+ ).to eq([
+ {
+ point: {
+ latitude: 48.85086,
+ longitude: 2.36143
+ },
+ },
+ {
+ point: {
+ latitude: 47.91231,
+ longitude: 1.87606
+ },
+ },
+ {
+ point: {
+ latitude: 52.50867,
+ longitude: 13.42879
+ },
+ }
+ ])
+ end
+ end
+
+ describe "#build_request_body" do
+ it "serializes BigDecimal coordinates to floats" do
+ points = [
+ {
+ point: {
+ latitude: 48.85086.to_d,
+ longitude: 2.36143.to_d
+ },
+ },
+ {
+ point: {
+ latitude: 47.91231.to_d,
+ longitude: 1.87606.to_d
+ },
+ },
+ {
+ point: {
+ latitude: 52.50867.to_d,
+ longitude: 13.42879.to_d
+ },
+ }
+ ]
+
+ expect(
+ matrix.build_request_body(points)
+ ).to eq(<<-JSON.delete(" \n"))
+ {
+ "origins": [
+ {
+ "point": {
+ "latitude": 48.85086,
+ "longitude": 2.36143
+ }
+ },
+ {
+ "point": {
+ "latitude": 47.91231,
+ "longitude": 1.87606
+ }
+ },
+ {
+ "point": {
+ "latitude": 52.50867,
+ "longitude": 13.42879
+ }
+ }
+ ],
+ "destinations": [
+ {
+ "point": {
+ "latitude": 48.85086,
+ "longitude": 2.36143
+ }
+ },
+ {
+ "point": {
+ "latitude": 47.91231,
+ "longitude": 1.87606
+ }
+ },
+ {
+ "point": {
+ "latitude": 52.50867,
+ "longitude": 13.42879
+ }
+ }
+ ]
+ }
+ JSON
+ end
+ end
+
+ describe "#extract_costs_to_way_costs!" do
+ it "puts distance & time costs in way_costs" do
+ way_costs = [
+ WayCost.new(
+ departure: Geokit::LatLng.new(48.85086, 2.36143),
+ arrival: Geokit::LatLng.new(47.91231, 1.87606),
+ id: '55-99'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(47.91231, 1.87606),
+ arrival: Geokit::LatLng.new(52.50867, 13.42879),
+ id: '99-22'
+ )
+ ]
+
+ expected_way_costs = [
+ WayCost.new(
+ departure: Geokit::LatLng.new(48.85086, 2.36143),
+ arrival: Geokit::LatLng.new(47.91231, 1.87606),
+ distance: 117947,
+ time: 8356,
+ id: '55-99'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(48.85086, 2.36143),
+ arrival: Geokit::LatLng.new(52.50867, 13.42879),
+ distance: 999088,
+ time: 62653,
+ id: '55-22'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(47.91231, 1.87606),
+ arrival: Geokit::LatLng.new(48.85086, 2.36143),
+ distance: 117231,
+ time: 9729,
+ id: '99-55'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(47.91231, 1.87606),
+ arrival: Geokit::LatLng.new(52.50867, 13.42879),
+ distance: 1114635,
+ time: 72079,
+ id: '99-22'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(52.50867, 13.42879),
+ arrival: Geokit::LatLng.new(48.85086, 2.36143),
+ distance: 997232,
+ time: 63245,
+ id: '22-55'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(52.50867, 13.42879),
+ arrival: Geokit::LatLng.new(47.91231, 1.87606),
+ distance: 1113108,
+ time: 68485,
+ id: '22-99'
+ ),
+ WayCost.new(
+ departure: Geokit::LatLng.new(52.50867, 13.42879),
+ arrival: Geokit::LatLng.new(52.50867, 13.42879),
+ distance: 344,
+ time: 109,
+ id: '22-22'
+ )
+ ]
+
+ matrix_response = JSON.parse(read_fixture('tom_tom_matrix.json'))
+
+ points = matrix.points_from_way_costs(way_costs)
+
+ expect(
+ matrix.extract_costs_to_way_costs!(way_costs, points, matrix_response)
+ ).to match_array(expected_way_costs)
+ end
+ end
+end
diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb
index cc483a118..5c5a6bde1 100644
--- a/spec/models/api/v1/api_key_spec.rb
+++ b/spec/models/api/v1/api_key_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Api::V1::ApiKey, type: :model do
subject { create(:api_key) }
it { should validate_presence_of :organisation }
- it { is_expected.to be_versioned }
+
it 'should have a valid factory' do
expect(build(:api_key)).to be_valid
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 09ac0e416..e57eee3b2 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Calendar, :type => :model do
it { is_expected.to validate_presence_of(:organisation) }
it { is_expected.to validate_presence_of(:name) }
- it { is_expected.to be_versioned }
+
describe '#to_time_table' do
let(:calendar) { create(:calendar, int_day_types: Calendar::MONDAY | Calendar::SUNDAY, date_ranges: [Date.today...(Date.today + 1.month)]) }
diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb
index ced99eb1d..448c22d33 100644
--- a/spec/models/chouette/access_link_spec.rb
+++ b/spec/models/chouette/access_link_spec.rb
@@ -4,7 +4,7 @@ describe Chouette::AccessLink, :type => :model do
subject { create(:access_link) }
it { is_expected.to validate_uniqueness_of :objectid }
- it { is_expected.to be_versioned }
+
describe '#get_objectid' do
subject { super().get_objectid }
diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb
index 2184c6ec2..9c637cf41 100644
--- a/spec/models/chouette/access_point_spec.rb
+++ b/spec/models/chouette/access_point_spec.rb
@@ -12,7 +12,7 @@ describe Chouette::AccessPoint, :type => :model do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_numericality_of :latitude }
it { is_expected.to validate_numericality_of :longitude }
- it { is_expected.to be_versioned }
+
describe ".latitude" do
it "should accept -90 value" do
diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb
index 34b19eeda..677c60dd9 100644
--- a/spec/models/chouette/company_spec.rb
+++ b/spec/models/chouette/company_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Chouette::Company, :type => :model do
subject { create(:company) }
it { should validate_presence_of :name }
- it { is_expected.to be_versioned }
+
describe "#nullables empty" do
it "should set null empty nullable attributes" do
diff --git a/spec/models/chouette/connection_link_spec.rb b/spec/models/chouette/connection_link_spec.rb
index 4ab67d007..4486e348c 100644
--- a/spec/models/chouette/connection_link_spec.rb
+++ b/spec/models/chouette/connection_link_spec.rb
@@ -8,7 +8,7 @@ describe Chouette::ConnectionLink, :type => :model do
subject { create(:connection_link) }
it { is_expected.to validate_uniqueness_of :objectid }
- it { is_expected.to be_versioned }
+
describe '#get_objectid' do
subject { super().get_objectid }
diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb
index d43d75374..8b2df69e5 100644
--- a/spec/models/chouette/group_of_line_spec.rb
+++ b/spec/models/chouette/group_of_line_spec.rb
@@ -4,7 +4,7 @@ describe Chouette::GroupOfLine, :type => :model do
subject { create(:group_of_line) }
it { should validate_presence_of :name }
- it { is_expected.to be_versioned }
+
describe "#stop_areas" do
let!(:line){create(:line, :group_of_lines => [subject])}
diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb
index dac45d6b5..078e3c1f1 100644
--- a/spec/models/chouette/journey_pattern_spec.rb
+++ b/spec/models/chouette/journey_pattern_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Chouette::JourneyPattern, :type => :model do
- it { is_expected.to be_versioned }
+
subject { create(:journey_pattern) }
describe 'checksum' do
diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb
index 056d5da9e..cd7cdcb09 100644
--- a/spec/models/chouette/line_spec.rb
+++ b/spec/models/chouette/line_spec.rb
@@ -7,7 +7,7 @@ describe Chouette::Line, :type => :model do
# it { is_expected.to validate_presence_of :network }
# it { is_expected.to validate_presence_of :company }
it { should validate_presence_of :name }
- it { is_expected.to be_versioned }
+
describe '#display_name' do
it 'should display local_id, number, name and company name' do
diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb
index 78a4150df..11ad7cacb 100644
--- a/spec/models/chouette/network_spec.rb
+++ b/spec/models/chouette/network_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Chouette::Network, :type => :model do
subject { create(:network) }
it { should validate_presence_of :name }
- it { is_expected.to be_versioned }
+
describe "#stop_areas" do
let!(:line){create(:line, :network => subject)}
diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb
index d24ad6348..3d4a87791 100644
--- a/spec/models/chouette/route/route_base_spec.rb
+++ b/spec/models/chouette/route/route_base_spec.rb
@@ -15,8 +15,7 @@ RSpec.describe Chouette::Route, :type => :model do
#it { is_expected.to validate_presence_of :direction_code }
it { is_expected.to validate_inclusion_of(:direction).in_array(%i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)) }
it { is_expected.to validate_inclusion_of(:wayback).in_array(%i(outbound inbound)) }
- it { is_expected.to be_versioned }
-
+
context "reordering methods" do
let(:bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}}
let(:ident){subject.stop_points.map(&:id)}
diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb
index 8b3a948a2..47233b04e 100644
--- a/spec/models/chouette/route/route_duplication_spec.rb
+++ b/spec/models/chouette/route/route_duplication_spec.rb
@@ -8,9 +8,6 @@ RSpec.describe Chouette::Route do
route.duplicate
expect( values_for_create(Chouette::Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) )
end
- it 'and others cannot' do
- expect{ route.duplicate name: 'YAN', line_id: 42 }.to raise_error(ArgumentError)
- end
it 'same associated stop_areeas' do
expect( route.duplicate.stop_areas.pluck(:id) ).to eq(route.stop_areas.pluck(:id))
end
diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb
index bda6bb04a..321b41b7b 100644
--- a/spec/models/chouette/routing_constraint_zone_spec.rb
+++ b/spec/models/chouette/routing_constraint_zone_spec.rb
@@ -8,7 +8,7 @@ describe Chouette::RoutingConstraintZone, type: :model do
it { is_expected.to validate_presence_of :route_id }
# shoulda matcher to validate length of array ?
xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) }
- it { is_expected.to be_versioned }
+
describe 'checksum' do
it_behaves_like 'checksum support'
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index e35300caf..185820388 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -13,7 +13,7 @@ describe Chouette::StopArea, :type => :model do
it { should validate_presence_of :kind }
it { should validate_numericality_of :latitude }
it { should validate_numericality_of :longitude }
- it { is_expected.to be_versioned }
+
describe "#area_type" do
it "should validate the value is correct regarding to the kind" do
diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb
index 6b9e7727f..ba3799619 100644
--- a/spec/models/chouette/stop_point_spec.rb
+++ b/spec/models/chouette/stop_point_spec.rb
@@ -4,7 +4,7 @@ describe Chouette::StopPoint, :type => :model do
it { is_expected.to validate_uniqueness_of :objectid }
it { is_expected.to validate_presence_of :stop_area }
- it { is_expected.to be_versioned }
+
describe '#objectid' do
subject { super().get_objectid }
diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb
index bb88877b9..a3354facb 100644
--- a/spec/models/chouette/time_table_spec.rb
+++ b/spec/models/chouette/time_table_spec.rb
@@ -6,7 +6,7 @@ describe Chouette::TimeTable, :type => :model do
it { is_expected.to validate_presence_of :comment }
it { is_expected.to validate_uniqueness_of :objectid }
- it { is_expected.to be_versioned }
+
def create_time_table_periode time_table, start_date, end_date
create(:time_table_period, time_table: time_table, :period_start => start_date, :period_end => end_date)
diff --git a/spec/models/chouette/timeband_spec.rb b/spec/models/chouette/timeband_spec.rb
index b960c203f..fa7c8f06e 100644
--- a/spec/models/chouette/timeband_spec.rb
+++ b/spec/models/chouette/timeband_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Chouette::Timeband, :type => :model do
- it { is_expected.to be_versioned }
+
describe '#create' do
context 'when valid' do
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index c69655bd4..6d44eeb2f 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Chouette::VehicleJourney, :type => :model do
subject { create(:vehicle_journey) }
- it { is_expected.to be_versioned }
+
it { should have_and_belong_to_many(:purchase_windows) }
it "must be valid with an at-stop day offset of 1" do
@@ -420,6 +420,7 @@ describe Chouette::VehicleJourney, :type => :model do
state['published_journey_name'] = 'edited_name'
state['published_journey_identifier'] = 'edited_identifier'
state['custom_fields'] = {energy: {value: 99}}
+ create :custom_field, field_type: :integer, code: :energy, name: :energy
Chouette::VehicleJourney.state_update(route, collection)
expect(state['errors']).to be_nil
@@ -867,7 +868,6 @@ describe Chouette::VehicleJourney, :type => :model do
let!( :footnote_first) {create( :footnote, :code => "1", :label => "dummy 1", :line => route.line)}
let!( :footnote_second) {create( :footnote, :code => "2", :label => "dummy 2", :line => route.line)}
-
it "should update vehicle's footnotes" do
expect(Chouette::VehicleJourney.find(subject.id).footnotes).to be_empty
subject.footnote_ids = [ footnote_first.id ]
@@ -876,4 +876,54 @@ describe Chouette::VehicleJourney, :type => :model do
end
end
end
+
+ describe "#fill_passing_time_at_borders" do
+ before do
+ start = create :stop_area
+ border = create :stop_area, kind: :non_commercial, area_type: :border
+ border_2 = create :stop_area, kind: :non_commercial, area_type: :border
+ middle = create :stop_area
+ border_3 = create :stop_area, kind: :non_commercial, area_type: :border
+ border_4 = create :stop_area, kind: :non_commercial, area_type: :border
+ _end = create :stop_area
+ journey_pattern = create :journey_pattern
+ journey_pattern.stop_points.destroy_all
+ journey_pattern.stop_points << start_point = create(:stop_point, stop_area: start, position: 0)
+ journey_pattern.stop_points << border_point = create(:stop_point, stop_area: border, position: 1)
+ journey_pattern.stop_points << border_point_2 = create(:stop_point, stop_area: border_2, position: 2)
+ journey_pattern.stop_points << middle_point = create(:stop_point, stop_area: middle, position: 3)
+ journey_pattern.stop_points << border_point_3 = create(:stop_point, stop_area: border_3, position: 4)
+ journey_pattern.stop_points << border_point_4 = create(:stop_point, stop_area: border_4, position: 5)
+ journey_pattern.stop_points << end_point = create(:stop_point, stop_area: _end, position: 6)
+ journey_pattern.update_attribute :costs, {
+ "#{start_point.stop_area_id}-#{border_point.stop_area_id}" => {distance: 50},
+ "#{border_point.stop_area_id}-#{border_point_2.stop_area_id}" => {distance: 0},
+ "#{border_point_2.stop_area_id}-#{middle_point.stop_area_id}" => {distance: 100},
+ "#{middle_point.stop_area_id}-#{border_point_3.stop_area_id}" => {distance: 100},
+ "#{border_point_3.stop_area_id}-#{border_point_4.stop_area_id}" => {distance: 0},
+ "#{border_point_4.stop_area_id}-#{end_point.stop_area_id}" => {distance: 100}
+ }
+ @journey = create :vehicle_journey, journey_pattern: journey_pattern
+ @journey.vehicle_journey_at_stops.destroy_all
+ @start = create :vehicle_journey_at_stop, stop_point: start_point, vehicle_journey: @journey
+ @target = create :vehicle_journey_at_stop, stop_point: border_point, vehicle_journey: @journey, arrival_time: nil, departure_time: nil
+ @target_2 = create :vehicle_journey_at_stop, stop_point: border_point_2, vehicle_journey: @journey, arrival_time: nil, departure_time: nil
+ @middle = create :vehicle_journey_at_stop, stop_point: middle_point, vehicle_journey: @journey, arrival_time: @start.arrival_time + 4.hours, departure_time: @start.departure_time + 4.hours
+ @target_3 = create :vehicle_journey_at_stop, stop_point: border_point_3, vehicle_journey: @journey, arrival_time: nil, departure_time: nil
+ @target_4 = create :vehicle_journey_at_stop, stop_point: border_point_4, vehicle_journey: @journey, arrival_time: nil, departure_time: nil
+ @end = create :vehicle_journey_at_stop, stop_point: end_point, vehicle_journey: @journey, arrival_time: @middle.arrival_time + 4.hours, departure_time: @middle.departure_time + 4.hours
+ end
+
+ it "should compute passing time" do
+ @journey.reload.fill_passing_time_at_borders
+ expect(@target.reload.arrival_time.to_i).to eq (@start.reload.departure_time + 1.0/3 * (@middle.reload.arrival_time - @start.departure_time)).to_i
+ expect(@target_2.reload.arrival_time).to eq @target.arrival_time
+ expect(@target.departure_time).to eq @target.arrival_time
+ expect(@target_2.departure_time).to eq @target.arrival_time
+ expect(@target_3.reload.arrival_time.to_i).to eq (@middle.reload.departure_time + 0.5 * (@end.reload.arrival_time - @middle.departure_time)).to_i
+ expect(@target_4.reload.arrival_time).to eq @target_3.arrival_time
+ expect(@target_3.departure_time).to eq @target_3.arrival_time
+ expect(@target_4.departure_time).to eq @target_3.arrival_time
+ end
+ end
end
diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb
index 61421287a..b6f854829 100644
--- a/spec/models/compliance_check_set_spec.rb
+++ b/spec/models/compliance_check_set_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe ComplianceCheckSet, type: :model do
it { should have_many :compliance_checks }
it { should have_many :compliance_check_blocks }
- it { is_expected.to be_versioned }
+
describe "#update_status" do
it "updates :status to successful when all resources are OK" do
diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb
index 4abe0ed9c..089d78434 100644
--- a/spec/models/compliance_control_block_spec.rb
+++ b/spec/models/compliance_control_block_spec.rb
@@ -17,4 +17,16 @@ RSpec.describe ComplianceControlBlock, type: :model do
it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs
Shuttle suburban regioalRail interregion4lRail })
.for(:transport_submode) }
+
+ context "transport mode & submode uniqueness" do
+ let(:cc_block) {create :compliance_control_block, transport_mode: 'bus', transport_submode: 'nightBus'}
+ let(:cc_set1) { cc_block.compliance_control_set }
+ let(:cc_set2) { create :compliance_control_set }
+
+ it "sould be unique in a compliance control set" do
+ expect( ComplianceControlBlock.new(transport_mode: 'bus', transport_submode: 'nightBus', compliance_control_set: cc_set1) ).not_to be_valid
+ expect( ComplianceControlBlock.new(transport_mode: 'bus', transport_submode: 'nightBus', compliance_control_set: cc_set2) ).to be_valid
+ end
+
+end
end
diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb
index c157dcaf3..a66e7f030 100644
--- a/spec/models/compliance_control_set_spec.rb
+++ b/spec/models/compliance_control_set_spec.rb
@@ -10,5 +10,5 @@ RSpec.describe ComplianceControlSet, type: :model do
it { should have_many(:compliance_control_blocks).dependent(:destroy) }
it { should validate_presence_of :name }
- it { is_expected.to be_versioned }
+
end
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index b92bcfbdb..1dfe6d33c 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -1,6 +1,7 @@
require 'rails_helper'
RSpec.describe CustomField, type: :model do
+
let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
context "validates" do
@@ -35,11 +36,43 @@ RSpec.describe CustomField, type: :model do
end
context "custom field_values for a resource" do
+ before do
+ create :custom_field, field_type: :integer, code: :energy, name: :energy
+ end
+
it { expect(vj.custom_field_value("energy")).to eq(99) }
end
+ context "with a 'list' field_type" do
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'list', options: {list_values: %w(foo bar baz)})] }
+ let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "1"} }
+ it "should cast the value" do
+ p vj.custom_fields
+ expect(vj.custom_fields[:energy].value).to eq 1
+ expect(vj.custom_fields[:energy].display_value).to eq "bar"
+ end
+
+ it "should validate the value" do
+ {
+ "1" => true,
+ 1 => true,
+ "azerty" => false,
+ "10" => false,
+ 10 => false
+ }.each do |val, valid|
+ vj = build :vehicle_journey, custom_field_values: {energy: val}
+ if valid
+ expect(vj.validate).to be_truthy
+ else
+ expect(vj.validate).to be_falsy
+ expect(vj.errors.messages[:"custom_fields.energy"]).to be_present
+ end
+ end
+ end
+ end
+
context "with an 'integer' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, options: {field_type: 'integer'})] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'integer')] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "99"} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq 99
@@ -47,6 +80,7 @@ RSpec.describe CustomField, type: :model do
it "should validate the value" do
{
+ 99 => true,
"99" => true,
"azerty" => false,
"91a" => false,
@@ -64,10 +98,39 @@ RSpec.describe CustomField, type: :model do
end
context "with a 'string' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, options: {field_type: 'string'})] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'string')] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq '99'
end
end
+
+ context "with a 'attachment' field_type" do
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment')] }
+ let( :vj ){ create :vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'users.json'))} }
+ it "should cast the value" do
+ expect(vj.custom_fields[:energy].value.class).to be CustomFieldAttachmentUploader
+ path = vj.custom_fields[:energy].value.path
+ expect(File.exists?(path)).to be_truthy
+ expect(vj).to receive(:remove_custom_field_energy!).and_call_original
+ vj.destroy
+ vj.run_callbacks(:commit)
+ expect(File.exists?(path)).to be_falsy
+ end
+
+ it "should display a link" do
+ val = vj.custom_fields[:energy].value
+ out = vj.custom_fields[:energy].display_value
+ expect(out).to match(val.url)
+ expect(out).to match(/\<a.*\>/)
+ end
+
+ context "with a whitelist" do
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', options: {extension_whitelist: %w(zip)})] }
+ it "should validate extension" do
+ expect(build(:vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'users.json'))})).to_not be_valid
+ expect(build(:vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'nozip.zip'))})).to be_valid
+ end
+ end
+ end
end
diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb
index 291ed974a..88a12b2bb 100644
--- a/spec/models/referential_metadata_spec.rb
+++ b/spec/models/referential_metadata_spec.rb
@@ -12,14 +12,19 @@ RSpec.describe ReferentialMetadata, :type => :model do
describe ".new_from" do
let(:referential_metadata) { create :referential_metadata, referential_source: create(:referential) }
- let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, []) }
+ let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, nil) }
+ before do
+ referential_metadata.line_ids.each do |id|
+ Chouette::Line.find(id).update_attribute :line_referential_id, referential_metadata.referential.line_referential_id
+ end
+ end
it "should not have an associated referential" do
expect(new_referential_metadata).to be_a_new(ReferentialMetadata)
end
- xit "should have the same lines" do
- expect(new_referential_metadata.lines).to eq(referential_metadata.lines)
+ it "should have the same lines" do
+ expect(new_referential_metadata.line_ids.sort).to eq(referential_metadata.line_ids.sort)
end
it "should have the same periods" do
@@ -34,6 +39,14 @@ RSpec.describe ReferentialMetadata, :type => :model do
expect(new_referential_metadata.referential_source).to eq(referential_metadata.referential)
end
+ context "with a functional scope" do
+ let(:organisation){ create :organisation, sso_attributes: {"functional_scope" => [referential_metadata.referential.lines.first.objectid]} }
+ let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, organisation) }
+
+ it "should scope the lines" do
+ expect(new_referential_metadata.line_ids).to eq [referential_metadata.referential.lines.first.id]
+ end
+ end
end
describe "Period" do
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index 1d9b3d78a..ca2caf57f 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -55,7 +55,7 @@ describe Referential, :type => :model do
context "Cloning referential" do
let(:clone) do
- Referential.new_from(ref, [])
+ Referential.new_from(ref, nil)
end
let!(:workbench){ create :workbench }
diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb
new file mode 100644
index 000000000..b407cd866
--- /dev/null
+++ b/spec/models/route_spec.rb
@@ -0,0 +1,68 @@
+require 'spec_helper'
+
+RSpec.describe Chouette::Route, :type => :model do
+ subject(:route){ create :route }
+ context "metadatas" do
+ it "should be empty at first" do
+ expect(Chouette::Route.has_metadata?).to be_truthy
+ expect(route.has_metadata?).to be_truthy
+ expect(route.metadata.creator_username).to be_nil
+ expect(route.metadata.modifier_username).to be_nil
+ end
+
+ context "once set" do
+ it "should set the correct values" do
+ Timecop.freeze(Time.now) do
+ route.metadata.creator_username = "john.doe"
+ route.save!
+ id = route.id
+ route = Chouette::Route.find id
+ expect(route.metadata.creator_username).to eq "john.doe"
+ expect(route.metadata.creator_username_updated_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N')
+ end
+ end
+ end
+
+ describe "#merge_metadata_from" do
+ let(:source){ create :route }
+ let(:metadata){ target.merge_metadata_from(source).metadata }
+ let(:target){ create :route }
+ before do
+ target.metadata.creator_username = "john"
+ target.metadata.modifier_username = "john"
+ end
+ context "when the source has no metadata" do
+ it "should do nothing" do
+ expect(metadata.creator_username).to eq "john"
+ expect(metadata.modifier_username).to eq "john"
+ end
+ end
+
+ context "when the source has older metadata" do
+ before do
+ source.metadata.creator_username = "jane"
+ source.metadata.modifier_username = "jane"
+ source.metadata.creator_username_updated_at = 1.month.ago
+ source.metadata.modifier_username_updated_at = 1.month.ago
+ end
+ it "should do nothing" do
+ expect(metadata.creator_username).to eq "john"
+ expect(metadata.modifier_username).to eq "john"
+ end
+ end
+
+ context "when the source has new metadata" do
+ before do
+ source.metadata.creator_username = "jane"
+ source.metadata.modifier_username = "jane"
+ target.metadata.creator_username_updated_at = 1.month.ago
+ target.metadata.modifier_username_updated_at = 1.month.ago
+ end
+ it "should update metadata" do
+ expect(metadata.creator_username).to eq "jane"
+ expect(metadata.modifier_username).to eq "jane"
+ end
+ end
+ end
+ end
+end
diff --git a/spec/services/route_way_cost_calculator_spec.rb b/spec/services/route_way_cost_calculator_spec.rb
index d5358fcf6..79b81e34d 100644
--- a/spec/services/route_way_cost_calculator_spec.rb
+++ b/spec/services/route_way_cost_calculator_spec.rb
@@ -7,18 +7,20 @@ RSpec.describe RouteWayCostCalculator do
# things in the request or response. This is just to fake the request so
# we don't actually call their API in tests. The test doesn't test
# anything given in the response.
- stub_request(:post, "https://api.tomtom.com/routing/1/batch/json?key")
+ stub_request(
+ :post,
+ "https://api.tomtom.com/routing/1/matrix/json?key&routeType=shortest&travelMode=bus"
+ )
.with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type'=>'application/json',
'User-Agent'=>'Faraday v0.9.2'
- }
- )
+ })
.to_return(
status: 200,
- body: "{\"formatVersion\":\"0.0.1\",\"batchItems\":[{\"statusCode\":200,\"response\":{\"routes\":[{\"summary\":{\"lengthInMeters\":117947,\"travelTimeInSeconds\":7969,\"trafficDelayInSeconds\":0,\"departureTime\":\"2018-03-12T12:32:26+01:00\",\"arrivalTime\":\"2018-03-12T14:45:14+01:00\"}}]}}]}",
+ body: "{\"formatVersion\":\"0.0.1\",\"matrix\":[[{\"statusCode\":200,\"response\":{\"routeSummary\":{\"lengthInMeters\":0,\"travelTimeInSeconds\":0,\"trafficDelayInSeconds\":0,\"departureTime\":\"2018-03-23T11:20:17+01:00\",\"arrivalTime\":\"2018-03-23T11:20:17+01:00\"}}}]]}",
headers: {}
)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index cde252236..947efd602 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -34,7 +34,6 @@ require 'webmock/rspec'
require 'simplecov'
require 'sidekiq/testing'
Sidekiq::Testing.fake!
-require 'paper_trail/frameworks/rspec'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index 9acdce73a..b50844ae4 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -8,6 +8,10 @@ module ReferentialHelper
Organisation.find_by!(code: "first")
end
+ def first_workgroup
+ Workgroup.find_by_name('IDFM')
+ end
+
def self.included(base)
base.class_eval do
extend ClassMethods
@@ -53,10 +57,18 @@ RSpec.configure do |config|
referential.add_member organisation, owner: true
end
+ workgroup = FactoryGirl.create(
+ :workgroup,
+ name: "IDFM",
+ line_referential: line_referential,
+ stop_area_referential: stop_area_referential
+ )
+
workbench = FactoryGirl.create(
:workbench,
name: "Gestion de l'offre",
organisation: organisation,
+ workgroup: workgroup,
line_referential: line_referential,
stop_area_referential: stop_area_referential
)
diff --git a/spec/views/companies/edit.html.erb_spec.rb b/spec/views/companies/edit.html.erb_spec.rb
index 8aaf705ab..c72d84c0b 100644
--- a/spec/views/companies/edit.html.erb_spec.rb
+++ b/spec/views/companies/edit.html.erb_spec.rb
@@ -5,7 +5,10 @@ describe "/companies/edit", :type => :view do
let!(:company) { assign(:company, create(:company)) }
let!(:companies) { Array.new(2) { create(:company) } }
let!(:line_referential) { assign :line_referential, company.line_referential }
-
+ before do
+ allow(view).to receive(:resource){ company }
+ allow(view).to receive(:current_referential){ first_referential }
+ end
describe "form" do
it "should render input for name" do
render
diff --git a/spec/views/companies/new.html.erb_spec.rb b/spec/views/companies/new.html.erb_spec.rb
index ebb8c03c5..6c2163677 100644
--- a/spec/views/companies/new.html.erb_spec.rb
+++ b/spec/views/companies/new.html.erb_spec.rb
@@ -4,7 +4,10 @@ describe "/companies/new", :type => :view do
let!(:company) { assign(:company, build(:company)) }
let!(:line_referential) { assign :line_referential, company.line_referential }
-
+ before do
+ allow(view).to receive(:resource){company}
+ allow(view).to receive(:current_referential){ first_referential }
+ end
describe "form" do
it "should render input for name" do
diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb
index bfbb0bb55..1bdb42817 100644
--- a/spec/views/stop_areas/edit.html.erb_spec.rb
+++ b/spec/views/stop_areas/edit.html.erb_spec.rb
@@ -8,6 +8,7 @@ describe "/stop_areas/edit", :type => :view do
before do
allow(view).to receive(:has_feature?)
+ allow(view).to receive(:resource){ stop_area }
end
describe "form" do
diff --git a/spec/views/stop_areas/new.html.erb_spec.rb b/spec/views/stop_areas/new.html.erb_spec.rb
index 23f7387fa..eced129e4 100644
--- a/spec/views/stop_areas/new.html.erb_spec.rb
+++ b/spec/views/stop_areas/new.html.erb_spec.rb
@@ -7,6 +7,7 @@ describe "/stop_areas/new", :type => :view do
before do
allow(view).to receive(:has_feature?)
+ allow(view).to receive(:resource){ stop_area }
end
describe "form" do