]> git.openstreetmap.org Git - rails.git/blob - test/controllers/preferences_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4638'
[rails.git] / test / controllers / preferences_controller_test.rb
1 require "test_helper"
2
3 class PreferencesControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/preferences", :method => :get },
9       { :controller => "preferences", :action => "show" }
10     )
11
12     assert_routing(
13       { :path => "/preferences/edit", :method => :get },
14       { :controller => "preferences", :action => "edit" }
15     )
16
17     assert_routing(
18       { :path => "/preferences", :method => :put },
19       { :controller => "preferences", :action => "update" }
20     )
21   end
22
23   def test_update_preferred_editor
24     user = create(:user, :languages => [])
25     session_for(user)
26
27     # Changing to a invalid editor should fail
28     user.preferred_editor = "unknown"
29     put preferences_path, :params => { :user => user.attributes }
30     assert_response :success
31     assert_template :edit
32     assert_select ".alert-success", false
33     assert_select ".alert-danger", true
34     assert_select "form > div > select#user_preferred_editor > option[selected]", false
35
36     # Changing to a valid editor should work
37     user.preferred_editor = "id"
38     put preferences_path, :params => { :user => user.attributes }
39     assert_redirected_to preferences_path
40     follow_redirect!
41     assert_template :show
42     assert_select ".alert-success", /^Preferences updated/
43     assert_select "dd", "iD (in-browser editor)"
44
45     # Changing to the default editor should work
46     user.preferred_editor = "default"
47     put preferences_path, :params => { :user => user.attributes }
48     assert_redirected_to preferences_path
49     follow_redirect!
50     assert_template :show
51     assert_select ".alert-success", /^Preferences updated/
52     assert_select "dd", "Default (currently iD)"
53   end
54 end