ref: master
test/integration/forgot_password_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
require_relative "../test_helper" class ForgotPasswordTest < ActionDispatch::IntegrationTest def setup ActionDispatch::Integration::Session.any_instance.stubs(:https?).returns(true) end def test_forgot_password_with_login User.destroy_all Profile.destroy_all ChangePassword.destroy_all create_user('forgotten', :password => 'test', :password_confirmation => 'test', :email => 'forgotten@localhost.localdomain').activate get '/account/forgot_password' assert_response :success assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' } post '/account/forgot_password', :field => 'login', :value => 'forgotten', :environment_id => Environment.default.id assert_response :success assert_template 'password_recovery_sent' assert_equal 1, ChangePassword.count code = ChangePassword.first.code get "/account/new_password/#{code}" assert_response :success assert_tag :tag => 'form', :attributes => { :action => "/account/new_password/#{code}" } post "/account/new_password/#{code}", :change_password => { :password => 'newpass', :password_confirmation => 'newpass'} assert_response :success assert_template 'new_password_ok' assert_tag :tag => 'a', :attributes => { :href => "/account/login" } login('forgotten', 'newpass') end def test_forgot_password_with_email User.destroy_all Profile.destroy_all ChangePassword.destroy_all create_user('forgotten', :password => 'test', :password_confirmation => 'test', :email => 'forgotten@localhost.localdomain').activate get '/account/forgot_password' assert_response :success assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' } post '/account/forgot_password', :field => 'email', :value => 'forgotten@localhost.localdomain', :environment_id => Environment.default.id assert_response :success assert_template 'password_recovery_sent' assert_equal 1, ChangePassword.count code = ChangePassword.first.code get "/account/new_password/#{code}" assert_response :success assert_tag :tag => 'form', :attributes => { :action => "/account/new_password/#{code}" } post "/account/new_password/#{code}", :change_password => { :password => 'newpass', :password_confirmation => 'newpass'} assert_response :success assert_template 'new_password_ok' assert_tag :tag => 'a', :attributes => { :href => "/account/login" } login('forgotten', 'newpass') end def test_forgot_password_with_email User.destroy_all Profile.destroy_all ChangePassword.destroy_all create_user('forgotten', :password => 'test', :password_confirmation => 'test', :email => 'forgotten@localhost.localdomain').activate get '/account/forgot_password' assert_response :success assert_tag :tag => 'form', :attributes => { :action => '/account/forgot_password', :method => 'post' } post '/account/forgot_password', :change_password => { :login => 'forgotten@localhost.localdomain', :environment_id => Environment.default.id } assert_response :success assert_template 'password_recovery_sent' assert_equal 1, ChangePassword.count code = ChangePassword.find(:first).code get "/account/new_password/#{code}" assert_response :success assert_tag :tag => 'form', :attributes => { :action => "/account/new_password/#{code}" } post "/account/new_password/#{code}", :change_password => { :password => 'newpass', :password_confirmation => 'newpass'} assert_response :success assert_template 'new_password_ok' assert_tag :tag => 'a', :attributes => { :href => "/account/login" } login('forgotten', 'newpass') end end |