aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Perles2015-11-10 17:23:15 +0100
committerBruno Perles2015-11-13 11:16:52 +0100
commit75ed3616bbc6b2ab0b4a24da3027e896171357ea (patch)
tree79291919a942ae3e59a6c9ace1f98bc6366758f7
parent9772ead99ea485b03113885c96115922e81712b6 (diff)
downloadchouette-core-75ed3616bbc6b2ab0b4a24da3027e896171357ea.tar.bz2
#40077 - Fix validates
-rw-r--r--app/models/rule_parameter_set.rb32
-rw-r--r--lib/ninoxe_extension/hub/company_restrictions.rb14
-rw-r--r--lib/ninoxe_extension/hub/connection_link_restrictions.rb2
-rw-r--r--lib/ninoxe_extension/hub/group_of_line_restrictions.rb14
-rw-r--r--lib/ninoxe_extension/hub/journey_pattern_restrictions.rb6
-rw-r--r--lib/ninoxe_extension/hub/line_restrictions.rb14
-rw-r--r--lib/ninoxe_extension/hub/network_restrictions.rb12
-rw-r--r--lib/ninoxe_extension/hub/stop_area_restrictions.rb40
-rw-r--r--lib/ninoxe_extension/hub/time_table_restrictions.rb4
9 files changed, 74 insertions, 64 deletions
diff --git a/app/models/rule_parameter_set.rb b/app/models/rule_parameter_set.rb
index dca36a729..1a32bbae2 100644
--- a/app/models/rule_parameter_set.rb
+++ b/app/models/rule_parameter_set.rb
@@ -9,8 +9,6 @@ class RuleParameterSet < ActiveRecord::Base
serialize :parameters, JSON
- #attr_accessible :name, :organisation_id
-
def self.mode_attribute_prefixes
%w( allowed_transport inter_stop_area_distance_min inter_stop_area_distance_max speed_max speed_min inter_stop_duration_variation_max)
end
@@ -31,25 +29,23 @@ class RuleParameterSet < ActiveRecord::Base
end
def self.validable_object_names
- ["network","company","group_of_line",
- "stop_area","access_point","access_link","connection_link",
- "time_table","line","route",
- "journey_pattern","vehicle_journey"]
+ %w( network company group_of_line stop_area access_point access_link connection_link time_table line route
+ journey_pattern vehicle_journey )
end
def self.validable_columns
- {"network" => ['objectid','name','registration_number'],
- "company" => ['objectid','name','registration_number'],
- "group_of_line" => ['objectid','name','registration_number'],
- "stop_area" => ['objectid','name','registration_number','city_name','country_code','zip_code'],
- "access_point" => ['objectid','name','city_name','country_code','zip_code'],
- "access_link" => ['objectid','name','link_distance','default_duration'],
- "connection_link" => ['objectid','name','link_distance','default_duration'],
- "time_table" => ['objectid','comment','version'],
- "line" => ['objectid','name','registration_number','number','published_name'],
- "route" => ['objectid','name','number','published_name'],
- "journey_pattern" => ['objectid','name','registration_number','published_name'],
- "vehicle_journey" => ['objectid','published_journey_name','published_journey_identifier','number'] }
+ { 'network' => ['objectid','name','registration_number'],
+ 'company' => ['objectid','name','registration_number'],
+ 'group_of_line' => ['objectid','name','registration_number'],
+ 'stop_area' => ['objectid','name','registration_number','city_name','country_code','zip_code'],
+ 'access_point' => ['objectid','name','city_name','country_code','zip_code'],
+ 'access_link' => ['objectid','name','link_distance','default_duration'],
+ 'connection_link' => ['objectid','name','link_distance','default_duration'],
+ 'time_table' => ['objectid','comment','version'],
+ 'line' => ['objectid','name','registration_number','number','published_name'],
+ 'route' => ['objectid','name','number','published_name'],
+ 'journey_pattern' => ['objectid','name','registration_number','published_name'],
+ 'vehicle_journey' => ['objectid','published_journey_name','published_journey_identifier','number'] }
end
def self.column_attribute_prefixes
diff --git a/lib/ninoxe_extension/hub/company_restrictions.rb b/lib/ninoxe_extension/hub/company_restrictions.rb
index 6cb12f0b6..ee194a046 100644
--- a/lib/ninoxe_extension/hub/company_restrictions.rb
+++ b/lib/ninoxe_extension/hub/company_restrictions.rb
@@ -9,15 +9,19 @@ module NinoxeExtension::Hub
# HUB-7
g.validate :specific_objectid
# HUB-8
- #g.validates_format_of :name, :with => %r{\A[\w ]{1,75}\z}
- g.validates_length_of :name, :minimum => 1, :maximum => 75
+ #g.validates_length_of :name, :minimum => 1, :maximum => 75
+ g.validates :name, length: { in: 1..75 }
# HUB-9
- g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- g.validates_uniqueness_of :registration_number
+ #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
+ #g.validates_uniqueness_of :registration_number
+ g.validates :registration_number,
+ uniqueness: true,
+ length: { in: 1..8 },
+ numericality: { only_integer: true }
end
end
def specific_objectid
- validate_specific_objectid( 3)
+ validate_specific_objectid(3)
end
end
end
diff --git a/lib/ninoxe_extension/hub/connection_link_restrictions.rb b/lib/ninoxe_extension/hub/connection_link_restrictions.rb
index 600222455..6d4c3046f 100644
--- a/lib/ninoxe_extension/hub/connection_link_restrictions.rb
+++ b/lib/ninoxe_extension/hub/connection_link_restrictions.rb
@@ -8,7 +8,7 @@ module NinoxeExtension::Hub
with_options if: :hub_restricted? do |cl|
# HUB-34
- cl.validates :link_distance, :numericality => { :max => 10000.0 }
+ cl.validates :link_distance, numericality: { less_than_or_equal_to: 10000.to_f }
end
end
end
diff --git a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
index f8370faf1..26e5c5d5c 100644
--- a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
+++ b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
@@ -10,15 +10,19 @@ module NinoxeExtension::Hub
# HUB-11
g.validate :specific_objectid
# HUB-12
- #g.validates_format_of :name, :with => %r{\A[\w ]{1,75}\z}
- g.validates_length_of :name, :minimum => 1, :maximum => 75
+ #g.validates_length_of :name, :minimum => 1, :maximum => 75
+ g.validates :name, length: { in: 1..75 }
# HUB-13
- g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- g.validates_uniqueness_of :registration_number
+ #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
+ #g.validates_uniqueness_of :registration_number
+ g.validates :registration_number,
+ uniqueness: true,
+ numericality: { only_integer: true },
+ length: { in: 1..8 }
end
end
def specific_objectid
- validate_specific_objectid( 6)
+ validate_specific_objectid(6)
end
end
end
diff --git a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
index d4e881d1f..f3ec2cdbd 100644
--- a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
+++ b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
@@ -10,10 +10,10 @@ module NinoxeExtension::Hub
# HUB-39
jp.validate :specific_objectid
# HUB-40
- jp.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ jp.validates :registration_number, numericality: { less_than: 10 ** 8 }
# HUB-41
- #jp.validates_format_of :name, :with => %r{\A[\w ]{0,75}\z}
- jp.validates_length_of :name, :maximum => 75, :allow_blank => true, :allow_nil => true
+ #jp.validates_length_of :name, :maximum => 75, :allow_blank => true, :allow_nil => true
+ jp.validates :name, length: { maximum: 75 }, allow_blank: true
end
end
def specific_objectid
diff --git a/lib/ninoxe_extension/hub/line_restrictions.rb b/lib/ninoxe_extension/hub/line_restrictions.rb
index 9d8f22112..bdae3d77c 100644
--- a/lib/ninoxe_extension/hub/line_restrictions.rb
+++ b/lib/ninoxe_extension/hub/line_restrictions.rb
@@ -12,14 +12,16 @@ module NinoxeExtension::Hub
#l.validates_format_of :objectid, :with => %r{\A\w+:\w+:[\w]{1,14}\z}
l.validate :specific_objectid
# HUB-16
- l.validates_format_of :number, :with => %r{\A[\w]{1,6}\z}
- # HUB-17
- #l.validates_format_of :name, :with => %r{\A[\w ]{0,75}\z}
- l.validates_length_of :name, :maximum => 75
+ #l.validates_format_of :number, :with => %r{\A[\w]{1,6}\z}
+ l.validates :number, length: { in: 1..6 }, format: { with: /\A[\w]+\z/ }
+ # HUB-17 & HUB-22
+ #l.validates_length_of :name, :maximum => 75
+ l.validates :name, length: { maximum: 75 }, uniqueness: true, allow_blank: true
# HUB-21
- l.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ #l.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ l.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
# HUB-22
- l.validates_uniqueness_of :name, :allow_blank => true
+ #l.validates_uniqueness_of :name, :allow_blank => true
end
end
diff --git a/lib/ninoxe_extension/hub/network_restrictions.rb b/lib/ninoxe_extension/hub/network_restrictions.rb
index b18a6c033..deba1f75e 100644
--- a/lib/ninoxe_extension/hub/network_restrictions.rb
+++ b/lib/ninoxe_extension/hub/network_restrictions.rb
@@ -9,11 +9,15 @@ module NinoxeExtension::Hub
# HUB-3
n.validate :specific_objectid
# HUB-4
- #n.validates_format_of :name, :with => %r{\A[\w ]{1,75}\z}
- n.validates_length_of :name, :minimum => 1, :maximum => 75
+ #n.validates_length_of :name, :minimum => 1, :maximum => 75
+ n.validates :name, length: { in: 1..75 }
# HUB-5
- n.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- n.validates_uniqueness_of :registration_number
+ #n.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
+ #n.validates_uniqueness_of :registration_number
+ n.validates :registration_number,
+ uniqueness: true,
+ numericality: { only_integer: true },
+ length: { in: 1..8 }
end
end
def specific_objectid
diff --git a/lib/ninoxe_extension/hub/stop_area_restrictions.rb b/lib/ninoxe_extension/hub/stop_area_restrictions.rb
index c83cecdb4..17df9dba1 100644
--- a/lib/ninoxe_extension/hub/stop_area_restrictions.rb
+++ b/lib/ninoxe_extension/hub/stop_area_restrictions.rb
@@ -18,9 +18,9 @@ module NinoxeExtension::Hub
def commercial_and_physical_hub_restricted?
physical_hub_restricted? || commercial_hub_restricted?
end
- def specific_objectid
- validate_specific_objectid( 12)
- end
+ # def specific_objectid
+ # validate_specific_objectid( 12)
+ # end
included do
include ObjectidRestrictions
@@ -29,38 +29,38 @@ module NinoxeExtension::Hub
with_options if: :commercial_and_physical_hub_restricted? do |sa|
# HUB-23
sa.validate :specific_objectid
- #sa.validates_format_of :name, :with => %r{\A[\w ]{1,75}\z}
- sa.validates_length_of :name, :minimum => 1, :maximum => 75
+ #sa.validates_length_of :name, :minimum => 1, :maximum => 75
+ sa.validates :name, length: { in: 1..75 }
end
with_options if: :commercial_hub_restricted? do |sa|
# HUB-24
- #sa.validates_format_of :nearest_topic_name, :with => %r{\A[\w ]{0,255}\z}
- sa.validates_length_of :nearest_topic_name, :maximum => 255, :allow_blank => true, :allow_nil => true
+ #sa.validates_length_of :nearest_topic_name, :maximum => 255, :allow_blank => true, :allow_nil => true
+ sa.validates :nearest_topic_name, length: { maximum: 255 }, allow_blank: true
end
with_options if: :physical_hub_restricted? do |sa|
# HUB-25
- #sa.validates_format_of :nearest_topic_name, :with => %r{\A[\w ]{0,60}\z}
- sa.validates_length_of :nearest_topic_name, :maximum => 60, :allow_blank => true, :allow_nil => true
+ #sa.validates_length_of :nearest_topic_name, :maximum => 60, :allow_blank => true, :allow_nil => true
+ sa.validates :nearest_topic_name, length: { maximum: 60 }, allow_blank: true
# HUB-28
- sa.validates_presence_of :coordinates
- # sa.validates_presence_of :longitude
- # sa.validates_presence_of :latitude
+ #sa.validates_presence_of :coordinates
+ sa.validates :coordinates, presence: true
# HUB-29
- #sa.validates_format_of :city_name, :with => %r{\A[\w ]{1,80}\z}
- sa.validates_length_of :city_name, :minimum => 1, :maximum => 80
-
+ #sa.validates_length_of :city_name, :minimum => 1, :maximum => 80
+ sa.validates :city_name, length: { in: 1..80 }
# HUB-30
- sa.validates_format_of :country_code, :with => %r{\A[\d]{5}\z}
+ #sa.validates_format_of :country_code, :with => %r{\A[\d]{5}\z}
+ sa.validates :country_code, presence: true, numericality: { only_integer: true }, length: { is: 5 }
# HUB-31
- # sa.validates_format_of :comment, :with => %r{\A[\w ]{0,255}\z}
- sa.validates_length_of :comment, :maximum => 255, :allow_blank => true, :allow_nil => true
- sa.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ #sa.validates_length_of :comment, :maximum => 255, :allow_blank => true, :allow_nil => true
+ sa.validates :comment, length: { maximum: 255 }, allow_blank: true
+ #sa.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
+ sa.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
end
end
def specific_objectid
- validate_specific_objectid( 12)
+ validate_specific_objectid(12)
end
end
end
diff --git a/lib/ninoxe_extension/hub/time_table_restrictions.rb b/lib/ninoxe_extension/hub/time_table_restrictions.rb
index 36e6846ae..b61d1e05a 100644
--- a/lib/ninoxe_extension/hub/time_table_restrictions.rb
+++ b/lib/ninoxe_extension/hub/time_table_restrictions.rb
@@ -10,8 +10,8 @@ module NinoxeExtension::Hub
# HUB-44
tt.validate :specific_objectid
# HUB-45
- #tt.validates_format_of :comment, :with => %r{\A[\w ]{0,75}\z}
- tt.validates_length_of :comment, :maximum => 75, :allow_blank => true, :allow_nil => true
+ #tt.validates_length_of :comment, :maximum => 75, :allow_blank => true, :allow_nil => true
+ tt.validates :comment, length: { maximum: 75 }, allow_blank: true
end
end
def specific_objectid