aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2017-05-24 11:31:34 +0200
committerRobert2017-05-29 08:49:52 +0200
commit278fb14a2dfedef96682a3be3d106d7d451ca483 (patch)
tree1a76c77efdf117024a680de6586ecbe227b22c07 /spec
parent32aeba90d7c79505162a3aaf39094e3b2bb682d1 (diff)
downloadchouette-core-278fb14a2dfedef96682a3be3d106d7d451ca483.tar.bz2
IncreasingTimeOrder: Make `increasing_times_validate` a class method
Making this a class method allows us to test it more easily. Previously it was attached to `Chouette::VehicleJourneyAtStop`, and the tests I copied call it on a VehicleJourneyAtStop. It seems like instantiating a Validator class is kind of a pain, or at least a bit weird, since it's for internal Rails use. So we change it to a class method. Change `#exceeds_gap?` in this class to a class method also so we can continue to call it from `.increasing_times_validate`. Eventually we'll switch to the new version in the `TimeDuration` module. Comment out the tests for `#exceeds_gap?` for now as we'll be moving those into a new spec file for `TimeDuration` Refs #870
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb50
1 files changed, 30 insertions, 20 deletions
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 a667fbfcc..0b8565b5b 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
@@ -23,24 +23,25 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do
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
+ # TODO: Move to TimeDuration
+ # 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
+ describe ".increasing_times_validate" do
let!(:vehicle_journey) { create(:vehicle_journey_odd) }
subject { vehicle_journey.vehicle_journey_at_stops.first }
@@ -50,7 +51,10 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do
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(
+ Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator
+ .increasing_times_validate(vjas2, vjas1)
+ ).to be_falsey
expect(vjas2.errors).not_to be_empty
expect(vjas2.errors[:arrival_time]).not_to be_blank
end
@@ -59,7 +63,10 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do
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(
+ Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator
+ .increasing_times_validate(vjas2, vjas1)
+ ).to be_falsey
expect(vjas2.errors).not_to be_empty
expect(vjas2.errors[:departure_time]).not_to be_blank
end
@@ -67,7 +74,10 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do
context "when vjas does'nt exceed gap" do
it "should not add errors" do
- expect(vjas2.increasing_times_validate(vjas1)).to be_truthy
+ expect(
+ Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator
+ .increasing_times_validate(vjas2, vjas1)
+ ).to be_truthy
expect(vjas2.errors).to be_empty
end
end