From 1b6f1b975214e5fde9d96b77c8893d819a71e9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 9 Feb 2010 00:08:57 +0100 Subject: [PATCH] Add registerable integration tests. --- app/views/registrations/edit.html.erb | 4 +- test/integration/registerable_test.rb | 65 ++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/app/views/registrations/edit.html.erb b/app/views/registrations/edit.html.erb index 58f3b49f..1fd0b452 100644 --- a/app/views/registrations/edit.html.erb +++ b/app/views/registrations/edit.html.erb @@ -18,8 +18,8 @@

<%= f.submit "Update" %>

<% end -%> -

Cancel your account

+

Cancel my account

-

Unhappy? <%= link_to "Cancel your account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>

+

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.

<%= render :partial => "shared/devise_links" %> diff --git a/test/integration/registerable_test.rb b/test/integration/registerable_test.rb index bdccf0bc..bb3e60ad 100644 --- a/test/integration/registerable_test.rb +++ b/test/integration/registerable_test.rb @@ -21,10 +21,7 @@ class RegistrationTest < ActionController::IntegrationTest end test 'a guest user should be able to sign up successfully and be blocked by confirmation' do - visit new_user_session_path - click_link 'Sign up' - - assert_template 'registrations/new' + visit new_user_registration_path fill_in 'email', :with => 'new_user@test.com' fill_in 'password', :with => 'new_user123' @@ -49,8 +46,7 @@ class RegistrationTest < ActionController::IntegrationTest end test 'a guest user cannot sign up with invalid information' do - visit new_user_session_path - click_link 'Sign up' + visit new_user_registration_path fill_in 'email', :with => 'invalid_email' fill_in 'password', :with => 'new_user123' @@ -68,9 +64,7 @@ class RegistrationTest < ActionController::IntegrationTest test 'a guest should not sign up with email/password that already exists' do user = create_user - - visit new_user_session_path - click_link 'Sign up' + visit new_user_registration_path fill_in 'email', :with => 'user@test.com' fill_in 'password', :with => '123456' @@ -82,4 +76,55 @@ class RegistrationTest < ActionController::IntegrationTest assert_not warden.authenticated?(:user) end -end + + test 'a guest should not be able to change account' do + visit edit_user_registration_path + follow_redirect! + assert_template 'sessions/new' + end + + test 'a signed in user should not be able to access sign up' do + sign_in_as_user + visit new_user_registration_path + assert_template 'home/index' + end + + test 'a signed in user should be able to edit his account' do + sign_in_as_user + visit edit_user_registration_path + + fill_in 'email', :with => 'user.new@email.com' + fill_in 'current password', :with => '123456' + click_button 'Update' + + assert_template 'home/index' + assert_contain 'You updated your account successfully.' + + assert_equal "user.new@email.com", User.first.email + end + + test 'a signed in user should be able to edit his password' do + sign_in_as_user + visit edit_user_registration_path + + fill_in 'password', :with => 'pas123' + fill_in 'password confirmation', :with => 'pas123' + fill_in 'current password', :with => '123456' + click_button 'Update' + + assert_template 'home/index' + assert_contain 'You updated your account successfully.' + + assert User.first.valid_password?('pas123') + end + + test 'a signed in user should be able to cancel his account' do + sign_in_as_user + visit edit_user_registration_path + + click_link "Cancel my account" + assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon." + + assert User.all.empty? + end +end \ No newline at end of file