Meilleure validation des événements

recurrent
echarp 8 years ago
parent b13af2ea6a
commit 090620a873
  1. 1
      Gemfile
  2. 13
      Gemfile.lock
  3. 5
      app/assets/stylesheets/all.css.sass
  4. 5
      app/models/event.rb
  5. 16
      app/views/events/_form.html.haml
  6. 2
      test/controllers/events_controller_test.rb
  7. 12
      test/fixtures/events.yml
  8. 18
      test/models/event_test.rb

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

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

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

@ -3,7 +3,10 @@ class Event < ActiveRecord::Base
has_many :notes
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 }

@ -19,21 +19,21 @@
.field
.helper= raw markdown.render t '.title_helper'
= f.label :title
= f.text_field :title, size: 70
= f.text_field :title, required: true, size: 70
.field
= f.label Event.human_attribute_name :start_time
= f.datetime_select :start_time
= f.datetime_select :start_time, required: true
.field
= f.label Event.human_attribute_name :end_time
= f.datetime_select :end_time
= f.datetime_select :end_time, required: true
.field
.helper= raw markdown.render t '.description_helper'
= 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
= f.label Event.human_attribute_name :city
= f.text_field :city, size: 70
= f.text_field :city, required: true, size: 70
.field
= f.label Event.human_attribute_name :region
= f.select :region,
@ -45,15 +45,15 @@
.field
.helper= raw markdown.render t '.url_helper'
= f.label Event.human_attribute_name :url
= f.text_field :url, size: 70
= f.text_field :url, required: true, size: 70
.field
.helper= raw markdown.render t '.contact_helper'
= f.label Event.human_attribute_name :contact
= f.text_field :contact, size: 70
= f.text_field :contact, required: true, size: 70
.field
.helper= raw markdown.render t '.submitter_helper'
= f.label :submitter
= f.text_field :submitter, size: 70
= f.text_field :submitter, required: true, size: 70
.field
.helper= raw markdown.render t '.tags_helper'
= f.label :tags

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

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

@ -7,13 +7,27 @@ class EventTest < ActiveSupport::TestCase
start_time: Time.new(),
end_time: Time.new() + 1,
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.moderator_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

Loading…
Cancel
Save