diff --git a/Gemfile b/Gemfile index bfdd3d06..17258886 100644 --- a/Gemfile +++ b/Gemfile @@ -84,6 +84,9 @@ gem 'geocoder' gem 'tinymce-rails' gem 'tinymce-rails-langs' +# Remove leading and trailing white spaces +gem 'strip_attributes' + # SEO optimisations gem 'meta-tags' diff --git a/Gemfile.lock b/Gemfile.lock index df19c725..08a85b55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -341,6 +341,8 @@ GEM activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) sqlite3 (1.3.10) + strip_attributes (1.5.1) + activemodel (>= 3.0, < 5.0) sysexits (1.2.0) temple (0.6.10) terminal-table (1.4.5) @@ -429,6 +431,7 @@ DEPENDENCIES simplecov spring sqlite3 + strip_attributes therubyracer tinymce-rails tinymce-rails-langs diff --git a/app/models/event.rb b/app/models/event.rb index bc198d21..2c349bcd 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -3,6 +3,7 @@ # This is the central ADL class, where are managed all events class Event < ActiveRecord::Base extend SimpleCalendar + strip_attributes belongs_to :related_region, foreign_key: 'region', class_name: Region has_many :notes, dependent: :destroy @@ -55,7 +56,8 @@ class Event < ActiveRecord::Base self.submission_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 before_validation on: :update do diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb index 62f27cb7..ef22452b 100644 --- a/test/controllers/events_controller_test.rb +++ b/test/controllers/events_controller_test.rb @@ -46,7 +46,8 @@ class EventsControllerTest < ActionController::TestCase city: @event.city, region: @event.related_region, url: @event.url, - contact: @event.contact + contact: @event.contact, + tags: @event.tags } assert_empty assigns(:event).errors.messages diff --git a/test/models/event_test.rb b/test/models/event_test.rb index f6a083f8..f81c7ed0 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -16,7 +16,8 @@ class EventTest < ActiveSupport::TestCase related_region: Region.first, url: 'http://example.com', contact: 'contact@example.com', - submitter: 'submitter@example.com' + submitter: 'submitter@example.com', + tags: 'hello world' ) assert @event.save, @event.errors.messages @@ -34,7 +35,8 @@ class EventTest < ActiveSupport::TestCase city: City.first, related_region: Region.first, url: 'http://example.com', - contact: 'contact@example.com' + contact: 'contact@example.com', + tags: 'hello world' ) assert @event.valid?, @event.errors.messages @@ -63,7 +65,8 @@ class EventTest < ActiveSupport::TestCase city: City.first, related_region: Region.first, url: 'http://example.com', - contact: 'contact@example.com' + contact: 'contact@example.com', + tags: 'hello world' ) assert @event.save, @event.errors.messages