adopt-a-hydrant/test/functional/users_controller_test.rb

62 lines
2.0 KiB
Ruby
Raw Normal View History

2011-05-15 23:33:32 +00:00
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
request.env["devise.mapping"] = Devise.mappings[:user]
2011-05-15 23:55:37 +00:00
@user = users(:erik)
2011-05-15 23:33:32 +00:00
end
test 'should render info window' do
sign_in @user
get :edit
assert_response :success
assert_select 'div#info_window', true
assert_select 'form#edit_form' do
assert_select '[action=?]', '/users'
assert_select '[method=?]', 'post'
end
assert_select 'h2', 'Edit your Profile'
assert_select 'input', :count => 14
assert_select 'label', :count => 7
assert_select 'input[name="commit"]' do
assert_select '[type=?]', 'submit'
assert_select '[value=?]', 'Update'
end
assert_select 'form#back_form' do
2011-05-31 11:12:02 +00:00
assert_select '[action=?]', '/info_window'
2011-05-15 23:33:32 +00:00
assert_select '[method=?]', 'get'
end
assert_select 'input[name="commit"]' do
assert_select '[type=?]', 'submit'
assert_select '[value=?]', 'Back'
end
end
test 'should update user if password is correct' do
sign_in @user
2011-05-15 23:55:37 +00:00
assert_not_equal @user.name, 'New Name'
put :update, :user => {:name => 'New Name', :current_password => 'correct'}
2011-05-15 23:33:32 +00:00
@user.reload
2011-05-15 23:55:37 +00:00
assert_equal @user.name, 'New Name'
2011-05-15 23:33:32 +00:00
assert_response :redirect
2011-05-31 11:12:02 +00:00
assert_redirected_to :controller => 'info_window', :action => 'index'
2011-05-15 23:33:32 +00:00
end
test 'should return error if password is incorrect' do
sign_in @user
2011-05-15 23:55:37 +00:00
put :update, :user => {:name => 'New Name', :current_password => 'incorrect'}
2011-05-15 23:33:32 +00:00
assert_response :error
end
test 'should create user if information is valid' do
2011-05-15 23:55:37 +00:00
post :create, :user => {:email => 'user@example.com', :name => 'User', :password => 'correct', :password_confirmation => 'correct'}
2011-05-15 23:33:32 +00:00
assert_response :success
end
test 'should return error if information is invalid' do
2011-05-15 23:55:37 +00:00
post :create, :user => {:email => 'user@example.com', :name => 'User', :password => 'correct', :password_confirmation => 'incorrect'}
2011-05-15 23:33:32 +00:00
assert_response :error
end
end