Skip to content

AttributeValidation

Reid Beels edited this page Aug 4, 2011 · 1 revision

Possible validations for attributes.

**Labels:**Phase-Design,Phase-QA

Introduction

This file responds to Issue84. "Validation" is used loosely and could be a validation test on save, but should be done earlier if Calagator might manipulate the attribute before saving it. Also remember that invalid values could be typed in the normal save/edit screens or could appear in an imported event or venue.

Event

Schema v 7

#  id          :integer         not null, primary key
#  title       :string(255)     
#  description :text            
#  start_time  :datetime        
#  venue_id    :integer         
#  url         :string(255)     
#  created_at  :datetime        
#  updated_at  :datetime        
#  end_time    :datetime        
#  source_id   :integer     

start_time

  • Event class currently validates_presence_of :title, :start_time
  • In Event create/edit, calendar forces this to be a valid datetime.
  • Import seems to have no independent check.

end_time

  • In Event create/edit, calendar forces this to be a valid datetime. But we are not checking to see if it is after start_time. See Issue82
  • Import seems to have no independent check.

url

  • In Event create/edit not currently validated, but should be. Could validate url syntax by URI.parse(url). See Source. Could also get a response code and check it for success. But what if non-success is a temporary problem, i.e., the domain is down only temporarily?
  • Import seems to have no independent check.

Venue

#  id             :integer         not null, primary key
#  title          :string(255)
#  description    :text
#  address        :string(255)
#  url            :string(255)
#  created_at     :datetime
#  updated_at     :datetime
#  street_address :string(255)
#  locality       :string(255)
#  region         :string(255)
#  postal_code    :string(255)
#  country        :string(255)
#  latitude       :float
#  longitude      :float
#  email          :string(255)
#  telephone      :string(255)
  • url - not currently validated, but should be. Could validate url syntax by URI.parse(url). Could also get a response code and check it for success. But what if non-success is a temporary problem, i.e., the domain is down only temporarily?
  • postal_code - Consider validating as follows. If country == (nil or "US" or "USA" or "United States") then zip should be 5 digits, 9 digits, or 5 digits '-' 4 digits. The reason for making it this complex is the possibility of getting Canadian or other non-US venues.
  • latitude and longitude - Venue class currently
  validates_inclusion_of :latitude, :longitude, 
    :allow_nil => true,
    :in => -180..180,
    :message => "must be between -180 and 180"

But does this create a problem with imported venues? I.e., they won't be saved at all if latitude or longitude is invalid. Instead, when attempting to import an event, each of latitude and longitude should be tested and set to nil if invalid. Then the venue will be saved. email - Not currently validated. Can and should do some rough syntactic checking. Could also do a DNS lookup to see if hostname accepts email. WIKI PARSE WARNING: unterminated '*'! telephone - ? Probably don't validate. Lots of syntaxes are possible, and Calagator doesn't do anything with this except display it. WIKI PARSE WARNING: unterminated '*'! others are either (a) created by Calagator or (b) shouldn't be validated because so many syntaxes / ranges are possible.WIKI PARSE WARNING: unterminated '*'!

*To do: See if these are handled differently by import*

Source

#  id          :integer         not null, primary key
#  title       :string(255)
#  url         :string(255)
#  imported_at :datetime
#  created_at  :datetime
#  updated_at  :datetime
  • Currently validates url syntax by URI.parse(url). In Import, also tries to import, so validates url substance.
  • Other attributes are created by Calagator