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

132 lines
3.1 KiB
Ruby
Raw Normal View History

2013-12-28 23:45:13 +01:00
require 'test_helper'
# Event life cycle
2013-12-28 23:45:13 +01:00
class EventsControllerTest < ActionController::TestCase
2016-09-19 21:58:50 +02:00
include Devise::Test::ControllerHelpers
2014-07-01 15:50:39 +02:00
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
2013-12-28 23:45:13 +01:00
get :index
assert_response :success
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
2013-12-28 23:45:13 +01:00
get :new
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
2014-09-02 01:02:51 +02:00
post :preview_create, event: {
title: @event.title,
start_time: @event.start_time, end_time: @event.end_time,
description: @event.description,
city: @event.city, region_id: @event.region.id,
url: @event.url, contact: @event.contact, tags: @event.tags
}
2014-07-01 15:50:39 +02:00
assert_empty assigns(:event).errors
end
assert_response :success
end
2014-07-01 15:50:39 +02:00
test 'should create event' do
assert_difference 'Event.count' do
post :create, event: {
title: @event.title,
start_time: @event.start_time, end_time: @event.end_time,
description: @event.description,
city: @event.city, region_id: @event.region.id,
url: @event.url,
contact: @event.contact,
tags: @event.tags
}
2014-07-01 15:50:39 +02:00
assert_empty assigns(:event).errors.messages
2013-12-28 23:45:13 +01:00
end
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
post :create, event: {
title: @event.title, start_time: @event.start_time, tags: @event.tags
}
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
2013-12-28 23:45:13 +01:00
get :show, id: @event
assert_response :success
end
2014-07-01 15:50:39 +02:00
test 'should get edit' do
get :edit, id: @event, 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
get :edit, id: @event
assert_redirected_to :root
end
2014-09-02 01:02:51 +02:00
test 'should preview' do
assert_no_difference 'Event.count' do
patch :preview, id: @event, secret: @event.secret, event: {
2014-09-02 01:02:51 +02:00
title: @event.title
}
assert_empty assigns(:event).errors
end
assert_response :success
end
2014-07-01 15:50:39 +02:00
test 'should update event' do
patch :update, id: @event, secret: @event.secret, event: {
2014-09-02 01:02:51 +02:00
title: @event.title
}
2014-07-01 15:50:39 +02:00
assert_empty assigns(:event).errors.messages
assert_redirected_to :root
2013-12-28 23:45:13 +01:00
end
2014-09-03 02:14:21 +02:00
test 'should not update event' do
patch :update, id: @event, secret: @event.secret, event: { title: nil }
2014-09-03 02:14:21 +02:00
assert_not_empty assigns(:event).errors.messages
end
test 'can not update event concurrently' do
patch :update, id: @event, secret: @event.secret, event: {
lock_version: @event.lock_version - 1
}
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
get :cancel, id: @event, secret: @event.secret
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
delete :destroy, id: @event, secret: @event.secret, event: {
reason: 'bye'
}
2013-12-28 23:45:13 +01:00
end
assert_equal 'bye', assigns(:event).reason
assert_redirected_to :root
2013-12-28 23:45:13 +01:00
end
end