diff options
| author | Xinhui | 2017-08-08 12:04:50 +0200 | 
|---|---|---|
| committer | Xinhui | 2017-08-08 12:44:39 +0200 | 
| commit | 117954f2666744b5301a7ffefb0b7d494fd49514 (patch) | |
| tree | 8bd03f0c5b33d3842ae07aa252e194e7d33044da /spec/models | |
| parent | 2cf8146cdb4a28fe247108f98c5bc7eb05940e05 (diff) | |
| parent | d524e5474a913df296d4f4586eba4b879bad8b6f (diff) | |
| download | chouette-core-117954f2666744b5301a7ffefb0b7d494fd49514.tar.bz2 | |
Merge branch 'checksum'
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/chouette/footnote_spec.rb | 19 | ||||
| -rw-r--r-- | spec/models/chouette/journey_pattern_spec.rb | 3 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_base_spec.rb | 7 | ||||
| -rw-r--r-- | spec/models/chouette/routing_constraint_zone_spec.rb | 4 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_period_spec.rb | 8 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_spec.rb | 246 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stop_spec.rb | 15 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 5 | 
8 files changed, 56 insertions, 251 deletions
diff --git a/spec/models/chouette/footnote_spec.rb b/spec/models/chouette/footnote_spec.rb index 5c09e3931..98d751499 100644 --- a/spec/models/chouette/footnote_spec.rb +++ b/spec/models/chouette/footnote_spec.rb @@ -1,9 +1,22 @@  require 'spec_helper' -describe Chouette::Footnote do - -  subject { build(:footnote) } +describe Chouette::Footnote, type: :model do +  let(:footnote) { create(:footnote) }    it { should validate_presence_of :line } +  describe 'checksum' do +    it_behaves_like 'checksum support', :footnote + +    context '#checksum_attributes' do +      it 'should return code and label' do +        expected = [footnote.code, footnote.label] +        expect(footnote.checksum_attributes).to include(*expected) +      end + +      it 'should not return other atrributes' do +        expect(footnote.checksum_attributes).to_not include(footnote.updated_at) +      end +    end +  end  end diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index 26d220056..047022ade 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -1,6 +1,9 @@  require 'spec_helper'  describe Chouette::JourneyPattern, :type => :model do +  describe 'checksum' do +    it_behaves_like 'checksum support', :journey_pattern +  end    # context 'validate minimum stop_points size' do    #   let(:journey_pattern) { create :journey_pattern } diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb index 08f201022..c93b311ff 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -1,6 +1,9 @@  RSpec.describe Chouette::Route, :type => :model do    subject { create(:route) } +  describe 'checksum' do +    it_behaves_like 'checksum support', :route +  end    describe '#objectid' do      subject { super().objectid } @@ -62,8 +65,4 @@ RSpec.describe Chouette::Route, :type => :model do        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 0165c369d..054cfb9e6 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -9,6 +9,10 @@ describe Chouette::RoutingConstraintZone, type: :model do    # shoulda matcher to validate length of array ?    xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) } +  describe 'checksum' do +    it_behaves_like 'checksum support', :routing_constraint_zone +  end +    describe 'validations' do      it 'validates the presence of route_id' do        expect { diff --git a/spec/models/chouette/time_table_period_spec.rb b/spec/models/chouette/time_table_period_spec.rb index 07dc602cb..cc1a3ae09 100644 --- a/spec/models/chouette/time_table_period_spec.rb +++ b/spec/models/chouette/time_table_period_spec.rb @@ -4,11 +4,15 @@ describe Chouette::TimeTablePeriod, :type => :model do    let!(:time_table) { create(:time_table)}    subject { create(:time_table_period ,:time_table => time_table, :period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,6) ) } -  let!(:p2) {create(:time_table_period ,:time_table => time_table, :period_start => Date.new(2014,7,6), :period_end => Date.new(2014,7,14) ) }  +  let!(:p2) {create(:time_table_period ,:time_table => time_table, :period_start => Date.new(2014,7,6), :period_end => Date.new(2014,7,14) ) }    it { is_expected.to validate_presence_of :period_start }    it { is_expected.to validate_presence_of :period_end } -   + +  describe 'checksum' do +    it_behaves_like 'checksum support', :time_table_period +  end +    describe "#overlap" do      context "when periods intersect, " do        it "should detect period overlap" do diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index f13e13d52..c4eaeaaf0 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -840,252 +840,15 @@ end                                :period_end => Date.new(2013, 05, 30))        expect(time_table.intersects([ Date.new(2013, 05, 27),  Date.new(2013, 05, 28)])).to eq([ Date.new(2013, 05, 27),  Date.new(2013, 05, 28)])      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") -      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", :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") -      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", :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", :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", :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", :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", :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 -  describe "#effective_days_of_periods" do -      before do -        subject.periods.clear -        subject.periods << Chouette::TimeTablePeriod.new( -                              :period_start => Date.new(2014, 6, 30), -                              :period_end => Date.new(2014, 7, 6)) -        subject.int_day_types = 4|8|16 -      end -      it "should return monday to wednesday" do -        expect(subject.effective_days_of_periods.size).to eq(3) -        expect(subject.effective_days_of_periods[0]).to eq(Date.new(2014, 6, 30)) -        expect(subject.effective_days_of_periods[1]).to eq(Date.new(2014, 7, 1)) -        expect(subject.effective_days_of_periods[2]).to eq(Date.new(2014, 7, 2)) -      end -      it "should return thursday" do -        expect(subject.effective_days_of_periods(Chouette::TimeTable.valid_days(32)).size).to eq(1) -        expect(subject.effective_days_of_periods(Chouette::TimeTable.valid_days(32))[0]).to eq(Date.new(2014, 7, 3)) -      end - -  end +  # it { is_expected.to validate_presence_of :comment } +  # it { is_expected.to validate_uniqueness_of :objectid } -  describe "#included_days" do -      before do -        subject.dates.clear -        subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,16), :in_out => true) -        subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,17), :in_out => false) -        subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,18), :in_out => true) -        subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,19), :in_out => false) -        subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,20), :in_out => true) -      end -      it "should return 3 dates" do -        days = subject.included_days -        expect(days.size).to eq(3) -        expect(days[0]).to eq(Date.new(2014, 7, 16)) -        expect(days[1]).to eq(Date.new(2014,7, 18)) -        expect(days[2]).to eq(Date.new(2014, 7,20)) -      end +  describe 'checksum' do +    it_behaves_like 'checksum support', :time_table    end - -    describe "#excluded_days" do        before do          subject.dates.clear @@ -1223,5 +986,4 @@ end          expect(subject.tag_list.size).to eq(2)        end    end -  end diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index d999ed1a8..4f9d12730 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -1,6 +1,21 @@  require 'spec_helper'  RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do +  describe 'checksum' do +    let(:at_stop) { build_stubbed(:vehicle_journey_at_stop) } + +    it_behaves_like 'checksum support', :vehicle_journey_at_stop + +    context '#checksum_attributes' do +      it 'should return attributes' do +        expected = [at_stop.departure_time.to_s(:time), at_stop.arrival_time.to_s(:time)] +        expected << at_stop.departure_day_offset.to_s +        expected << at_stop.arrival_day_offset.to_s +        expect(at_stop.checksum_attributes).to include(*expected) +      end +    end +  end +    describe "#day_offset_outside_range?" do      let (:at_stop) { build_stubbed(:vehicle_journey_at_stop) } diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 3c04a77cc..52f2ab42d 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -17,8 +17,13 @@ describe Chouette::VehicleJourney, :type => :model do      expect(vehicle_journey).to be_valid    end +  describe 'checksum' do +    it_behaves_like 'checksum support', :vehicle_journey +  end +    describe "vjas_departure_time_must_be_before_next_stop_arrival_time",        skip: "Validation currently commented out because it interferes with day offsets" do +      let(:vehicle_journey) { create :vehicle_journey }      let(:vjas) { vehicle_journey.vehicle_journey_at_stops }  | 
