notebook/test/controllers/magic_controller_test.rb
2015-08-28 00:06:09 -05:00

71 lines
1.5 KiB
Ruby

require 'test_helper'
# Tests for the MagicController class
class MagicControllerTest < ActionController::TestCase
setup do
@user = users(:tolkien)
@other_user = users(:rowling)
@universe = universes(:middleearth)
log_in_user(:tolkien)
end
test 'should get index' do
get :index
assert_response :success
assert_not_nil assigns(:magics)
end
test 'should get new' do
get :new
assert_response :success
end
test 'should create magic' do
assert_difference('Magic.count') do
post :create, magic: { name: 'Magic Rings', universe: @universe }
end
assert_redirected_to magic_path(assigns(:magic))
end
test 'should show magic' do
@magic = magics(:wizard)
get :show, id: @magic.id
assert_response :success
end
test 'should get edit' do
@magic = magics(:wizard)
get :edit, id: @magic.id
assert_response :success
end
test 'should update magic' do
@magic = magics(:wizard)
put :update, id: @magic, magic: { name: 'Maiar Magic', universe: @universe }
assert_response 302
assert_redirected_to magic_path(@magic)
end
test 'should destroy magic' do
assert_difference('Magic.count', -1) do
delete :destroy, id: magics(:wizard).id
end
assert_redirected_to magic_list_url
end
test 'should not be able to destroy magic as stranger' do
log_in_user(:rowling)
assert_difference('Magic.count', 0) do
delete :destroy, id: magics(:wizard).id
end
assert_redirected_to magic_list_url
end
end