From ad51ee2db119c4587f7f1b73056cb91bd0969222 Mon Sep 17 00:00:00 2001 From: renaud Date: Tue, 5 Dec 2023 14:18:02 +0100 Subject: [PATCH] CHOUETTE-3258 use ara-ruby gem --- Gemfile | 2 +- Gemfile.lock | 10 ++++--- app/models/export/ara.rb | 13 +++++---- spec/models/export/ara_spec.rb | 52 ++++++++++++++++++++++++++-------- 4 files changed, 54 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 1d95b241a2..9b52064069 100644 --- a/Gemfile +++ b/Gemfile @@ -135,7 +135,7 @@ gem 'redis-actionpack', '>= 5.3.0' gem 'gtfs', en_route: 'gtfs' gem 'netex', en_route: 'netex' gem 'rgeo-shapefile' -gem 'ara-file', '>= 0.1.2', en_route: 'ara-file' +gem 'ara', '>= 1.0.0', en_route: 'ara-ruby' gem 'neptune', en_route: 'neptune' # Monitoring diff --git a/Gemfile.lock b/Gemfile.lock index 7393bfb709..fe52cdcfe8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,10 @@ GIT - remote: https://bitbucket.org/enroute-mobi/ara-file.git - revision: 4e96971bfb52ea3208d3231ecc72dd0d070f59d0 + remote: https://bitbucket.org/enroute-mobi/ara-ruby.git + revision: ac8cc50642bfad5e23f55b04020d87d5b3a5d808 specs: - ara-file (0.1.2) + ara (1.0.0) + faraday + json GIT remote: https://bitbucket.org/enroute-mobi/cuckoo.git @@ -868,7 +870,7 @@ DEPENDENCIES activerecord-postgis-adapter (~> 5.2.3) acts_as_list acts_as_tree - ara-file (>= 0.1.2)! + ara (>= 1.0.0)! awesome_print bcrypt_pbkdf better_errors diff --git a/app/models/export/ara.rb b/app/models/export/ara.rb index d2db75e158..c098118c05 100644 --- a/app/models/export/ara.rb +++ b/app/models/export/ara.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # Export a dataset into a Ara CSV file +require 'ara/file' class Export::Ara < Export::Base include LocalExportSupport @@ -29,7 +30,7 @@ def export_file end def target - @target ||= ::Ara::File.new export_file + @target ||= ::Ara::File::Target.new export_file end attr_writer :target @@ -354,7 +355,7 @@ def referent_uuid end def ara_model - Ara::StopArea.new ara_attributes + Ara::File::StopArea.new ara_attributes end # TODO: To be shared @@ -430,7 +431,7 @@ def ara_attributes end def ara_model - Ara::StopVisit.new ara_attributes + Ara::File::StopVisit.new ara_attributes end def stop_area_id @@ -545,7 +546,7 @@ def ara_attributes end def ara_model - Ara::Line.new ara_attributes + Ara::File::Line.new ara_attributes end # TODO: To be shared @@ -594,7 +595,7 @@ def ara_attributes end def ara_model - Ara::Operator.new ara_attributes + Ara::File::Operator.new ara_attributes end # TODO: To be shared @@ -648,7 +649,7 @@ def ara_attributes end def ara_model - Ara::VehicleJourney.new ara_attributes + Ara::File::VehicleJourney.new ara_attributes end # TODO: To be shared diff --git a/spec/models/export/ara_spec.rb b/spec/models/export/ara_spec.rb index 0e14833df0..7869708e83 100644 --- a/spec/models/export/ara_spec.rb +++ b/spec/models/export/ara_spec.rb @@ -29,9 +29,23 @@ it { is_expected.to be_successful } describe 'file' do - # TODO: Use Ara::File to read the file - subject { export.file.read.split("\n") } - it { is_expected.to have_attributes(size: 48) } + subject(:source) { Ara::File::Source.new(export.file.path) } + describe 'stop_visits count ' do + subject { source.stop_visits.to_a.size } + it { is_expected.to eq(18) } + end + describe 'lines count' do + subject { source.lines.to_a.size } + it { is_expected.to eq(6) } + end + describe 'vehicle_journeys count' do + subject { source.vehicle_journeys.to_a.size } + it { is_expected.to eq(6) } + end + describe 'operators count' do + subject { source.operators.to_a.size } + it { is_expected.to eq(0) } + end end end @@ -54,9 +68,23 @@ it { is_expected.to be_successful } describe 'file' do - # TODO: Use Ara::File to read the file - subject { export.file.read.split("\n") } - it { is_expected.to have_attributes(size: 30) } + subject(:source) { Ara::File::Source.new(export.file.path) } + describe 'stop_visits count ' do + subject { source.stop_visits.to_a.size } + it { is_expected.to eq(0) } + end + describe 'lines count' do + subject { source.lines.to_a.size } + it { is_expected.to eq(6) } + end + describe 'vehicle_journeys count' do + subject { source.vehicle_journeys.to_a.size } + it { is_expected.to eq(6) } + end + describe 'operators count' do + subject { source.operators.to_a.size } + it { is_expected.to eq(0) } + end end end end @@ -184,7 +212,7 @@ subject do part.export! target end - it { is_expected.to match_array([an_instance_of(Ara::StopArea)] * 2) } + it { is_expected.to match_array([an_instance_of(Ara::File::StopArea)] * 2) } context "when one of the Stop Area has a registration number 'dummy'" do before { stop_area.update registration_number: 'dummy' } @@ -241,7 +269,7 @@ subject do part.export! target end - it { is_expected.to match_array([an_instance_of(Ara::Line)] * 2) } + it { is_expected.to match_array([an_instance_of(Ara::File::Line)] * 2) } it 'contains Line having a number' do expect(subject.first).to respond_to(:number) @@ -323,7 +351,7 @@ part.export! target end - it { is_expected.to match_array([an_instance_of(Ara::Operator)] * 2) } + it { is_expected.to match_array([an_instance_of(Ara::File::Operator)] * 2) } context "when one of the Company has a registration number 'dummy'" do before { company.update registration_number: 'dummy' } @@ -377,7 +405,7 @@ end describe 'the Ara File target' do - it { is_expected.to match_array([an_instance_of(Ara::VehicleJourney)]) } + it { is_expected.to match_array([an_instance_of(Ara::File::VehicleJourney)]) } it 'contains a Vehicle journey having a direction_type' do expect(subject.first).to respond_to(:direction_type) @@ -397,7 +425,7 @@ end describe 'the Ara File target' do - it { is_expected.to match_array([an_instance_of(Ara::VehicleJourney)] * 2) } + it { is_expected.to match_array([an_instance_of(Ara::File::VehicleJourney)] * 2) } context "when one of the Vehicle Journey has a code 'test': 'dummy" do before { vehicle_journey.codes.create!(code_space: code_space, value: 'dummy') } @@ -581,7 +609,7 @@ let(:at_stops_count) { vehicle_journey.vehicle_journey_at_stops.count } - it { is_expected.to match_array([an_instance_of(Ara::StopVisit)] * at_stops_count) } + it { is_expected.to match_array([an_instance_of(Ara::File::StopVisit)] * at_stops_count) } describe Export::Ara::StopVisits::Decorator do context 'with the first stop_visit' do