Project

General

Profile

Patch #31399 » 0003-lets-sudo-mode-handle-PUT-on-my-account-makes-tests-.patch

Jens Krämer, 2019-06-14 09:44

View differences:

app/controllers/my_controller.rb
25 25

  
26 26
  accept_api_auth :account
27 27

  
28
  require_sudo_mode :account, only: :post
28
  require_sudo_mode :account, only: :put
29 29
  require_sudo_mode :reset_rss_key, :reset_api_key, :show_api_key, :destroy
30 30

  
31 31
  helper :issues
test/integration/routing/my_test.rb
22 22
class RoutingMyTest < Redmine::RoutingTest
23 23
  def test_my
24 24
    should_route 'GET /my/account' => 'my#account'
25
    should_route 'POST /my/account' => 'my#account'
25
    should_route 'PUT /my/account' => 'my#account'
26 26

  
27 27
    should_route 'GET /my/account/destroy' => 'my#destroy'
28 28
    should_route 'POST /my/account/destroy' => 'my#destroy'
test/integration/sudo_mode_test.rb
149 149
    expire_sudo_mode!
150 150
    get '/my/account'
151 151
    assert_response :success
152
    post '/my/account', :params => {user: { mail: 'newmail@test.com' }}
152
    put '/my/account', :params => {user: { mail: 'newmail@test.com' }}
153 153
    assert_response :success
154 154
    assert_select 'h2', 'Confirm your password to continue'
155 155
    assert_select 'form[action="/my/account"]'
......
157 157
    assert_select '#flash_error', 0
158 158

  
159 159
    # wrong password
160
    post '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'wrong'}
160
    put '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'wrong'}
161 161
    assert_response :success
162 162
    assert_select 'h2', 'Confirm your password to continue'
163 163
    assert_select 'form[action="/my/account"]'
......
165 165
    assert_select '#flash_error'
166 166

  
167 167
    # correct password
168
    post '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith'}
168
    put '/my/account', :params => {user: { mail: 'newmail@test.com' }, sudo_password: 'jsmith'}
169 169
    assert_redirected_to '/my/account'
170 170
    assert_equal 'newmail@test.com', User.find_by_login('jsmith').mail
171 171

  
172 172
    # sudo mode should now be active and not require password again
173
    post '/my/account', :params => {user: { mail: 'even.newer.mail@test.com' }}
173
    put '/my/account', :params => {user: { mail: 'even.newer.mail@test.com' }}
174 174
    assert_redirected_to '/my/account'
175 175
    assert_equal 'even.newer.mail@test.com', User.find_by_login('jsmith').mail
176 176
  end
(3-3/3)