diff options
| author | Teddy Wing | 2017-05-23 18:11:43 +0200 |
|---|---|---|
| committer | Robert | 2017-05-29 08:49:52 +0200 |
| commit | c8452bfcedf158abf5c10a0ca8d1449650710eca (patch) | |
| tree | 8053d66466fca9a3df211e2d469844d5a38facab /spec | |
| parent | 3a89c7495894912cfac7b56913ce2465b5314ec6 (diff) | |
| download | chouette-core-c8452bfcedf158abf5c10a0ca8d1449650710eca.tar.bz2 | |
Move #increasing_times_validate into IncreasingTimeOrderValidator
Just move the methods and tests for now (and add a little whitespace).
Haven't modified anything yet so the code isn't working or integrated
into the new class.
Refs #870
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stop_spec.rb | 42 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb | 50 |
2 files changed, 50 insertions, 42 deletions
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index ba5b2bf74..328f91726 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -1,46 +1,4 @@ require 'spec_helper' describe Chouette::VehicleJourneyAtStop, :type => :model do - let!(:vehicle_journey) { create(:vehicle_journey_odd)} - subject { vehicle_journey.vehicle_journey_at_stops.first } - - describe "#exceeds_gap?" do - it "should return false if gap < 1.hour" do - t1 = Time.now - t2 = Time.now + 3.minutes - expect(subject.exceeds_gap?(t1, t2)).to be_falsey - end - it "should return true if gap > 4.hour" do - t1 = Time.now - t2 = Time.now + (4.hours + 1.minutes) - expect(subject.exceeds_gap?(t1, t2)).to be_truthy - end - end - - describe "#increasing_times_validate" do - let(:vjas1){ vehicle_journey.vehicle_journey_at_stops[0]} - let(:vjas2){ vehicle_journey.vehicle_journey_at_stops[1]} - context "when vjas#arrival_time exceeds gap" do - it "should add errors on arrival_time" do - vjas1.arrival_time = vjas2.arrival_time - 5.hour - expect(vjas2.increasing_times_validate(vjas1)).to be_falsey - expect(vjas2.errors).not_to be_empty - expect(vjas2.errors[:arrival_time]).not_to be_blank - end - end - context "when vjas#departure_time exceeds gap" do - it "should add errors on departure_time" do - vjas1.departure_time = vjas2.departure_time - 5.hour - expect(vjas2.increasing_times_validate(vjas1)).to be_falsey - expect(vjas2.errors).not_to be_empty - expect(vjas2.errors[:departure_time]).not_to be_blank - end - end - context "when vjas does'nt exceed gap" do - it "should not add errors" do - expect(vjas2.increasing_times_validate(vjas1)).to be_truthy - expect(vjas2.errors).to be_empty - end - end - end end diff --git a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb index ea161ec79..a667fbfcc 100644 --- a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb @@ -22,4 +22,54 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do expect(subject).not_to be_valid end end + + describe "#exceeds_gap?" do + let!(:vehicle_journey) { create(:vehicle_journey_odd) } + subject { vehicle_journey.vehicle_journey_at_stops.first } + + it "should return false if gap < 1.hour" do + t1 = Time.now + t2 = Time.now + 3.minutes + expect(subject.exceeds_gap?(t1, t2)).to be_falsey + end + + it "should return true if gap > 4.hour" do + t1 = Time.now + t2 = Time.now + (4.hours + 1.minutes) + expect(subject.exceeds_gap?(t1, t2)).to be_truthy + end + end + + describe "#increasing_times_validate" do + let!(:vehicle_journey) { create(:vehicle_journey_odd) } + subject { vehicle_journey.vehicle_journey_at_stops.first } + + let(:vjas1) { vehicle_journey.vehicle_journey_at_stops[0] } + let(:vjas2) { vehicle_journey.vehicle_journey_at_stops[1] } + + context "when vjas#arrival_time exceeds gap" do + it "should add errors on arrival_time" do + vjas1.arrival_time = vjas2.arrival_time - 5.hour + expect(vjas2.increasing_times_validate(vjas1)).to be_falsey + expect(vjas2.errors).not_to be_empty + expect(vjas2.errors[:arrival_time]).not_to be_blank + end + end + + context "when vjas#departure_time exceeds gap" do + it "should add errors on departure_time" do + vjas1.departure_time = vjas2.departure_time - 5.hour + expect(vjas2.increasing_times_validate(vjas1)).to be_falsey + expect(vjas2.errors).not_to be_empty + expect(vjas2.errors[:departure_time]).not_to be_blank + end + end + + context "when vjas does'nt exceed gap" do + it "should not add errors" do + expect(vjas2.increasing_times_validate(vjas1)).to be_truthy + expect(vjas2.errors).to be_empty + end + end + end end |
