diff options
| author | cedricnjanga | 2017-09-06 10:56:58 +0200 | 
|---|---|---|
| committer | cedricnjanga | 2017-09-06 11:01:22 +0200 | 
| commit | 84789cce5ed46c5e280f449fcde32a8612c2fa9d (patch) | |
| tree | 706449d5b6f0ee96889ae6b9c5a07ccb57612288 /spec/models | |
| parent | e9360b375f27d43d91d833d301224b0b04daf2f1 (diff) | |
| parent | 13ad6afc8290080c8fc5e3efd6cb26aedf2853e2 (diff) | |
| download | chouette-core-84789cce5ed46c5e280f449fcde32a8612c2fa9d.tar.bz2 | |
Resolve merge conflict
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/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/routing_constraint_zone_spec.rb | 19 | ||||
| -rw-r--r-- | spec/models/chouette/stop_point_spec.rb | 2 | ||||
| -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/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 | 
13 files changed, 279 insertions, 157 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/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/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..5eae8caf0 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -9,7 +9,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 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/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,  | 
