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
|
|
|
|
|
2011-12-25 07:23:19 +00:00
|
|
|
test 'should render edit form' do
|
2011-05-15 23:33:32 +00:00
|
|
|
sign_in @user
|
|
|
|
get :edit
|
|
|
|
assert_response :success
|
|
|
|
assert_select 'form#edit_form' do
|
|
|
|
assert_select '[action=?]', '/users'
|
|
|
|
assert_select '[method=?]', 'post'
|
|
|
|
end
|
2012-01-14 22:31:01 +00:00
|
|
|
assert_select 'input', :count => 15
|
2012-01-02 12:36:34 +00:00
|
|
|
assert_select 'label', :count => 12
|
2011-05-15 23:33:32 +00:00
|
|
|
assert_select 'input[name="commit"]' do
|
|
|
|
assert_select '[type=?]', 'submit'
|
|
|
|
assert_select '[value=?]', 'Update'
|
|
|
|
end
|
2012-01-14 22:31:01 +00:00
|
|
|
assert_select 'a.btn', 'Back'
|
2011-05-15 23:33:32 +00:00
|
|
|
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-12-25 07:23:19 +00:00
|
|
|
assert_redirected_to :controller => 'sidebar', :action => 'search'
|
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
|