agenda-libre-ruby/test/controllers/moderations_controller_test.rb

115 lines
2.8 KiB
Ruby
Raw Normal View History

2014-01-06 11:22:39 +01:00
require 'test_helper'
# Event management, moderation means refusal, acceptation or demands for more
# information
2014-01-06 11:22:39 +01:00
class ModerationsControllerTest < ActionController::TestCase
2014-07-01 15:50:39 +02:00
include Devise::TestHelpers
setup do
@moderation = events :one
sign_in users(:one)
end
2014-09-03 02:14:21 +02:00
test 'should get index' do
get :index
assert_response :success
assert_not_nil assigns(:events)
end
test 'should preview event' do
patch :preview, id: @moderation, event: {
title: 'hello world',
region: regions(:region_one)
}
end
2014-07-01 15:50:39 +02:00
test 'should edit event' do
put :update, id: @moderation, event: {
title: 'hello world',
region: regions(:region_one)
2014-07-01 15:50:39 +02:00
}
assert_redirected_to :moderations
2014-07-01 15:50:39 +02:00
end
2014-09-03 02:14:21 +02:00
test 'should not edit event' do
put :update, id: @moderation, event: {
title: nil
}
assert_not_empty assigns(:moderation).errors
end
2014-07-01 15:50:39 +02:00
test 'should accept event' do
@moderation = events :proposed
decision = @moderation.decision_time
assert !@moderation.moderated?
assert_difference 'Event.moderated.count' do
put :accept, id: @moderation
end
2014-07-01 15:50:39 +02:00
assert assigns(:moderation).moderated?
2014-07-01 15:50:39 +02:00
assert_empty assigns(:moderation).errors
assert decision < assigns(:moderation).decision_time
assert_redirected_to :moderations
2014-07-01 15:50:39 +02:00
end
test 'should update event' do
# Added so paper trail can have some bit of history
patch :update, id: @moderation, event: { title: 'hop hop' }
patch :update, id: @moderation, 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
tags: @moderation.tags
}
assert_empty assigns(:moderation).errors
assert_redirected_to :moderations
end
2014-09-03 02:14:21 +02:00
test 'should not update event' do
patch :update, id: @moderation, event: {
2014-09-03 02:14:21 +02:00
title: nil
}
assert_not_empty assigns(:moderation).errors
end
test 'can not update event concurrently' do
patch :update, id: @moderation, event: {
lock_version: @moderation.lock_version - 1
}
assert_redirected_to edit_moderation_path @moderation
end
2014-07-01 15:50:39 +02:00
test 'should reject event' do
assert_difference 'Event.count', -1 do
2016-09-11 19:13:10 +02:00
delete :destroy, id: @moderation, 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
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
2016-09-11 19:13:10 +02:00
delete :destroy, id: @moderation, reason: 'r_4', event: { reason: 'bye' }
2014-09-03 02:14:21 +02:00
end
2016-09-11 19:13:10 +02:00
assert_not_empty assigns(:moderation).reason
2014-09-03 02:14:21 +02:00
assert_empty assigns(:moderation).errors
assert_redirected_to :moderations
2014-09-03 02:14:21 +02:00
end
2014-01-06 11:22:39 +01:00
end