You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

my_controller_test.rb 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class MyControllerTest < Redmine::ControllerTest
  20. fixtures :users, :email_addresses, :user_preferences, :roles, :projects, :members, :member_roles,
  21. :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources, :queries, :enabled_modules,
  22. :journals
  23. def setup
  24. @request.session[:user_id] = 2
  25. end
  26. def test_index
  27. get :index
  28. assert_response :success
  29. assert_select 'h2', 'My page'
  30. end
  31. def test_page
  32. get :page
  33. assert_response :success
  34. assert_select 'h2', 'My page'
  35. end
  36. def test_page_with_timelog_block
  37. preferences = User.find(2).pref
  38. preferences[:my_page_layout] = {'top' => ['timelog']}
  39. preferences.save!
  40. with_issue = TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :hours => 2.5, :activity_id => 10, :issue_id => 1)
  41. without_issue = TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :hours => 3.5, :activity_id => 10, :project_id => 1)
  42. get :page
  43. assert_response :success
  44. assert_select "tr#time-entry-#{with_issue.id}" do
  45. assert_select 'td.subject a[href="/issues/1"]'
  46. assert_select 'td.hours', :text => '2.50'
  47. end
  48. assert_select "tr#time-entry-#{without_issue.id}" do
  49. assert_select 'td.hours', :text => '3.50'
  50. end
  51. end
  52. def test_page_with_assigned_issues_block_and_no_custom_settings
  53. preferences = User.find(2).pref
  54. preferences.my_page_layout = {'top' => ['issuesassignedtome']}
  55. preferences.my_page_settings = nil
  56. preferences.save!
  57. get :page
  58. assert_select '#block-issuesassignedtome' do
  59. assert_select 'table.issues' do
  60. assert_select 'th a[data-remote=true][data-method=post]', :text => 'Tracker'
  61. end
  62. assert_select '#issuesassignedtome-settings' do
  63. assert_select 'select[name=?]', 'settings[issuesassignedtome][columns][]'
  64. end
  65. end
  66. end
  67. def test_page_with_assigned_issues_block_and_custom_columns
  68. preferences = User.find(2).pref
  69. preferences.my_page_layout = {'top' => ['issuesassignedtome']}
  70. preferences.my_page_settings = {'issuesassignedtome' => {:columns => ['tracker', 'subject', 'due_date']}}
  71. preferences.save!
  72. get :page
  73. assert_select '#block-issuesassignedtome' do
  74. assert_select 'table.issues td.due_date'
  75. end
  76. end
  77. def test_page_with_assigned_issues_block_and_custom_sort
  78. preferences = User.find(2).pref
  79. preferences.my_page_layout = {'top' => ['issuesassignedtome']}
  80. preferences.my_page_settings = {'issuesassignedtome' => {:sort => 'due_date'}}
  81. preferences.save!
  82. get :page
  83. assert_select '#block-issuesassignedtome' do
  84. assert_select 'table.issues.sort-by-due-date'
  85. end
  86. end
  87. def test_page_with_issuequery_block_and_no_settings
  88. user = User.find(2)
  89. user.pref.my_page_layout = {'top' => ['issuequery']}
  90. user.pref.save!
  91. get :page
  92. assert_response :success
  93. assert_select '#block-issuequery' do
  94. assert_select 'h3', :text => 'Issues'
  95. assert_select 'select[name=?]', 'settings[issuequery][query_id]' do
  96. assert_select 'option[value="5"]', :text => 'Open issues by priority and tracker'
  97. end
  98. end
  99. end
  100. def test_page_with_issuequery_block_and_global_query
  101. user = User.find(2)
  102. query = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
  103. user.pref.my_page_layout = {'top' => ['issuequery']}
  104. user.pref.my_page_settings = {'issuequery' => {:query_id => query.id}}
  105. user.pref.save!
  106. get :page
  107. assert_response :success
  108. assert_select '#block-issuequery' do
  109. assert_select 'a[href=?]', "/issues?query_id=#{query.id}"
  110. # assert number of columns (columns from query + id column + checkbox column)
  111. assert_select 'table.issues th', 7
  112. # assert results limit
  113. assert_select 'table.issues tr.issue', 10
  114. assert_select 'table.issues td.assigned_to'
  115. end
  116. end
  117. def test_page_with_issuequery_block_and_project_query
  118. user = User.find(2)
  119. query = IssueQuery.create!(:name => 'All issues', :project => Project.find(1), :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
  120. user.pref.my_page_layout = {'top' => ['issuequery']}
  121. user.pref.my_page_settings = {'issuequery' => {:query_id => query.id}}
  122. user.pref.save!
  123. get :page
  124. assert_response :success
  125. assert_select '#block-issuequery' do
  126. assert_select 'a[href=?]', "/projects/ecookbook/issues?query_id=#{query.id}"
  127. # assert number of columns (columns from query + id column + checkbox column)
  128. assert_select 'table.issues th', 7
  129. # assert results limit
  130. assert_select 'table.issues tr.issue', 10
  131. assert_select 'table.issues td.assigned_to'
  132. end
  133. end
  134. def test_page_with_issuequery_block_and_query_should_display_custom_columns
  135. user = User.find(2)
  136. query = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
  137. user.pref.my_page_layout = {'top' => ['issuequery']}
  138. user.pref.my_page_settings = {'issuequery' => {:query_id => query.id, :columns => [:subject, :due_date]}}
  139. user.pref.save!
  140. get :page
  141. assert_response :success
  142. assert_select '#block-issuequery' do
  143. # assert number of columns (columns from query + id column + checkbox column)
  144. assert_select 'table.issues th', 5
  145. assert_select 'table.issues th', :text => 'Due date'
  146. end
  147. end
  148. def test_page_with_multiple_issuequery_blocks
  149. user = User.find(2)
  150. query1 = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
  151. query2 = IssueQuery.create!(:name => 'Other issues', :user => user, :column_names => [:tracker, :subject, :priority])
  152. user.pref.my_page_layout = {'top' => ['issuequery__1', 'issuequery']}
  153. user.pref.my_page_settings = {
  154. 'issuequery' => {:query_id => query1.id, :columns => [:subject, :due_date]},
  155. 'issuequery__1' => {:query_id => query2.id}
  156. }
  157. user.pref.save!
  158. get :page
  159. assert_response :success
  160. assert_select '#block-issuequery' do
  161. assert_select 'h3', :text => /All issues/
  162. assert_select 'table.issues th', :text => 'Due date'
  163. end
  164. assert_select '#block-issuequery__1' do
  165. assert_select 'h3', :text => /Other issues/
  166. assert_select 'table.issues th', :text => 'Priority'
  167. end
  168. assert_select '#block-select' do
  169. assert_select 'option[value=?]:not([disabled])', 'issuequery__2', :text => 'Issues'
  170. end
  171. end
  172. def test_page_with_activity
  173. user = User.find(2)
  174. user.pref.my_page_layout = {'top' => ['activity']}
  175. user.pref.time_zone = 'UTC'
  176. user.pref.save!
  177. get :page
  178. assert_response :success
  179. assert_select 'div#block-activity' do
  180. assert_select 'h3' do
  181. assert_select 'a[href=?]', activity_path(from: User.current.today, user_id: user.id), :text => 'Activity'
  182. end
  183. assert_select 'div#activity' do
  184. assert_select 'dt', 10
  185. end
  186. end
  187. end
  188. def test_page_with_updated_issues_block
  189. preferences = User.find(2).pref
  190. preferences.my_page_layout = {'top' => ['issuesupdatedbyme']}
  191. preferences.my_page_settings = {'issuesupdatedbyme' => {}}
  192. preferences.save!
  193. project = Project.find(3)
  194. project.close
  195. get :page
  196. assert_response :success
  197. assert_select '#block-issuesupdatedbyme' do
  198. report_url = CGI.unescape(css_select('h3 a').first.attr('href'))
  199. assert_match 'f[]=project.status', report_url
  200. assert_match 'v[project.status][]=1', report_url
  201. assert_match 'f[]=updated_by', report_url
  202. assert_match 'v[updated_by][]=me', report_url
  203. assert_select 'table.issues tbody tr', 2
  204. assert_select 'table.issues tbody tr[id=?]', 'issue-1', 1, :title => 'Cannot print recipes'
  205. assert_select 'table.issues tbody tr[id=?]', 'issue-14', 0
  206. end
  207. end
  208. def test_page_with_all_blocks
  209. blocks = Redmine::MyPage.blocks.keys
  210. preferences = User.find(2).pref
  211. preferences[:my_page_layout] = {'top' => blocks}
  212. preferences.save!
  213. get :page
  214. assert_response :success
  215. assert_select 'div.mypage-box', blocks.size
  216. end
  217. def test_page_with_assigned_issues_block_should_not_show_issues_from_closed_projects
  218. preferences = User.find(2).pref
  219. preferences.my_page_layout = {'top' => ['issuesassignedtome']}
  220. preferences.my_page_settings = {'issuesassignedtome' => {}}
  221. preferences.save!
  222. issue = Issue.find(1)
  223. issue.assigned_to = User.find(2)
  224. issue.save!
  225. project = Project.find(2)
  226. project.close
  227. project.save
  228. get :page
  229. assert_response :success
  230. assert_select '#block-issuesassignedtome table.issues tbody' do
  231. report_url = css_select('h3 a').map {|e| e.attr('href')}.first
  232. assert_match 'f%5B%5D=project.status', report_url
  233. assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url
  234. assert_select 'tr', 1
  235. assert_select 'tr[id=?]', 'issue-1', 1, :title => 'Cannot print recipes'
  236. assert_select 'tr[id=?]', 'issue-4', 0
  237. end
  238. end
  239. def test_page_with_reported_issues_block_should_not_show_issues_from_closed_projects
  240. preferences = User.find(2).pref
  241. preferences.my_page_layout = {'top' => ['issuesreportedbyme']}
  242. preferences.my_page_settings = {'issuesreportedbyme' => {}}
  243. preferences.save!
  244. issue = Issue.find(1)
  245. issue.assigned_to = User.find(2)
  246. issue.save!
  247. project = Project.find(2)
  248. project.close
  249. project.save
  250. get :page
  251. assert_response :success
  252. assert_select '#block-issuesreportedbyme' do
  253. report_url = css_select('h3 a').map {|e| e.attr('href')}.first
  254. assert_match 'f%5B%5D=project.status', report_url
  255. assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url
  256. assert_select 'table.issues tbody tr', 10
  257. assert_select 'table.issues tbody tr[id=?]', 'issue-1', 1, :title => 'Cannot print recipes'
  258. assert_select 'table.issues tbody tr[id=?]', 'issue-4', 0
  259. end
  260. end
  261. def test_page_with_watched_issues_block_should_not_show_issues_from_closed_projects
  262. preferences = User.find(2).pref
  263. preferences.my_page_layout = {'top' => ['issueswatched']}
  264. preferences.my_page_settings = {'issueswatched' => {}}
  265. preferences.save!
  266. issue = Issue.find(1)
  267. issue.watcher_user_ids = ['1', '2']
  268. issue.save!
  269. issue2 = Issue.find(4)
  270. issue2.watcher_user_ids = ['2']
  271. issue2.save!
  272. project = Project.find(2)
  273. project.close
  274. project.save
  275. get :page
  276. assert_response :success
  277. assert_select '#block-issueswatched table.issues tbody' do
  278. report_url = css_select('h3 a').map {|e| e.attr('href')}.first
  279. assert_match 'f%5B%5D=project.status', report_url
  280. assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url
  281. assert_select 'tr', 1
  282. assert_select 'tr[id=?]', 'issue-1', 1, :title => 'Cannot print recipes'
  283. assert_select 'tr[id=?]', 'issue-4', 0
  284. end
  285. end
  286. def test_my_account_should_show_editable_custom_fields
  287. get :account
  288. assert_response :success
  289. assert_select 'input[name=?]', 'user[custom_field_values][4]'
  290. end
  291. def test_my_account_should_not_show_non_editable_custom_fields
  292. UserCustomField.find(4).update_attribute :editable, false
  293. get :account
  294. assert_response :success
  295. assert_select 'input[name=?]', 'user[custom_field_values][4]', 0
  296. end
  297. def test_my_account_should_show_language_select
  298. get :account
  299. assert_response :success
  300. assert_select 'select[name=?]', 'user[language]'
  301. end
  302. def test_my_account_with_avatar_enabled_should_link_to_edit_avatar
  303. with_settings :gravatar_enabled => '1' do
  304. Redmine::Configuration.with 'avatar_server_url' => 'https://gravatar.com' do
  305. get :account
  306. assert_response :success
  307. assert_select 'a[href=?] img.gravatar', 'https://gravatar.com'
  308. end
  309. end
  310. end
  311. def test_my_account_should_not_show_language_select_with_force_default_language_for_loggedin
  312. with_settings :force_default_language_for_loggedin => '1' do
  313. get :account
  314. assert_response :success
  315. assert_select 'select[name=?]', 'user[language]', 0
  316. end
  317. end
  318. def test_update_account
  319. put :account, :params => {
  320. :user => {
  321. :firstname => "Joe",
  322. :login => "root",
  323. :admin => 1,
  324. :group_ids => ['10'],
  325. :custom_field_values => {
  326. "4" => "0100562500"
  327. }
  328. }
  329. }
  330. assert_redirected_to '/my/account'
  331. user = User.find(2)
  332. assert_equal "Joe", user.firstname
  333. assert_equal "jsmith", user.login
  334. assert_equal "0100562500", user.custom_value_for(4).value
  335. # ignored
  336. assert !user.admin?
  337. assert user.groups.empty?
  338. end
  339. def test_update_account_should_send_security_notification
  340. ActionMailer::Base.deliveries.clear
  341. put :account, :params => {
  342. :user => {
  343. :mail => 'foobar@example.com'
  344. }
  345. }
  346. assert_not_nil (mail = ActionMailer::Base.deliveries.last)
  347. assert_mail_body_match '0.0.0.0', mail
  348. assert_mail_body_match I18n.t(:mail_body_security_notification_change_to, field: I18n.t(:field_mail), value: 'foobar@example.com'), mail
  349. assert_select_email do
  350. assert_select 'a[href^=?]', 'http://localhost:3000/my/account', :text => 'My account'
  351. end
  352. # The old email address should be notified about the change for security purposes
  353. assert [mail.bcc, mail.cc].flatten.include?(User.find(2).mail)
  354. assert [mail.bcc, mail.cc].flatten.include?('foobar@example.com')
  355. end
  356. def test_my_account_should_show_destroy_link
  357. get :account
  358. assert_select 'a[href="/my/account/destroy"]'
  359. end
  360. def test_get_destroy_should_display_the_destroy_confirmation
  361. get :destroy
  362. assert_response :success
  363. assert_select 'form[action="/my/account/destroy"]' do
  364. assert_select 'input[name=confirm]'
  365. end
  366. end
  367. def test_post_destroy_without_confirmation_should_not_destroy_account
  368. assert_no_difference 'User.count' do
  369. post :destroy
  370. end
  371. assert_response :success
  372. end
  373. def test_post_destroy_without_confirmation_should_destroy_account
  374. assert_difference 'User.count', -1 do
  375. post :destroy, :params => {
  376. :confirm => '1'
  377. }
  378. end
  379. assert_redirected_to '/'
  380. assert_match /deleted/i, flash[:notice]
  381. end
  382. def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
  383. User.any_instance.stubs(:own_account_deletable?).returns(false)
  384. assert_no_difference 'User.count' do
  385. post :destroy, :params => {
  386. :confirm => '1'
  387. }
  388. end
  389. assert_redirected_to '/my/account'
  390. end
  391. def test_change_password
  392. get :password
  393. assert_response :success
  394. assert_select 'input[type=password][name=password]'
  395. assert_select 'input[type=password][name=new_password]'
  396. assert_select 'input[type=password][name=new_password_confirmation]'
  397. end
  398. def test_update_password
  399. post :password, :params => {
  400. :password => 'jsmith',
  401. :new_password => 'secret123',
  402. :new_password_confirmation => 'secret123'
  403. }
  404. assert_redirected_to '/my/account'
  405. assert User.try_to_login('jsmith', 'secret123')
  406. end
  407. def test_update_password_with_non_matching_confirmation
  408. post :password, :params => {
  409. :password => 'jsmith',
  410. :new_password => 'secret123',
  411. :new_password_confirmation => 'secret1234'
  412. }
  413. assert_response :success
  414. assert_select_error /Password doesn.*t match confirmation/
  415. assert User.try_to_login('jsmith', 'jsmith')
  416. end
  417. def test_update_password_with_wrong_password
  418. # wrong password
  419. post :password, :params => {
  420. :password => 'wrongpassword',
  421. :new_password => 'secret123',
  422. :new_password_confirmation => 'secret123'
  423. }
  424. assert_response :success
  425. assert_equal 'Wrong password', flash[:error]
  426. assert User.try_to_login('jsmith', 'jsmith')
  427. end
  428. def test_change_password_should_redirect_if_user_cannot_change_its_password
  429. User.find(2).update_attribute(:auth_source_id, 1)
  430. get :password
  431. assert_not_nil flash[:error]
  432. assert_redirected_to '/my/account'
  433. end
  434. def test_update_password_should_send_security_notification
  435. ActionMailer::Base.deliveries.clear
  436. post :password, :params => {
  437. :password => 'jsmith',
  438. :new_password => 'secret123',
  439. :new_password_confirmation => 'secret123'
  440. }
  441. assert_not_nil (mail = ActionMailer::Base.deliveries.last)
  442. assert_mail_body_no_match 'secret123', mail # just to be sure: pw should never be sent!
  443. assert_select_email do
  444. assert_select 'a[href^=?]', 'http://localhost:3000/my/password', :text => 'Change password'
  445. end
  446. end
  447. def test_update_page_with_blank_preferences
  448. user = User.generate!(:language => 'en')
  449. @request.session[:user_id] = user.id
  450. post :update_page, :params => {
  451. :settings => {
  452. 'issuesassignedtome' => {
  453. 'columns' => ['subject', 'due_date']}
  454. }
  455. },
  456. :xhr => true
  457. assert_response :success
  458. assert_include '$("#block-issuesassignedtome").replaceWith(', response.body
  459. assert_include 'Due date', response.body
  460. assert_equal({:columns => ['subject', 'due_date']}, user.reload.pref.my_page_settings('issuesassignedtome'))
  461. end
  462. def test_add_block
  463. post :add_block, :params => {
  464. :block => 'issueswatched'
  465. }
  466. assert_redirected_to '/my/page'
  467. assert User.find(2).pref[:my_page_layout]['top'].include?('issueswatched')
  468. end
  469. def test_add_block_xhr
  470. post :add_block, :params => {
  471. :block => 'issueswatched'
  472. },
  473. :xhr => true
  474. assert_response :success
  475. assert_include 'issueswatched', User.find(2).pref[:my_page_layout]['top']
  476. end
  477. def test_add_invalid_block_should_error
  478. post :add_block, :params => {
  479. :block => 'invalid'
  480. }
  481. assert_response 422
  482. end
  483. def test_remove_block
  484. post :remove_block, :params => {
  485. :block => 'issuesassignedtome'
  486. }
  487. assert_redirected_to '/my/page'
  488. assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
  489. end
  490. def test_remove_block_xhr
  491. post :remove_block, :params => {
  492. :block => 'issuesassignedtome'
  493. },
  494. :xhr => true
  495. assert_response :success
  496. assert_include '$("#block-issuesassignedtome").remove();', response.body
  497. assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
  498. end
  499. def test_order_blocks
  500. pref = User.find(2).pref
  501. pref.my_page_layout = {'left' => ['news', 'calendar','documents']}
  502. pref.save!
  503. post :order_blocks, :params => {
  504. :group => 'left',
  505. :blocks => ['documents', 'calendar', 'news']
  506. },
  507. :xhr => true
  508. assert_response :success
  509. assert_equal ['documents', 'calendar', 'news'], User.find(2).pref.my_page_layout['left']
  510. end
  511. def test_move_block
  512. pref = User.find(2).pref
  513. pref.my_page_layout = {'left' => ['news','documents'], 'right' => ['calendar']}
  514. pref.save!
  515. post :order_blocks, :params => {
  516. :group => 'left',
  517. :blocks => ['news', 'calendar', 'documents']
  518. },
  519. :xhr => true
  520. assert_response :success
  521. assert_equal({'left' => ['news', 'calendar', 'documents'], 'right' => []}, User.find(2).pref.my_page_layout)
  522. end
  523. def test_reset_rss_key_with_existing_key
  524. @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
  525. post :reset_rss_key
  526. assert_not_equal @previous_token_value, User.find(2).rss_key
  527. assert User.find(2).rss_token
  528. assert_match /reset/, flash[:notice]
  529. assert_redirected_to '/my/account'
  530. end
  531. def test_reset_rss_key_without_existing_key
  532. Token.delete_all
  533. assert_nil User.find(2).rss_token
  534. post :reset_rss_key
  535. assert User.find(2).rss_token
  536. assert_match /reset/, flash[:notice]
  537. assert_redirected_to '/my/account'
  538. end
  539. def test_show_api_key
  540. get :show_api_key
  541. assert_response :success
  542. assert_select 'pre', User.find(2).api_key
  543. end
  544. def test_reset_api_key_with_existing_key
  545. @previous_token_value = User.find(2).api_key # Will generate one if it's missing
  546. post :reset_api_key
  547. assert_not_equal @previous_token_value, User.find(2).api_key
  548. assert User.find(2).api_token
  549. assert_match /reset/, flash[:notice]
  550. assert_redirected_to '/my/account'
  551. end
  552. def test_reset_api_key_without_existing_key
  553. assert_nil User.find(2).api_token
  554. post :reset_api_key
  555. assert User.find(2).api_token
  556. assert_match /reset/, flash[:notice]
  557. assert_redirected_to '/my/account'
  558. end
  559. end