aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2017-12-28 15:42:11 +0100
committerAlban Peignier2017-12-28 15:42:11 +0100
commitb9bcf2fc557c7e17451f4101ae4157cf7671cc6b (patch)
treed342cd46228e7b3cbbfa842a88e579036761a3f5
parent31965824161284176fee1fddfce7e2fe3894ad7e (diff)
downloadchouette-core-5313_stop_areas_parent.tar.bz2
Add specs on StopArea parent area_type validation. Refuse parent of the same type. Refs #53135313_stop_areas_parent
-rw-r--r--app/models/chouette/stop_area.rb2
-rw-r--r--spec/models/chouette/stop_area_spec.rb36
2 files changed, 37 insertions, 1 deletions
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 08a5d0826..4f1359ff8 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -49,7 +49,7 @@ module Chouette
def parent_area_type_must_be_greater
return unless self.parent
- if Chouette::AreaType.find(self.area_type) > Chouette::AreaType.find(self.parent.area_type)
+ if Chouette::AreaType.find(self.area_type) >= Chouette::AreaType.find(self.parent.area_type)
errors.add(:parent_id, I18n.t('stop_areas.errors.parent_area_type', area_type: self.parent.area_type))
end
end
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index bec8c0868..9db0f11a5 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -426,6 +426,42 @@ describe Chouette::StopArea, :type => :model do
# end
# end
+ describe "#parent" do
+
+ let(:stop_area) { FactoryGirl.build :stop_area, parent: FactoryGirl.build(:stop_area) }
+
+ it "is valid when parent has an 'higher' type" do
+ stop_area.area_type = 'zdep'
+ stop_area.parent.area_type = 'zdlp'
+
+ stop_area.valid?
+ expect(stop_area.errors).to_not have_key(:parent_id)
+ end
+
+ it "is valid when parent is undefined" do
+ stop_area.parent = nil
+
+ stop_area.valid?
+ expect(stop_area.errors).to_not have_key(:parent_id)
+ end
+
+ it "isn't valid when parent has the same type" do
+ stop_area.parent.area_type = stop_area.area_type = 'zdep'
+
+ stop_area.valid?
+ expect(stop_area.errors).to have_key(:parent_id)
+ end
+
+ it "isn't valid when parent has a lower type" do
+ stop_area.area_type = 'lda'
+ stop_area.parent.area_type = 'zdep'
+
+ stop_area.valid?
+ expect(stop_area.errors).to have_key(:parent_id)
+ end
+
+ end
+
describe '#waiting_time' do
let(:stop_area) { FactoryGirl.build :stop_area }