Strip white spaces from event attributes

This commit is contained in:
echarp 2014-12-14 13:29:52 +01:00
parent 3056e20c68
commit fb86f09254
5 changed files with 17 additions and 5 deletions

View File

@ -84,6 +84,9 @@ gem 'geocoder'
gem 'tinymce-rails' gem 'tinymce-rails'
gem 'tinymce-rails-langs' gem 'tinymce-rails-langs'
# Remove leading and trailing white spaces
gem 'strip_attributes'
# SEO optimisations # SEO optimisations
gem 'meta-tags' gem 'meta-tags'

View File

@ -341,6 +341,8 @@ GEM
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10) sqlite3 (1.3.10)
strip_attributes (1.5.1)
activemodel (>= 3.0, < 5.0)
sysexits (1.2.0) sysexits (1.2.0)
temple (0.6.10) temple (0.6.10)
terminal-table (1.4.5) terminal-table (1.4.5)
@ -429,6 +431,7 @@ DEPENDENCIES
simplecov simplecov
spring spring
sqlite3 sqlite3
strip_attributes
therubyracer therubyracer
tinymce-rails tinymce-rails
tinymce-rails-langs tinymce-rails-langs

View File

@ -3,6 +3,7 @@
# This is the central ADL class, where are managed all events # This is the central ADL class, where are managed all events
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
extend SimpleCalendar extend SimpleCalendar
strip_attributes
belongs_to :related_region, foreign_key: 'region', class_name: Region belongs_to :related_region, foreign_key: 'region', class_name: Region
has_many :notes, dependent: :destroy has_many :notes, dependent: :destroy
@ -55,7 +56,8 @@ class Event < ActiveRecord::Base
self.submission_time = DateTime.now self.submission_time = DateTime.now
self.decision_time = DateTime.now self.decision_time = DateTime.now
self.submitter = contact if submitter.empty? # Populate submitter using contact info if absent
self.submitter ||= contact
end end
before_validation on: :update do before_validation on: :update do

View File

@ -46,7 +46,8 @@ class EventsControllerTest < ActionController::TestCase
city: @event.city, city: @event.city,
region: @event.related_region, region: @event.related_region,
url: @event.url, url: @event.url,
contact: @event.contact contact: @event.contact,
tags: @event.tags
} }
assert_empty assigns(:event).errors.messages assert_empty assigns(:event).errors.messages

View File

@ -16,7 +16,8 @@ class EventTest < ActiveSupport::TestCase
related_region: Region.first, related_region: Region.first,
url: 'http://example.com', url: 'http://example.com',
contact: 'contact@example.com', contact: 'contact@example.com',
submitter: 'submitter@example.com' submitter: 'submitter@example.com',
tags: 'hello world'
) )
assert @event.save, @event.errors.messages assert @event.save, @event.errors.messages
@ -34,7 +35,8 @@ class EventTest < ActiveSupport::TestCase
city: City.first, city: City.first,
related_region: Region.first, related_region: Region.first,
url: 'http://example.com', url: 'http://example.com',
contact: 'contact@example.com' contact: 'contact@example.com',
tags: 'hello world'
) )
assert @event.valid?, @event.errors.messages assert @event.valid?, @event.errors.messages
@ -63,7 +65,8 @@ class EventTest < ActiveSupport::TestCase
city: City.first, city: City.first,
related_region: Region.first, related_region: Region.first,
url: 'http://example.com', url: 'http://example.com',
contact: 'contact@example.com' contact: 'contact@example.com',
tags: 'hello world'
) )
assert @event.save, @event.errors.messages assert @event.save, @event.errors.messages