2013-12-28 23:45:13 +01:00
|
|
|
require 'test_helper'
|
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Event life cycle
|
2018-01-01 17:52:33 +01:00
|
|
|
class EventsControllerTest < ActionDispatch::IntegrationTest
|
2013-12-28 23:45:13 +01:00
|
|
|
setup do
|
2014-07-01 15:50:39 +02:00
|
|
|
@event = events :one
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should get index' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get events_url
|
2013-12-28 23:45:13 +01:00
|
|
|
assert_response :success
|
2014-10-11 16:12:07 +02:00
|
|
|
assert_not_nil assigns :events
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should get new' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get new_event_url
|
2013-12-28 23:45:13 +01:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2014-09-02 01:02:51 +02:00
|
|
|
test 'should preview event creation' do
|
2014-07-01 15:50:39 +02:00
|
|
|
assert_no_difference 'Event.count' do
|
2018-01-01 17:52:33 +01:00
|
|
|
post preview_events_url, params: { event: {
|
2014-01-01 21:26:35 +01:00
|
|
|
title: @event.title,
|
2014-10-11 16:12:07 +02:00
|
|
|
start_time: @event.start_time, end_time: @event.end_time,
|
2014-01-01 21:26:35 +01:00
|
|
|
description: @event.description,
|
2015-02-15 15:50:47 +01:00
|
|
|
city: @event.city, region_id: @event.region.id,
|
2016-12-17 16:59:11 +01:00
|
|
|
url: @event.url, contact: @event.contact, tag_list: 'helo world'
|
2018-01-01 17:52:33 +01:00
|
|
|
} }
|
2014-07-01 15:50:39 +02:00
|
|
|
|
|
|
|
assert_empty assigns(:event).errors
|
2014-01-01 21:26:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should create event' do
|
|
|
|
assert_difference 'Event.count' do
|
2018-01-01 17:52:33 +01:00
|
|
|
post events_url, params: { event: {
|
2014-01-01 21:26:35 +01:00
|
|
|
title: @event.title,
|
2014-10-11 16:12:07 +02:00
|
|
|
start_time: @event.start_time, end_time: @event.end_time,
|
2014-01-01 21:26:35 +01:00
|
|
|
description: @event.description,
|
2015-02-15 15:50:47 +01:00
|
|
|
city: @event.city, region_id: @event.region.id,
|
2018-01-01 17:52:33 +01:00
|
|
|
url: @event.url, contact: @event.contact, tag_list: 'helo world'
|
|
|
|
} }
|
2014-07-01 15:50:39 +02:00
|
|
|
|
|
|
|
assert_empty assigns(:event).errors.messages
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :root
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|
|
|
|
|
2014-09-03 02:14:21 +02:00
|
|
|
test 'should not create event' do
|
|
|
|
assert_no_difference 'Event.count' do
|
2018-01-01 17:52:33 +01:00
|
|
|
post events_url, params: {
|
|
|
|
event: { title: @event.title, start_time: @event.start_time }
|
2015-04-04 16:27:59 +02:00
|
|
|
}
|
2014-09-03 02:14:21 +02:00
|
|
|
|
|
|
|
assert_not_empty assigns(:event).errors.messages
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should show event' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get event_url(@event)
|
2013-12-28 23:45:13 +01:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should get edit' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get edit_event_url(@event), params: { secret: @event.secret }
|
2013-12-28 23:45:13 +01:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should not get edit' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get edit_event_url(@event)
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :root
|
2014-05-25 23:59:03 +02:00
|
|
|
end
|
|
|
|
|
2014-09-02 01:02:51 +02:00
|
|
|
test 'should preview' do
|
|
|
|
assert_no_difference 'Event.count' do
|
2018-01-01 17:52:33 +01:00
|
|
|
patch preview_event_url(@event), params: {
|
|
|
|
secret: @event.secret, event: { title: @event.title }
|
2014-09-02 01:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_empty assigns(:event).errors
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should update event' do
|
2018-01-01 17:52:33 +01:00
|
|
|
patch event_url(@event), params: {
|
|
|
|
secret: @event.secret, event: { title: @event.title }
|
2014-09-02 01:02:51 +02:00
|
|
|
}
|
2014-07-01 15:50:39 +02:00
|
|
|
|
|
|
|
assert_empty assigns(:event).errors.messages
|
2018-03-17 16:53:38 +01:00
|
|
|
assert_redirected_to event_url(@event)
|
2013-12-28 23:45:13 +01: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 event_url(@event), params: {
|
|
|
|
secret: @event.secret, event: { title: nil }
|
|
|
|
}
|
2014-09-03 02:14:21 +02:00
|
|
|
|
|
|
|
assert_not_empty assigns(:event).errors.messages
|
|
|
|
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 event_url(@event), params: {
|
|
|
|
secret: @event.secret, event: { lock_version: @event.lock_version - 1 }
|
2014-10-11 16:12:07 +02:00
|
|
|
}
|
|
|
|
assert_redirected_to edit_event_url(@event, secret: @event.secret)
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should get cancel page' do
|
2018-01-01 17:52:33 +01:00
|
|
|
get cancel_event_url(@event), params: { secret: @event.secret }
|
2014-05-25 23:59:03 +02:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:50:39 +02:00
|
|
|
test 'should destroy event' do
|
2013-12-28 23:45:13 +01:00
|
|
|
assert_difference('Event.count', -1) do
|
2018-01-01 17:52:33 +01:00
|
|
|
delete event_url(@event), params: {
|
|
|
|
secret: @event.secret, event: { reason: 'bye' }
|
2016-09-17 19:41:29 +02:00
|
|
|
}
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|
|
|
|
|
2016-09-17 19:41:29 +02:00
|
|
|
assert_equal 'bye', assigns(:event).reason
|
2014-11-05 21:25:18 +01:00
|
|
|
assert_redirected_to :root
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|
|
|
|
end
|