aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorcedricnjanga2017-11-10 17:23:45 +0100
committercedricnjanga2017-11-10 17:23:45 +0100
commit3b3d3252aa514fbd5b2c12a6cc0a2825d9d8b12e (patch)
tree5d22bfc466fd50b76dd805f891b62f59132d22fa /app
parent2f8ff43fe89a8c78575fdb7a9737b5484117087c (diff)
downloadchouette-core-3b3d3252aa514fbd5b2c12a6cc0a2825d9d8b12e.tar.bz2
Add validation and specs to models on objectid_format presence
Diffstat (limited to 'app')
-rw-r--r--app/models/chouette/company.rb1
-rw-r--r--app/models/chouette/network.rb1
-rw-r--r--app/models/chouette/routing_constraint_zone.rb2
-rw-r--r--app/models/chouette/stop_area.rb2
-rw-r--r--app/models/chouette/stop_point.rb2
-rw-r--r--app/models/chouette/time_table.rb1
-rw-r--r--app/models/concerns/netex_attributes_support.rb (renamed from app/models/concerns/default_netex_attributes_support.rb)2
-rw-r--r--app/models/concerns/object_id_format_to_line_referential.rb8
-rw-r--r--app/models/concerns/object_id_format_to_referential.rb8
-rw-r--r--app/models/line_referential.rb3
-rw-r--r--app/models/referential.rb5
-rw-r--r--app/models/stop_area_referential.rb3
-rw-r--r--app/models/workbench.rb3
13 files changed, 30 insertions, 11 deletions
diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb
index f324dbd04..94a23f008 100644
--- a/app/models/chouette/company.rb
+++ b/app/models/chouette/company.rb
@@ -8,6 +8,7 @@ class Chouette::Company < Chouette::ActiveRecord
validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true
validates_presence_of :name
+ validates_presence_of :objectid_format
validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true
def self.nullable_attributes
diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb
index 76c587141..dad1a17d2 100644
--- a/app/models/chouette/network.rb
+++ b/app/models/chouette/network.rb
@@ -12,6 +12,7 @@ class Chouette::Network < Chouette::ActiveRecord
validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true
validates_presence_of :name
+ validates_presence_of :objectid_format
def self.object_id_key
"PTNetwork"
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb
index 0e22acd42..124884830 100644
--- a/app/models/chouette/routing_constraint_zone.rb
+++ b/app/models/chouette/routing_constraint_zone.rb
@@ -5,7 +5,7 @@ class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord
belongs_to :route
has_array_of :stop_points, class_name: 'Chouette::StopPoint'
- validates_presence_of :name, :stop_points, :route
+ validates_presence_of :name, :stop_points, :route, :objectid_format
# validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') }
validate :stop_points_belong_to_route, :not_all_stop_points_selected
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 0735d9cae..7872581cb 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -64,7 +64,7 @@ class Chouette::StopArea < Chouette::ActiveRecord
end
def objectid_format
- "#{self.stop_area_referential.objectid_format}_attributes_support".camelcase.constantize
+ "#{self.stop_area_referential.objectid_format}_attributes_support".camelcase.constantize if self.stop_area_referential.objectid_format
end
def coordinates
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index 99a893602..c4034e2d4 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -19,6 +19,8 @@ module Chouette
acts_as_list :scope => :route, top_of_list: 0
+ validates_presence_of :objectid_format
+
validates_presence_of :stop_area
validate :stop_area_id_validation
def stop_area_id_validation
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index f4db0c3b1..6572dbfe4 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -52,6 +52,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
accepts_nested_attributes_for :periods, :allow_destroy => :true
validates_presence_of :comment
+ validates_presence_of :objectid_format
validates_associated :dates
validates_associated :periods
diff --git a/app/models/concerns/default_netex_attributes_support.rb b/app/models/concerns/netex_attributes_support.rb
index 4cf77ea65..d78528dbf 100644
--- a/app/models/concerns/default_netex_attributes_support.rb
+++ b/app/models/concerns/netex_attributes_support.rb
@@ -1,4 +1,4 @@
-module DefaultNetexAttributesSupport
+module NetexAttributesSupport
extend ActiveSupport::Concern
included do
diff --git a/app/models/concerns/object_id_format_to_line_referential.rb b/app/models/concerns/object_id_format_to_line_referential.rb
index 205f7e4e2..9725be824 100644
--- a/app/models/concerns/object_id_format_to_line_referential.rb
+++ b/app/models/concerns/object_id_format_to_line_referential.rb
@@ -1,5 +1,11 @@
module ObjectIdFormatToLineReferential
+ extend ActiveSupport::Concern
+
+ included do
+ validates_presence_of :objectid_format
+ end
+
def objectid_format
- "#{self.line_referential.objectid_format}_attributes_support".camelcase.constantize
+ "#{self.line_referential.objectid_format}_attributes_support".camelcase.constantize if self.line_referential.objectid_format
end
end
diff --git a/app/models/concerns/object_id_format_to_referential.rb b/app/models/concerns/object_id_format_to_referential.rb
index 2371aa0be..1b99acf17 100644
--- a/app/models/concerns/object_id_format_to_referential.rb
+++ b/app/models/concerns/object_id_format_to_referential.rb
@@ -1,5 +1,11 @@
module ObjectIdFormatToReferential
+ extend ActiveSupport::Concern
+
+ included do
+ validates_presence_of :objectid_format
+ end
+
def objectid_format
- "#{self.referential.objectid_format}_attributes_support".camelcase.constantize
+ "#{self.referential.objectid_format}_attributes_support".camelcase.constantize if self.referential.objectid_format
end
end
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb
index cbe07e9b1..d81644080 100644
--- a/app/models/line_referential.rb
+++ b/app/models/line_referential.rb
@@ -10,7 +10,8 @@ class LineReferential < ActiveRecord::Base
has_many :networks, class_name: 'Chouette::Network'
has_many :line_referential_syncs, -> { order created_at: :desc }
has_many :workbenches
- enumerize :objectid_format, in: %w(default_netex stif_netex)
+ enumerize :objectid_format, in: %w(netex stif_netex)
+ validates_presence_of :objectid_format
def add_member(organisation, options = {})
attributes = options.merge organisation: organisation
diff --git a/app/models/referential.rb b/app/models/referential.rb
index e4721a405..87ac61f56 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -12,8 +12,6 @@ class Referential < ActiveRecord::Base
validates_uniqueness_of :slug
- validates_presence_of :line_referential
- validates_presence_of :stop_area_referential
validates_format_of :slug, :with => %r{\A[a-z][0-9a-z_]+\Z}
validates_format_of :prefix, :with => %r{\A[0-9a-zA-Z_]+\Z}
validates_format_of :upper_corner, :with => %r{\A-?[0-9]+\.?[0-9]*\,-?[0-9]+\.?[0-9]*\Z}
@@ -56,7 +54,8 @@ class Referential < ActiveRecord::Base
belongs_to :referential_suite
- enumerize :objectid_format, in: %w(default_netex stif_netex)
+ enumerize :objectid_format, in: %w(netex stif_netex)
+ validates_presence_of :objectid_format
scope :ready, -> { where(ready: true) }
scope :in_periode, ->(periode) { where(id: referential_ids_in_periode(periode)) }
diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb
index c05d6e6be..2ef1278d8 100644
--- a/app/models/stop_area_referential.rb
+++ b/app/models/stop_area_referential.rb
@@ -6,7 +6,8 @@ class StopAreaReferential < ActiveRecord::Base
has_many :stop_areas, class_name: 'Chouette::StopArea'
has_many :stop_area_referential_syncs, -> {order created_at: :desc}
has_many :workbenches
- enumerize :objectid_format, in: %w(default_netex stif_netex)
+ enumerize :objectid_format, in: %w(netex stif_netex)
+ validates_presence_of :objectid_format
def add_member(organisation, options = {})
attributes = options.merge organisation: organisation
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index 22cad0f7f..8a48b0f9f 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -4,7 +4,8 @@ class Workbench < ActiveRecord::Base
belongs_to :line_referential
belongs_to :stop_area_referential
belongs_to :output, class_name: 'ReferentialSuite'
- enumerize :objectid_format, in: %w(default_netex stif_netex)
+ enumerize :objectid_format, in: %w(netex stif_netex)
+ validates_presence_of :objectid_format
has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential
has_many :networks, through: :line_referential