Meilleure validation des événements

This commit is contained in:
echarp 2014-05-26 01:06:43 +02:00
parent b13af2ea6a
commit 090620a873
8 changed files with 48 additions and 24 deletions

View File

@ -59,6 +59,7 @@ gem 'i18n-active_record',
git: 'git://github.com/svenfuchs/i18n-active_record.git', git: 'git://github.com/svenfuchs/i18n-active_record.git',
require: 'i18n/active_record' require: 'i18n/active_record'
gem 'font-awesome-rails' gem 'font-awesome-rails'
gem 'email_validator'
gem 'simple_calendar', github: 'echarp/simple_calendar' gem 'simple_calendar', github: 'echarp/simple_calendar'
#gem 'simple_calendar', github: 'excid3/simple_calendar', branch: '1.0' #gem 'simple_calendar', github: 'excid3/simple_calendar', branch: '1.0'

View File

@ -7,7 +7,7 @@ GIT
GIT GIT
remote: git://github.com/gregbell/active_admin.git remote: git://github.com/gregbell/active_admin.git
revision: 27c570994c1c58b070a3a2b97d9f67fb41b78ce9 revision: 0af41dfdcab1f3974814d27d0b6f32929a0c682d
specs: specs:
activeadmin (1.0.0.pre) activeadmin (1.0.0.pre)
arbre (~> 1.0) arbre (~> 1.0)
@ -62,7 +62,7 @@ GEM
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
arel (5.0.1.20140414130214) arel (5.0.1.20140414130214)
bcrypt (3.1.7) bcrypt (3.1.7)
bourbon (3.2.1) bourbon (3.2.3)
sass (~> 3.2) sass (~> 3.2)
thor thor
builder (3.2.2) builder (3.2.2)
@ -94,13 +94,15 @@ GEM
em-websocket (0.5.1) em-websocket (0.5.1)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0) http_parser.rb (~> 0.6.0)
email_validator (1.4.0)
activemodel
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.0.3) eventmachine (1.0.3)
execjs (2.0.2) execjs (2.0.2)
ffi (1.9.3) ffi (1.9.3)
font-awesome-rails (4.1.0.0) font-awesome-rails (4.1.0.0)
railties (>= 3.2, < 5.0) railties (>= 3.2, < 5.0)
formatador (0.2.4) formatador (0.2.5)
formtastic (2.3.0.rc3) formtastic (2.3.0.rc3)
actionpack (>= 3.0) actionpack (>= 3.0)
fssm (0.2.10) fssm (0.2.10)
@ -114,7 +116,7 @@ GEM
guard-bundler (2.0.0) guard-bundler (2.0.0)
bundler (~> 1.0) bundler (~> 1.0)
guard (~> 2.2) guard (~> 2.2)
guard-livereload (2.1.2) guard-livereload (2.2.0)
em-websocket (~> 0.5) em-websocket (~> 0.5)
guard (~> 2.0) guard (~> 2.0)
multi_json (~> 1.8) multi_json (~> 1.8)
@ -164,7 +166,7 @@ GEM
mime-types (1.25.1) mime-types (1.25.1)
minitest (5.3.4) minitest (5.3.4)
modernizr-rails (2.7.1) modernizr-rails (2.7.1)
multi_json (1.10.0) multi_json (1.10.1)
mysql2 (0.3.16) mysql2 (0.3.16)
openlayers-rails (0.0.4) openlayers-rails (0.0.4)
railties (>= 3.1) railties (>= 3.1)
@ -261,6 +263,7 @@ DEPENDENCIES
compass-rails compass-rails
devise devise
devise-i18n devise-i18n
email_validator
font-awesome-rails font-awesome-rails
gritter gritter
guard-bundler guard-bundler

View File

