diff options
| author | Teddy Wing | 2017-07-17 18:28:21 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-07-21 15:59:53 +0200 |
| commit | dca839c6b1d55413d613a02ad8e8d98b688b3155 (patch) | |
| tree | c6eded086a18345e17c207a5f421f595d4b65079 /spec | |
| parent | 0166ef93691416b687091c4ff0aa6fb308a449e2 (diff) | |
| download | chouette-core-dca839c6b1d55413d613a02ad8e8d98b688b3155.tar.bz2 | |
VehicleJourneyAtStop: Add new specs for day offset validation
Replace our numericality validation tests with an equivalent set of
tests since we're now using a custom validation function.
Move `#outside_range` into the class scope so we can test it. Ignoring
model validation tests and hooking into this method as the "real"
important validator.
Refs #3597
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stop_spec.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index 23f33fc8f..99c8af066 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -1,16 +1,28 @@ require 'spec_helper' RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do - it do - should validate_numericality_of(:arrival_day_offset) - .is_greater_than_or_equal_to(0) - .is_less_than_or_equal_to(Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX) - end + describe "#day_offset_outside_range" do + it "disallows negative offsets" do + at_stop = build_stubbed(:vehicle_journey_at_stop) + + expect(at_stop.day_offset_outside_range?(-1)).to be true + end + + it "disallows offsets greater than DAY_OFFSET_MAX" do + at_stop = build_stubbed(:vehicle_journey_at_stop) - it do - should validate_numericality_of(:departure_day_offset) - .is_greater_than_or_equal_to(0) - .is_less_than_or_equal_to(Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX) + expect(at_stop.day_offset_outside_range?( + Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX + 1 + )).to be true + end + + it "allows offsets between 0 and DAY_OFFSET_MAX inclusive" do + at_stop = build_stubbed(:vehicle_journey_at_stop) + + expect(at_stop.day_offset_outside_range?( + Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX + )).to be false + end end describe "#validate" do |
