Les heures de soumission et de validation d'evt étaient mal gérées

This commit is contained in:
echarp 2014-07-28 16:16:27 +02:00
parent c6ab829578
commit e866578b9e
5 changed files with 59 additions and 4 deletions

View File

@ -32,8 +32,8 @@ class Event < ActiveRecord::Base
before_validation on: :create do
self.submission_time = Date.today
self.decision_time = Date.today
self.submission_time = DateTime.now
self.decision_time = DateTime.now
if self.submitter.empty?
self.submitter = self.contact
@ -46,6 +46,12 @@ class Event < ActiveRecord::Base
self.submitter_mail_id = SecureRandom.urlsafe_base64(32)[0...32]
end
before_update do
if moderated? and moderated_was != moderated
self.decision_time = DateTime.now
end
end
def same_day?
start_time.to_date == end_time.to_date
end

View File

@ -33,7 +33,7 @@
=l event.end_time, format: :at
%td= event.city
%td= event.related_region.name
%td= time_ago_in_words event.submission_time.to_date
%td= time_ago_in_words event.submission_time
%th.actions
= link_to edit_moderation_path event do
%em.fa.fa-pencil

View File

@ -18,10 +18,20 @@ class ModerationsControllerTest < ActionController::TestCase
end
test 'should accept event' do
put :accept, id: @moderation
@moderation = events :proposed
decision = @moderation.decision_time
assert !@moderation.moderated?
assert_difference 'Event.moderated.count' do
put :accept, id: @moderation
end
assert assigns(:moderation).moderated?
assert_empty assigns(:moderation).errors
assert decision < assigns(:moderation).decision_time
assert_redirected_to moderations_path
end

View File

@ -37,3 +37,22 @@ two:
submission_time: 2013-12-28 16:04:56
moderator_mail_id: MyString
submitter_mail_id: MyString
proposed:
title: MyString
description: MyText
start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 16:04:56
city: city_two.name
related_region: region_two
locality: 1
url: http://exemple.com
contact: test2@example.com
submitter: test2@example.com
moderated: 0
tags: MyString
secret: MyString
decision_time: 2013-12-28 16:04:56
submission_time: 2013-12-28 16:04:56
moderator_mail_id: MyString
submitter_mail_id: MyString

View File

@ -48,4 +48,24 @@ class EventTest < ActiveSupport::TestCase
@event.url = 'http:/truc.com'
assert !@event.valid?, @event.errors.messages
end
test 'moderation' do
@event = Event.new(
title: 'hello world',
start_time: Time.new(),
end_time: Time.new() + 1,
description: 'et hop!',
city: City.first(),
related_region: Region.first(),
url: 'http://example.com',
contact: 'contact@example.com'
)
assert @event.save(), @event.errors.messages
assert !@event.moderated?
@event.update(moderated: 1)
assert @event.moderated?, @event.errors.messages
end
end