@ -108,6 +108,11 @@ main
vertical-align: baseline vertical-align: baseline
background-color: buttonface background-color: buttonface
.field_with_errors
display: inline
input, textarea, select, a.button
background-color: pink
/* /*
input, textarea, select input, textarea, select
color: black color: black

View File

@ -3,7 +3,10 @@ class Event < ActiveRecord::Base
has_many :notes has_many :notes
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
validates_presence_of :region validates_presence_of :title, :description, :city, :region, :url, :contact, :submitter
validates_format_of :url, with: /https?:\/\//
validates :contact, email: true
validates :submitter, email: true
default_scope { where moderated: 1 } default_scope { where moderated: 1 }

View File

@ -19,21 +19,21 @@
.field .field
.helper= raw markdown.render t '.title_helper' .helper= raw markdown.render t '.title_helper'
= f.label :title = f.label :title
= f.text_field :title, size: 70 = f.text_field :title, required: true, size: 70
.field .field
= f.label Event.human_attribute_name :start_time = f.label Event.human_attribute_name :start_time
= f.datetime_select :start_time = f.datetime_select :start_time, required: true
.field .field
= f.label Event.human_attribute_name :end_time = f.label Event.human_attribute_name :end_time
= f.datetime_select :end_time = f.datetime_select :end_time, required: true
.field .field
.helper= raw markdown.render t '.description_helper' .helper= raw markdown.render t '.description_helper'
= f.label Event.human_attribute_name :description = f.label Event.human_attribute_name :description
= f.text_area :description, rows: 29, cols: 80 = f.text_area :description, required: true, rows: 29, cols: 80
.field .field
= f.label Event.human_attribute_name :city = f.label Event.human_attribute_name :city
= f.text_field :city, size: 70 = f.text_field :city, required: true, size: 70
.field .field
= f.label Event.human_attribute_name :region = f.label Event.human_attribute_name :region
= f.select :region, = f.select :region,
@ -45,15 +45,15 @@
.field .field
.helper= raw markdown.render t '.url_helper' .helper= raw markdown.render t '.url_helper'
= f.label Event.human_attribute_name :url = f.label Event.human_attribute_name :url
= f.text_field :url, size: 70 = f.text_field :url, required: true, size: 70
.field .field
.helper= raw markdown.render t '.contact_helper' .helper= raw markdown.render t '.contact_helper'
= f.label Event.human_attribute_name :contact = f.label Event.human_attribute_name :contact
= f.text_field :contact, size: 70 = f.text_field :contact, required: true, size: 70
.field .field
.helper= raw markdown.render t '.submitter_helper' .helper= raw markdown.render t '.submitter_helper'
= f.label :submitter = f.label :submitter
= f.text_field :submitter, size: 70 = f.text_field :submitter, required: true, size: 70
.field .field
.helper= raw markdown.render t '.tags_helper' .helper= raw markdown.render t '.tags_helper'
= f.label :tags = f.label :tags

View File

@ -29,7 +29,6 @@ class EventsControllerTest < ActionController::TestCase
url: @event.url, url: @event.url,
contact: @event.contact, contact: @event.contact,
submitter: @event.submitter, submitter: @event.submitter,
submitter_mail_id: @event.submitter_mail_id,
tags: @event.tags tags: @event.tags
} }
end end
@ -50,7 +49,6 @@ class EventsControllerTest < ActionController::TestCase
url: @event.url, url: @event.url,
contact: @event.contact, contact: @event.contact,
submitter: @event.submitter, submitter: @event.submitter,
submitter_mail_id: @event.submitter_mail_id,
tags: @event.tags tags: @event.tags
} }
end end

View File

@ -8,9 +8,9 @@ one:
city: Jolie ville city: Jolie ville
region: region_one region: region_one
locality: 1 locality: 1
url: MyString url: http://exemple.com
contact: MyString contact: test@example.com
submitter: MyString submitter: test@example.com
moderated: 1 moderated: 1
tags: MyString tags: MyString
secret: MyString secret: MyString
@ -27,9 +27,9 @@ two:
city: Une autre ville city: Une autre ville
region: region_one region: region_one
locality: 1 locality: 1
url: MyString url: http://exemple.com
contact: MyString contact: test2@example.com
submitter: MyString submitter: test2@example.com
moderated: 1 moderated: 1
tags: MyString tags: MyString
secret: MyString secret: MyString

View File

@ -7,13 +7,27 @@ class EventTest < ActiveSupport::TestCase
start_time: Time.new(), start_time: Time.new(),
end_time: Time.new() + 1, end_time: Time.new() + 1,
description: 'et hop!', description: 'et hop!',
region: Region.first() city: City.first().name,
region: Region.first(),
url: 'http://example.com',
contact: 'test@example.com',
submitter: 'test@example.com'
) )
assert @event.save() assert @event.save(), @event.errors.messages
assert_equal 32, @event.secret.size() assert_equal 32, @event.secret.size()
assert_equal 32, @event.moderator_mail_id.size() assert_equal 32, @event.moderator_mail_id.size()
assert_equal 32, @event.submitter_mail_id.size() assert_equal 32, @event.submitter_mail_id.size()
# Check invalid url
@event.url = 'htt://truc.com'
assert !@event.valid?
@event.url = 'http:/truc.com'
assert !@event.valid?
@event.contact = 'hop@@@'
assert !@event.valid?
end end
end end