diff options
| author | Xinhui Xu | 2017-09-12 15:52:49 +0200 |
|---|---|---|
| committer | GitHub | 2017-09-12 15:52:49 +0200 |
| commit | 095dd5151d40d25c9abb015808834b32e575c750 (patch) | |
| tree | 3aacd609bfbd277a5e33e8ee2208a3293f85a3ba /spec/models | |
| parent | e2270acdfcec57a8be2ada201a668d9d610953ab (diff) | |
| parent | 4aa19d931f8585c061dd3da49e31b2ddbbb1bf6b (diff) | |
| download | chouette-core-095dd5151d40d25c9abb015808834b32e575c750.tar.bz2 | |
Merge branch 'master' into compliance_control
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/chouette/access_link_spec.rb | 12 | ||||
| -rw-r--r-- | spec/models/chouette/company_spec.rb | 7 | ||||
| -rw-r--r-- | spec/models/chouette/connection_link_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/footnote_spec.rb | 14 | ||||
| -rw-r--r-- | spec/models/chouette/group_of_line_spec.rb | 6 | ||||
| -rw-r--r-- | spec/models/chouette/network_spec.rb | 7 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_base_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_duplication_spec.rb | 52 | ||||
| -rw-r--r-- | spec/models/chouette/routing_constraint_zone_spec.rb | 19 | ||||
| -rw-r--r-- | spec/models/chouette/stop_point_spec.rb | 21 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_spec.rb | 208 | ||||
| -rw-r--r-- | spec/models/chouette/trident_active_record_spec.rb | 128 | ||||
| -rw-r--r-- | spec/models/concerns/error_format_spec.rb | 12 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 35 | ||||
| -rw-r--r-- | spec/models/referential_metadata_spec.rb | 4 | ||||
| -rw-r--r-- | spec/models/vehicle_journey_export_spec.rb | 34 | ||||
| -rw-r--r-- | spec/models/vehicle_journey_import_spec.rb | 8 | ||||
| -rw-r--r-- | spec/models/vehicle_translation_spec.rb | 1 |
18 files changed, 398 insertions, 174 deletions
diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb index 0e1e91593..5a31b8f0c 100644 --- a/spec/models/chouette/access_link_spec.rb +++ b/spec/models/chouette/access_link_spec.rb @@ -7,7 +7,7 @@ describe Chouette::AccessLink, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end it { is_expected.to validate_presence_of :name } @@ -19,7 +19,7 @@ describe Chouette::AccessLink, :type => :model do def self.legacy_link_types %w{Underground Mixed Overground} end - + legacy_link_types.each do |link_type| context "when link_type is #{link_type}" do access_link_type = Chouette::ConnectionLinkType.new(link_type.underscore) @@ -32,7 +32,7 @@ describe Chouette::AccessLink, :type => :model do end describe "#access_link_type=" do - + it "should change link_type with ConnectionLinkType#name" do subject.access_link_type = "underground" expect(subject.link_type).to eq("Underground") @@ -45,7 +45,7 @@ describe Chouette::AccessLink, :type => :model do def self.legacy_link_orientations %w{AccessPointToStopArea StopAreaToAccessPoint} end - + legacy_link_orientations.each do |link_orientation| context "when link_orientation is #{link_orientation}" do link_orientation_type = Chouette::LinkOrientationType.new(link_orientation.underscore) @@ -59,7 +59,7 @@ describe Chouette::AccessLink, :type => :model do end describe "#link_orientation_type=" do - + it "should change link_orientation with LinkOrientationType#name" do subject.link_orientation_type = "access_point_to_stop_area" expect(subject.link_orientation).to eq("AccessPointToStopArea") @@ -76,7 +76,7 @@ describe Chouette::AccessLink, :type => :model do subject.link_orientation_type = "stop_area_to_access_point" expect(subject.link_key).to eq("S_#{subject.stop_area.id}-A_#{subject.access_point.id}") end - + end end diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb index 3da8b4311..a3101d79c 100644 --- a/spec/models/chouette/company_spec.rb +++ b/spec/models/chouette/company_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe Chouette::Company, :type => :model do - subject { create(:company) } - - it { is_expected.to validate_presence_of :name } - - # it { should validate_presence_of :objectid } - it { is_expected.to validate_uniqueness_of :objectid } + it { should validate_presence_of :name } 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 5921bf581..57eb7d66c 100644 --- a/spec/models/chouette/connection_link_spec.rb +++ b/spec/models/chouette/connection_link_spec.rb @@ -11,7 +11,7 @@ describe Chouette::ConnectionLink, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end it { is_expected.to validate_presence_of :name } diff --git a/spec/models/chouette/footnote_spec.rb b/spec/models/chouette/footnote_spec.rb index 98d751499..fc5e5f306 100644 --- a/spec/models/chouette/footnote_spec.rb +++ b/spec/models/chouette/footnote_spec.rb @@ -2,9 +2,21 @@ require 'spec_helper' describe Chouette::Footnote, type: :model do let(:footnote) { create(:footnote) } - it { should validate_presence_of :line } + describe 'data_source_ref' do + it 'should set default if omitted' do + expect(footnote.data_source_ref).to eq "DATASOURCEREF_EDITION_BOIV" + end + + it 'should not set default if not omitted' do + source = "RANDOM_DATASOURCE" + object = build(:footnote, data_source_ref: source) + object.save + expect(object.data_source_ref).to eq source + end + end + describe 'checksum' do it_behaves_like 'checksum support', :footnote diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb index d49329118..29b4433c5 100644 --- a/spec/models/chouette/group_of_line_spec.rb +++ b/spec/models/chouette/group_of_line_spec.rb @@ -3,11 +3,7 @@ require 'spec_helper' describe Chouette::GroupOfLine, :type => :model do subject { create(:group_of_line) } - - it { is_expected.to validate_presence_of :name } - - # it { should validate_presence_of :objectid } - it { is_expected.to validate_uniqueness_of :objectid } + it { should validate_presence_of :name } describe "#stop_areas" do let!(:line){create(:line, :group_of_lines => [subject])} diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb index c9e510e84..32bacc512 100644 --- a/spec/models/chouette/network_spec.rb +++ b/spec/models/chouette/network_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe Chouette::Network, :type => :model do - subject { create(:network) } - - it { is_expected.to validate_presence_of :name } - - # it { should validate_presence_of :objectid } - it { is_expected.to validate_uniqueness_of :objectid } + it { should validate_presence_of :name } 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 c93b311ff..794da4f1b 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Chouette::Route, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) } diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb new file mode 100644 index 000000000..6645b909f --- /dev/null +++ b/spec/models/chouette/route/route_duplication_spec.rb @@ -0,0 +1,52 @@ +# From Chouette import what we need ™ +Route = Chouette::Route +StopArea = Chouette::StopArea +StopPoint = Chouette::StopPoint + +RSpec.describe Route do + + let!( :route ){ create :route } + + context '#duplicate' do + describe 'properties' do + it 'same attribute values' do + route.duplicate + expect( values_for_create(Route.last, except: %w{objectid}) ).to eq( values_for_create( route, except: %w{objectid} ) ) + 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 + end + + describe 'side_effects' do + it { + expect{ route.duplicate }.to change{Route.count}.by(1) + } + it 'duplicates its stop points' do + expect{ route.duplicate }.to change{StopPoint.count}.by(route.stop_points.count) + end + it 'does bot duplicate the stop areas' do + expect{ route.duplicate }.not_to change{StopArea.count} + end + end + + describe 'is idempotent, concerning' do + let( :first_duplicate ){ route.duplicate } + let( :second_duplicate ){ first_duplicate.reload.duplicate } + + it 'the required attributes' do + expect( values_for_create(first_duplicate, except: %w{objectid}) ).to eq( values_for_create( second_duplicate, except: %w{objectid} ) ) + end + + it 'the stop areas' do + expect( first_duplicate.stop_areas.pluck(:id) ).to eq( route.stop_areas.pluck(:id) ) + expect( second_duplicate.stop_areas.pluck(:id) ).to eq( first_duplicate.stop_areas.pluck(:id) ) + end + + end + end + +end diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index 054cfb9e6..c344642e6 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe Chouette::RoutingConstraintZone, type: :model do subject { create(:routing_constraint_zone) } - let!(:routing_constraint_zone) { create(:routing_constraint_zone) } it { is_expected.to validate_presence_of :name } # shoulda matcher to validate length of array ? @@ -16,38 +15,38 @@ describe Chouette::RoutingConstraintZone, type: :model do describe 'validations' do it 'validates the presence of route_id' do expect { - routing_constraint_zone.update!(route_id: nil) + subject.update!(route_id: nil) }.to raise_error(NoMethodError) end it 'validates the presence of stop_point_ids' do expect { - routing_constraint_zone.update!(stop_point_ids: []) + subject.update!(stop_point_ids: []) }.to raise_error(ActiveRecord::RecordInvalid) end it 'validates that stop points belong to the route' do route = create(:route) expect { - routing_constraint_zone.update!(route_id: route.id) + subject.update!(route_id: route.id) }.to raise_error(ActiveRecord::RecordInvalid) end xit 'validates that not all stop points from the route are selected' do routing_constraint_zone.stop_points = routing_constraint_zone.route.stop_points expect { - routing_constraint_zone.save! + subject.save! }.to raise_error(ActiveRecord::RecordInvalid) end end describe 'deleted stop areas' do it 'does not have them in stop_area_ids' do - stop_point = routing_constraint_zone.route.stop_points.last - routing_constraint_zone.stop_points << stop_point - routing_constraint_zone.save! - routing_constraint_zone.route.stop_points.last.destroy! - expect(routing_constraint_zone.stop_points.map(&:id)).not_to include(stop_point.id) + stop_point = subject.route.stop_points.last + subject.stop_points << stop_point + subject.save! + subject.route.stop_points.last.destroy! + expect(subject.stop_points.map(&:id)).not_to include(stop_point.id) end end diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb index 212c32e1a..329e76a75 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -1,6 +1,7 @@ -require 'spec_helper' +# From Chouette import what we need ™ +StopPoint = Chouette::StopPoint -describe Chouette::StopPoint, :type => :model do +describe StopPoint, :type => :model do let!(:vehicle_journey) { create(:vehicle_journey)} subject { Chouette::Route.find( vehicle_journey.route_id).stop_points.first } @@ -9,7 +10,7 @@ describe Chouette::StopPoint, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end describe "#destroy" do @@ -38,4 +39,18 @@ describe Chouette::StopPoint, :type => :model do expect(jpsp_stop_point_ids(@vehicle.journey_pattern_id)).not_to include(@stop_point.id) end end + + describe '#duplicate' do + let!( :new_route ){ create :route } + + it 'creates a new instance' do + expect{ subject.duplicate(for_route: new_route) }.to change{ StopPoint.count }.by(1) + end + it 'new instance has a new route' do + expect(subject.duplicate(for_route: new_route).route).to eq(new_route) + end + it 'and old stop_area' do + expect(subject.duplicate(for_route: new_route).stop_area).to eq(subject.stop_area) + end + end end diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index c4eaeaaf0..761c39e5b 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -820,13 +820,13 @@ end describe "#intersects" do it "should return day if a date equal day" do - time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1") + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc") time_table.dates << Chouette::TimeTableDate.new( :date => Date.today, :in_out => true) expect(time_table.intersects([Date.today])).to eq([Date.today]) end it "should return [] if a period not include days" do - time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1", :int_day_types => 12) + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) time_table.periods << Chouette::TimeTablePeriod.new( :period_start => Date.new(2013, 05, 27), :period_end => Date.new(2013, 05, 30)) @@ -834,7 +834,7 @@ end end it "should return days if a period include day" do - time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1", :int_day_types => 12) # Day type monday and tuesday + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday time_table.periods << Chouette::TimeTablePeriod.new( :period_start => Date.new(2013, 05, 27), :period_end => Date.new(2013, 05, 30)) @@ -842,6 +842,207 @@ end end end + describe "#include_day?" do + it "should return true if a date equal day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc") + time_table.dates << Chouette::TimeTableDate.new( :date => Date.today, :in_out => true) + expect(time_table.include_day?(Date.today)).to eq(true) + end + + it "should return true if a period include day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2013, 05, 27), + :period_end => Date.new(2013, 05, 29)) + expect(time_table.include_day?( Date.new(2013, 05, 27))).to eq(true) + end + end + + describe "#include_in_dates?" do + it "should return true if a date equal day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc") + time_table.dates << Chouette::TimeTableDate.new( :date => Date.today, :in_out => true) + expect(time_table.include_in_dates?(Date.today)).to eq(true) + end + + it "should return false if a period include day but that is exclued" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday + excluded_date = Date.new(2013, 05, 27) + time_table.dates << Chouette::TimeTableDate.new( :date => excluded_date, :in_out => false) + expect(time_table.include_in_dates?( excluded_date)).to be_falsey + end + end + + describe "#include_in_periods?" do + it "should return true if a period include day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 4) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2012, 1, 1), + :period_end => Date.new(2012, 01, 30)) + expect(time_table.include_in_periods?(Date.new(2012, 1, 2))).to eq(true) + end + + it "should return false if a period include day but that is exclued" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday + excluded_date = Date.new(2013, 05, 27) + time_table.dates << Chouette::TimeTableDate.new( :date => excluded_date, :in_out => false) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2013, 05, 27), + :period_end => Date.new(2013, 05, 29)) + expect(time_table.include_in_periods?( excluded_date)).to be_falsey + end + end + + describe "#include_in_overlap_dates?" do + it "should return true if a day is included in overlap dates" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 4) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2012, 1, 1), + :period_end => Date.new(2012, 01, 30)) + time_table.dates << Chouette::TimeTableDate.new( :date => Date.new(2012, 1, 2), :in_out => true) + expect(time_table.include_in_overlap_dates?(Date.new(2012, 1, 2))).to eq(true) + end + it "should return false if the day is excluded" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 4) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2012, 1, 1), + :period_end => Date.new(2012, 01, 30)) + time_table.dates << Chouette::TimeTableDate.new( :date => Date.new(2012, 1, 2), :in_out => false) + expect(time_table.include_in_overlap_dates?(Date.new(2012, 1, 2))).to be_falsey + end + end + + describe "#dates" do + it "should have with position 0" do + expect(subject.dates.first.position).to eq(0) + end + context "when first date has been removed" do + before do + subject.dates.first.destroy + end + it "should begin with position 0" do + expect(subject.dates.first.position).to eq(0) + end + end + end + describe "#validity_out_between?" do + let(:empty_tm) {build(:time_table)} + it "should be false if empty calendar" do + expect(empty_tm.validity_out_between?( Date.today, Date.today + 7.day)).to be_falsey + end + it "should be true if caldendar is out during start_date and end_date period" do + start_date = subject.bounding_dates.max - 2.day + end_date = subject.bounding_dates.max + 2.day + expect(subject.validity_out_between?( start_date, end_date)).to be_truthy + end + it "should be false if calendar is out on start date" do + start_date = subject.bounding_dates.max + end_date = subject.bounding_dates.max + 2.day + expect(subject.validity_out_between?( start_date, end_date)).to be_falsey + end + it "should be false if calendar is out on end date" do + start_date = subject.bounding_dates.max - 2.day + end_date = subject.bounding_dates.max + expect(subject.validity_out_between?( start_date, end_date)).to be_truthy + end + it "should be false if calendar is out after start_date" do + start_date = subject.bounding_dates.max + 2.day + end_date = subject.bounding_dates.max + 4.day + expect(subject.validity_out_between?( start_date, end_date)).to be_falsey + end + end + describe "#validity_out_from_on?" do + let(:empty_tm) {build(:time_table)} + it "should be false if empty calendar" do + expect(empty_tm.validity_out_from_on?( Date.today)).to be_falsey + end + it "should be true if caldendar ends on expected date" do + expected_date = subject.bounding_dates.max + expect(subject.validity_out_from_on?( expected_date)).to be_truthy + end + it "should be true if calendar ends before expected date" do + expected_date = subject.bounding_dates.max + 30.day + expect(subject.validity_out_from_on?( expected_date)).to be_truthy + end + it "should be false if calendars ends after expected date" do + expected_date = subject.bounding_dates.max - 30.day + expect(subject.validity_out_from_on?( expected_date)).to be_falsey + end + end + describe "#bounding_dates" do + context "when timetable contains only periods" do + before do + subject.dates = [] + subject.save + end + it "should retreive periods.period_start.min and periods.period_end.max" do + expect(subject.bounding_dates.min).to eq(subject.periods.map(&:period_start).min) + expect(subject.bounding_dates.max).to eq(subject.periods.map(&:period_end).max) + end + end + context "when timetable contains only dates" do + before do + subject.periods = [] + subject.save + end + it "should retreive dates.min and dates.max" do + expect(subject.bounding_dates.min).to eq(subject.dates.map(&:date).min) + expect(subject.bounding_dates.max).to eq(subject.dates.map(&:date).max) + end + end + it "should contains min date" do + min_date = subject.bounding_dates.min + subject.dates.each do |tm_date| + expect(min_date <= tm_date.date).to be_truthy + end + subject.periods.each do |tm_period| + expect(min_date <= tm_period.period_start).to be_truthy + end + + end + it "should contains max date" do + max_date = subject.bounding_dates.max + subject.dates.each do |tm_date| + expect(tm_date.date <= max_date).to be_truthy + end + subject.periods.each do |tm_period| + expect(tm_period.period_end <= max_date).to be_truthy + end + + end + end + describe "#periods" do + it "should begin with position 0" do + expect(subject.periods.first.position).to eq(0) + end + context "when first period has been removed" do + before do + subject.periods.first.destroy + end + it "should begin with position 0" do + expect(subject.periods.first.position).to eq(0) + end + end + it "should have period_start before period_end" do + period = Chouette::TimeTablePeriod.new + period.period_start = Date.today + period.period_end = Date.today + 10 + expect(period.valid?).to be_truthy + end + it "should not have period_start after period_end" do + period = Chouette::TimeTablePeriod.new + period.period_start = Date.today + period.period_end = Date.today - 10 + expect(period.valid?).to be_falsey + end + it "should not have period_start equal to period_end" do + period = Chouette::TimeTablePeriod.new + period.period_start = Date.today + period.period_end = Date.today + expect(period.valid?).to be_falsey + end + end + # it { is_expected.to validate_presence_of :comment } # it { is_expected.to validate_uniqueness_of :objectid } @@ -964,7 +1165,6 @@ end target=subject.duplicate expect(target.id).to be_nil expect(target.comment).to eq(I18n.t("activerecord.copy", name: subject.comment)) - expect(target.objectid).to eq(subject.objectid+"_1") expect(target.int_day_types).to eq(subject.int_day_types) expect(target.dates.size).to eq(subject.dates.size) target.dates.each do |d| diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb index 76544f85d..d5e30594d 100644 --- a/spec/models/chouette/trident_active_record_spec.rb +++ b/spec/models/chouette/trident_active_record_spec.rb @@ -1,119 +1,57 @@ require 'spec_helper' describe Chouette::TridentActiveRecord, :type => :model do - - it { expect(Chouette::TridentActiveRecord.ancestors).to include(Chouette::ActiveRecord) } - subject { create(:time_table) } - describe "#uniq_objectid" do + it { should validate_presence_of :objectid } + it { should validate_uniqueness_of :objectid } - it "should rebuild objectid" do - tm = create(:time_table) - tm.objectid = subject.objectid - tm.uniq_objectid - expect(tm.objectid).to eq(subject.objectid+"_1") - end + describe "#default_values" do + let(:object) { build(:time_table, objectid: nil) } - it "should rebuild objectid" do - tm = create(:time_table) - tm.objectid = subject.objectid - tm.uniq_objectid - tm.save - tm = create(:time_table) - tm.objectid = subject.objectid - tm.uniq_objectid - expect(tm.objectid).to eq(subject.objectid+"_2") + it 'should fill __pending_id__' do + object.default_values + expect(object.objectid.include?('__pending_id__')).to be_truthy end - end - def create_object(options = {}) - options = {name: "merge1"}.merge options - attributes = { comment: options[:name], objectid: options[:objectid] } - Chouette::TimeTable.new attributes - end - - describe "#prepare_auto_columns" do - - it "should left objectid" do - tm = create_object :objectid => "first:Timetable:merge1" - tm.prepare_auto_columns - expect(tm.objectid).to eq("first:Timetable:merge1") - end - - it "should add pending_id to objectid" do - tm = create_object - tm.prepare_auto_columns - expect(tm.objectid.start_with?("first:Timetable:__pending_id__")).to be_truthy - end - - it "should set id to objectid" do - tm = create_object - tm.save - expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s) - end + describe "#objectid" do + let(:object) { build(:time_table, objectid: nil) } - it "should detect objectid conflicts" do - tm = create_object - tm.save - tm.objectid = "first:Timetable:"+(tm.id+1).to_s - tm.save - tm = create_object - tm.save - expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s+"_1") + it 'should build objectid on create' do + object.save + id = "#{object.provider_id}:#{object.model_name}:#{object.local_id}:#{object.boiv_id}" + expect(object.objectid).to eq(id) end - end - - describe "objectid" do - - it "should build automatic objectid when empty" do - g1 = create_object - g1.save - expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s) + it 'should call build_objectid on after save' do + expect(object).to receive(:build_objectid) + object.save end - it "should build automatic objectid with fixed when only suffix given" do - g1 = create_object - g1.objectid = "toto" - g1.save - expect(g1.objectid).to eq("first:Timetable:toto") + it 'should not build new objectid is already set' do + id = "first:TimeTable:1-1:LOC" + object.objectid = id + object.save + expect(object.objectid).to eq(id) end - it "should build automatic objectid with extension when already exists" do - g1 = create_object - g1.save - cnt = g1.id + 1 - g1.objectid = "first:Timetable:"+cnt.to_s - g1.save - g2 = create_object - g2.save - expect(g2.objectid).to eq("first:Timetable:"+g2.id.to_s+"_1") + it 'should call default_values on create' do + expect(object).to receive(:default_values) + object.save end - it "should build automatic objectid with extension when already exists" do - g1 = create_object - g1.save - cnt = g1.id + 2 - g1.objectid = "first:Timetable:"+cnt.to_s - g1.save - g2 = create_object - g2.objectid = "first:Timetable:"+cnt.to_s+"_1" - g2.save - g3 = create_object - g3.save - expect(g3.objectid).to eq("first:Timetable:"+g3.id.to_s+"_2") + it 'should not call default_values on update' do + object = create(:time_table) + expect(object).to_not receive(:default_values) + object.touch end - it "should build automatic objectid when id cleared" do - g1 = create_object - g1.objectid = "first:Timetable:xxxx" - g1.save - g1.objectid = nil - g1.save - expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s) + it 'should create a new objectid when cleared' do + object.save + object.objectid = nil + object.save + expect(object.objectid).to be_truthy end end - end diff --git a/spec/models/concerns/error_format_spec.rb b/spec/models/concerns/error_format_spec.rb index 45b4c2f60..f82aecf44 100644 --- a/spec/models/concerns/error_format_spec.rb +++ b/spec/models/concerns/error_format_spec.rb @@ -1,7 +1,7 @@ RSpec.describe ErrorFormat do - - context '#details' do - context 'are empty' do + + context '#details' do + context 'are empty' do it 'if no errors are present' do expect( described_class.details(build_stubbed(:referential)) @@ -14,7 +14,7 @@ RSpec.describe ErrorFormat do end end - context 'are not empty' do + context 'are not empty' do it 'if an error is present and validation has been carried out' do invalid = build_stubbed(:referential, name: nil) expect( invalid ).not_to be_valid @@ -27,12 +27,12 @@ RSpec.describe ErrorFormat do create(:referential, name: 'hello') invalid = build_stubbed( :referential, - name: 'hello', + name: '', slug: 'hello world' ) expect( invalid ).not_to be_valid expect( described_class.details(invalid) ).to eq({ - name: { error: "n'est pas disponible", value: 'hello' }, + name: { error: "doit être rempli(e)", value: '' }, slug: { error: "n'est pas valide", value: 'hello world' } }) end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 477d269e0..cd5a30982 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -26,12 +26,35 @@ RSpec.describe Import, type: :model do ) end - # describe "#destroy" do - # it "must call #destroy on imports children and then import_messages, import_resources linked" do - # TODO - # - # end - # end + describe "#destroy" do + it "must destroy all child imports" do + workbench_import = create(:workbench_import) + create(:netex_import, parent: workbench_import) + + workbench_import.destroy + + expect(workbench_import).to be_destroyed + expect(NetexImport.count).to eq(0) + end + + it "must destroy all associated ImportMessages" do + import = create(:import) + create(:import_resource, import: import) + + import.destroy + + expect(ImportResource.count).to eq(0) + end + + it "must destroy all associated ImportResources" do + import = create(:import) + create(:import_message, import: import) + + import.destroy + + expect(ImportMessage.count).to eq(0) + end + end describe "#notify_parent" do it "must call #child_change on its parent" do diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb index 775e6f228..291ed974a 100644 --- a/spec/models/referential_metadata_spec.rb +++ b/spec/models/referential_metadata_spec.rb @@ -30,8 +30,8 @@ RSpec.describe ReferentialMetadata, :type => :model do expect(new_referential_metadata.referential).to be(nil) end - it "should have the same referential_source" do - expect(new_referential_metadata.referential_source).to eq(referential_metadata.referential_source) + it "should have the right referential_source" do + expect(new_referential_metadata.referential_source).to eq(referential_metadata.referential) end end diff --git a/spec/models/vehicle_journey_export_spec.rb b/spec/models/vehicle_journey_export_spec.rb index 6252a73f9..83b3bbb04 100644 --- a/spec/models/vehicle_journey_export_spec.rb +++ b/spec/models/vehicle_journey_export_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe VehicleJourneyExport, :type => :model do - + let!(:line) { create(:line) } let!(:route) { create(:route, :line => line) } let!(:other_route) { create(:route, :line => line) } @@ -10,10 +10,10 @@ describe VehicleJourneyExport, :type => :model do let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } - let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } - let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - + let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:1:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:2:loc", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } + let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:3:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:stop_point0) { route.stop_points[0] } let!(:stop_point1) { route.stop_points[1] } let!(:stop_point2) { route.stop_points[2] } @@ -21,10 +21,10 @@ describe VehicleJourneyExport, :type => :model do let!(:stop_point4) { route.stop_points[4] } let!(:time_table) { create(:time_table)} - - subject { VehicleJourneyExport.new(:vehicle_journeys => route.vehicle_journeys, :route => route) } - describe ".tt_day_types" do + subject { VehicleJourneyExport.new(:vehicle_journeys => route.vehicle_journeys, :route => route) } + + describe ".tt_day_types" do it "should return no day_type" do time_table.int_day_types = 0 @@ -35,10 +35,10 @@ describe VehicleJourneyExport, :type => :model do time_table.int_day_types = 4|8|16|32|64|128|256 expect(subject.tt_day_types(time_table)).to eq("LuMaMeJeVeSaDi") end - + end - describe ".tt_periods" do + describe ".tt_periods" do it "should return empty period" do time_table.periods.clear @@ -50,10 +50,10 @@ describe VehicleJourneyExport, :type => :model do time_table.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,8)) expect(subject.tt_periods(time_table)).to eq("[2014-08-01 -> 2014-08-08] ") end - + end - - describe ".tt_included_days" do + + describe ".tt_included_days" do it "should return empty included dates" do time_table.dates.clear @@ -65,10 +65,10 @@ describe VehicleJourneyExport, :type => :model do time_table.dates << Chouette::TimeTableDate.new(:date => Date.new(2014,8,1), :in_out => true) expect(subject.tt_peculiar_days(time_table)).to eq("2014-08-01 ") end - + end - describe ".tt_excluded_days" do + describe ".tt_excluded_days" do it "should return empty excluded dates" do time_table.dates.clear @@ -80,7 +80,7 @@ describe VehicleJourneyExport, :type => :model do time_table.dates << Chouette::TimeTableDate.new(:date => Date.new(2014,8,1), :in_out => false) expect(subject.tt_excluded_days(time_table)).to eq("2014-08-01 ") end - + end - + end diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index b01523dd9..7b31dc806 100644 --- a/spec/models/vehicle_journey_import_spec.rb +++ b/spec/models/vehicle_journey_import_spec.rb @@ -36,9 +36,9 @@ describe VehicleJourneyImport, :type => :model do let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } - let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } - let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2:loc", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } + let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } let!(:stop_point0) { route.stop_points[0] } let!(:stop_point1) { route.stop_points[1] } @@ -86,7 +86,7 @@ describe VehicleJourneyImport, :type => :model do expect(Chouette::VehicleJourneyAtStop.all.size).to eq(17) end - it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order", :skip => "Time gap validation is in pending status" do + it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order", :skip => "Time gap validation is in pending status" do expect(VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object).save).to be_falsey expect(Chouette::VehicleJourney.all.size).to eq(3) expect(Chouette::VehicleJourneyAtStop.all.size).to eq(0) diff --git a/spec/models/vehicle_translation_spec.rb b/spec/models/vehicle_translation_spec.rb index c9a573ae2..d30cfa03e 100644 --- a/spec/models/vehicle_translation_spec.rb +++ b/spec/models/vehicle_translation_spec.rb @@ -6,7 +6,6 @@ describe VehicleTranslation, :type => :model do # To fix : need to comment :company => company # after adding company to apartment excluded models let!(:vehicle_journey){ create(:vehicle_journey, - :objectid => "dummy", :journey_pattern => journey_pattern, :route => journey_pattern.route, # :company => company, |
