aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-07-17 17:59:34 +0200
committerTeddy Wing2017-07-21 15:59:53 +0200
commit161f3184783ba3419238d3ce6b2291ef9fabfa01 (patch)
treedc7e42217b3b4052fc98331568316d4e0543abdd
parentac03cfc3b24c49b952a31f84cf7063a9cd68acc4 (diff)
downloadchouette-core-161f3184783ba3419238d3ce6b2291ef9fabfa01.tar.bz2
VehicleJourneyAtStop: Add error message to max day offset error
Add a custom error message for when the day offset exceeds our maximum. Unfortunately, this uses Rails 5 lambda syntax, so it doesn't work. Will need to extract it to a method, but figured I'd just commit this anyway for posterity. The French error message text was taken from the Redmine issue, authored by Luc. I translated it into English. Refs #3597
-rw-r--r--app/models/chouette/vehicle_journey_at_stop.rb19
-rw-r--r--config/locales/vehicle_journey_at_stops.en.yml4
-rw-r--r--config/locales/vehicle_journey_at_stops.fr.yml4
-rw-r--r--spec/models/chouette/vehicle_journey_at_stop_spec.rb21
4 files changed, 46 insertions, 2 deletions
diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb
index c569e5849..f58773d18 100644
--- a/app/models/chouette/vehicle_journey_at_stop.rb
+++ b/app/models/chouette/vehicle_journey_at_stop.rb
@@ -28,11 +28,26 @@ module Chouette
validates :arrival_day_offset, numericality: {
greater_than_or_equal_to: 0,
- less_than_or_equal_to: DAY_OFFSET_MAX
+ less_than_or_equal_to: DAY_OFFSET_MAX,
+ message: ->(object, data) do
+ byebug
+ I18n.t(
+ 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max',
+ local_id: object.vehicle_journey.objectid.local_id,
+ max: DAY_OFFSET_MAX + 1
+ )
+ end
}
validates :departure_day_offset, numericality: {
greater_than_or_equal_to: 0,
- less_than_or_equal_to: DAY_OFFSET_MAX
+ less_than_or_equal_to: DAY_OFFSET_MAX,
+ message: ->(object, data) do
+ I18n.t(
+ 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max',
+ local_id: object.vehicle_journey.objectid.local_id,
+ max: DAY_OFFSET_MAX + 1
+ )
+ end
}
after_initialize :set_virtual_attributes
diff --git a/config/locales/vehicle_journey_at_stops.en.yml b/config/locales/vehicle_journey_at_stops.en.yml
new file mode 100644
index 000000000..a96effa2b
--- /dev/null
+++ b/config/locales/vehicle_journey_at_stops.en.yml
@@ -0,0 +1,4 @@
+en:
+ vehicle_journey_at_stops:
+ errors:
+ day_offset_must_not_exceed_max: "The vehicle journey with ID %{local_id} cannot have times exceeding %{max} days"
diff --git a/config/locales/vehicle_journey_at_stops.fr.yml b/config/locales/vehicle_journey_at_stops.fr.yml
new file mode 100644
index 000000000..3eff79cf4
--- /dev/null
+++ b/config/locales/vehicle_journey_at_stops.fr.yml
@@ -0,0 +1,4 @@
+fr:
+ vehicle_journey_at_stops:
+ errors:
+ day_offset_must_not_exceed_max: "La course avec l'identifiant %{local_id} ne peut pas avoir des horaires sur plus de %{max} jours"
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
index f0b34d77a..82b0783a6 100644
--- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb
+++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
@@ -12,4 +12,25 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
.is_greater_than_or_equal_to(0)
.is_less_than_or_equal_to(Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX)
end
+
+ describe "#validate" do
+ it "displays the proper error message when day offset exceeds the max" do
+ bad_offset = Chouette::VehicleJourneyAtStop::DAY_OFFSET_MAX + 1
+
+ at_stop = build_stubbed(
+ :vehicle_journey_at_stop,
+ arrival_day_offset: bad_offset,
+ departure_day_offset: bad_offset
+ )
+
+ at_stop.validate
+
+ expect(at_stop.errors[:arrival_day_offset]).to include(
+ I18n.t('vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max')
+ )
+ expect(at_stop.errors[:departure_day_offset]).to include(
+ I18n.t('vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max')
+ )
+ end
+ end
end