2014-01-06 11:22:39 +01:00
|
|
|
require 'test_helper'
|
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Event management, moderation means refusal, acceptation or demands for more
|
|
|
|
# information
|
2018-01-01 17:52:33 +01:00
|
|
|
class ModerationsControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
include Devise::Test::IntegrationHelpers
|
2014-07-01 15:50:39 +02:00
|
|
|
|
|
|
|
setup do
|
|
|
|
@moderation = events :one
|
|
|
|
|
|
|
|
sign_in users(:one)
|
|
|
|
end
|
|
|
|
|
2014-09-03 02:14:21 +02:00
|
|
|
test 'should get index' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get moderations_url
|
2014-09-03 02:14:21 +02:00
|
|
|
assert_response :success
|
|
|
|
assert_not_nil assigns(:events)
|
|
|
|
end
|
|
|
|
|
2014-08-09 18:59:11 +02:00
|
|
|
test 'should preview event' do
|
2018-01-01 17:52:33 +01:00
|
|
|
patch moderation_url(@moderation), params: {
|
|
|
|
event: {
|
|
|
|
title: 'hello world',
|
|
|
|
region: regions(:region_one)
|
|
|
|
}
|
2014-08-09 18:59:11 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should edit event' do
|
2018-01-01 17:52:33 +01:00
|
|
|
put moderation_url(@moderation), params: {
|
|
|
|
event: {
|
|
|
|
title: 'hello world',
|
|
|
|
region: regions(:region_one)
|
|
|
|
}
|
2014-07-01 15:50:39 +02:00
|
|
|
}
|
2018-01-01 17:52:33 +01:00
|
|
|
assert_redirected_to moderations_url
|
2014-07-01 15:50:39 +02:00
|
|
|
end
|
|
|
|
|
2014-09-03 02:14:21 +02:00
|
|
|
test 'should not edit event' do
|
2018-01-01 17:52:33 +01:00
|
|
|
put moderation_url(@moderation), params: { event: { title: nil } }
|
2014-09-03 02:14:21 +02:00
|
|
|
assert_not_empty assigns(:moderation).errors
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should accept event' do
|
2014-07-28 16:16:27 +02:00
|
|
|
@moderation = events :proposed
|
|
|
|
|
|
|
|
decision = @moderation.decision_time
|
2018-05-23 09:25:12 +02:00
|
|
|
assert_not @moderation.moderated?
|
2014-07-28 16:16:27 +02:00
|
|
|
|
|
|
|
assert_difference 'Event.moderated.count' do
|
2018-01-01 17:52:33 +01:00
|
|
|
put accept_moderation_url(@moderation)
|
2014-07-28 16:16:27 +02:00
|
|
|
end
|
2014-07-01 15:50:39 +02:00
|
|
|
|
2014-07-07 13:14:17 +02:00
|
|
|
assert assigns(:moderation).moderated?
|
2014-07-01 15:50:39 +02:00
|
|
|
assert_empty assigns(:moderation).errors
|
2014-07-28 16:16:27 +02:00
|
|
|
|
|
|
|
assert decision < assigns(:moderation).decision_time
|
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :moderations
|
2014-07-01 15:50:39 +02:00
|
|
|
end
|
|
|
|
|
2014-07-20 21:46:28 +02:00
|
|
|
test 'should update event' do
|
2015-09-05 18:56:48 +02:00
|
|
|
# Added so paper trail can have some bit of history
|
2018-01-01 17:52:33 +01:00
|
|
|
patch moderation_url(@moderation), params: { event: { title: 'hop hop' } }
|
|
|
|
patch moderation_url(@moderation), params: {
|
|
|
|
event: {
|
|
|
|
title: @moderation.title,
|
|
|
|
start_time: @moderation.start_time, end_time: @moderation.end_time,
|
|
|
|
description: @moderation.description,
|
|
|
|
url: @moderation.url,
|
|
|
|
contact: @moderation.contact
|
|
|
|
}
|
2014-09-03 02:14:21 +02:00
|
|
|
}
|
2014-07-20 21:46:28 +02:00
|
|
|
|
|
|
|
assert_empty assigns(:moderation).errors
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :moderations
|
2014-07-20 21:46:28 +02:00
|
|
|
end
|
|
|
|
|
2014-09-03 02:14:21 +02:00
|
|
|
test 'should not update event' do
|
2018-01-01 17:52:33 +01:00
|
|
|
patch moderation_url(@moderation), params: { event: { title: nil } }
|
2014-09-03 02:14:21 +02:00
|
|
|
|
|
|
|
assert_not_empty assigns(:moderation).errors
|
|
|
|
end
|
|
|
|
|
2014-10-11 16:12:07 +02:00
|
|
|
test 'can not update event concurrently' do
|
2018-01-01 17:52:33 +01:00
|
|
|
patch moderation_url(@moderation), params: {
|
|
|
|
event: { lock_version: @moderation.lock_version - 1 }
|
2014-10-11 16:12:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_redirected_to edit_moderation_path @moderation
|
|
|
|
end
|
|
|
|
|
2017-05-06 15:46:22 +02:00
|
|
|
test 'should reject spam' do
|
|
|
|
assert_difference 'Event.count', -1 do
|
2018-01-01 17:52:33 +01:00
|
|
|
delete moderation_url(@moderation), params: {
|
|
|
|
reason: 'r_0', event: { reason: '' }
|
|
|
|
}
|
2017-05-06 15:46:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_not_empty assigns(:moderation).reason
|
|
|
|
assert_empty assigns(:moderation).errors
|
|
|
|
|
|
|
|
assert_redirected_to :moderations
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should reject event' do
|
|
|
|
assert_difference 'Event.count', -1 do
|
2018-01-01 17:52:33 +01:00
|
|
|
delete moderation_url(@moderation), params: {
|
|
|
|
reason: 'r_1', event: { reason: '' }
|
|
|
|
}
|
2014-07-01 15:50:39 +02:00
|
|
|
end
|
|
|
|
|
2016-09-11 19:13:10 +02:00
|
|
|
assert_not_empty assigns(:moderation).reason
|
2014-07-01 15:50:39 +02:00
|
|
|
assert_empty assigns(:moderation).errors
|
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :moderations
|
2014-07-01 15:50:39 +02:00
|
|
|
end
|
2014-09-03 02:14:21 +02:00
|
|
|
|
|
|
|
test 'should reject event with a reason' do
|
|
|
|
assert_difference 'Event.count', -1 do
|
2018-01-01 17:52:33 +01:00
|
|
|
delete moderation_url(@moderation), params: {
|
|
|
|
reason: 'r_4', event: { reason: 'bye' }
|
|
|
|
}
|
2014-09-03 02:14:21 +02:00
|
|
|
end
|
|
|
|
|
2016-09-17 19:41:29 +02:00
|
|
|
assert_equal 'bye', assigns(:moderation).reason
|
2014-09-03 02:14:21 +02:00
|
|
|
assert_empty assigns(:moderation).errors
|
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :moderations
|
2014-09-03 02:14:21 +02:00
|
|
|
end
|
2014-01-06 11:22:39 +01:00
|
|
|
end
|