aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2017-05-23 15:21:32 +0200
committerRobert2017-05-29 08:49:52 +0200
commit95ebdc82c85acdf7cae208294a750e40e9e418c2 (patch)
tree5280c2669134c4bc44432f5baada1bf3fe3c546f /spec
parent9aaa337d0b5e44736834f98f9aca8b4f31c63afc (diff)
downloadchouette-core-95ebdc82c85acdf7cae208294a750e40e9e418c2.tar.bz2
VehicleJourney: Move `#increasing_times` validator to a new class
Create a new validator class for this validation. By splitting the increasing time validation into a separate group, we can unify the functionality that's currently split between `VehicleJourney` and `VehicleJourneyAtStop`. This will allow us to go to a single place to look for the validation. Move the `#increasing_times` method into our new class with minor modification to make it work. Move the test for the method into a new spec file. Refs #870
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_order_validator_spec.rb25
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb12
2 files changed, 25 insertions, 12 deletions
diff --git a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_order_validator_spec.rb b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_order_validator_spec.rb
new file mode 100644
index 000000000..6c5541edd
--- /dev/null
+++ b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_order_validator_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Chouette::VehicleJourneyAtStopsAreInIncreasingOrderValidator do
+ subject { create(:vehicle_journey_odd) }
+
+ describe "#increasing_times" do
+ before(:each) do
+ subject.vehicle_journey_at_stops[0].departure_time =
+ subject.vehicle_journey_at_stops[1].departure_time - 5.hour
+ subject.vehicle_journey_at_stops[0].arrival_time =
+ subject.vehicle_journey_at_stops[0].departure_time
+ subject.vehicle_journey_at_stops[1].arrival_time =
+ subject.vehicle_journey_at_stops[1].departure_time
+ end
+
+ it "should make instance invalid" do
+ subject.validate
+
+ expect(
+ subject.vehicle_journey_at_stops[1].errors[:departure_time]
+ ).not_to be_blank
+ expect(subject).not_to be_valid
+ end
+ end
+end
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index ed76c278c..4a108d7c0 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -466,18 +466,6 @@ describe Chouette::VehicleJourney, :type => :model do
end
context "when following departure times exceeds gap" do
- describe "#increasing_times" do
- before(:each) do
- subject.vehicle_journey_at_stops[0].departure_time = subject.vehicle_journey_at_stops[1].departure_time - 5.hour
- subject.vehicle_journey_at_stops[0].arrival_time = subject.vehicle_journey_at_stops[0].departure_time
- subject.vehicle_journey_at_stops[1].arrival_time = subject.vehicle_journey_at_stops[1].departure_time
- end
- it "should make instance invalid" do
- subject.increasing_times
- expect(subject.vehicle_journey_at_stops[1].errors[:departure_time]).not_to be_blank
- expect(subject).not_to be_valid
- end
- end
describe "#update_attributes" do
let!(:params){ {"vehicle_journey_at_stops_attributes" => {
"0"=>{"id" => subject.vehicle_journey_at_stops[0].id ,"arrival_time" => 1.minutes.ago,"departure_time" => 1.minutes.ago},