]> git.openstreetmap.org Git - rails.git/blob - test/controllers/preferences_controller_test.rb
Merge remote-tracking branch 'upstream/pull/3257'
[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 ".notice", false
33     assert_select ".error", true
34     assert_select "form > div.form-group > 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_response :redirect
40     assert_redirected_to preferences_path
41     follow_redirect!
42     assert_template :show
43     assert_select ".notice", /^Preferences updated/
44     assert_select "dd", "iD (in-browser editor)"
45
46     # Changing to the default editor should work
47     user.preferred_editor = "default"
48     put preferences_path, :params => { :user => user.attributes }
49     assert_response :redirect
50     assert_redirected_to preferences_path
51     follow_redirect!
52     assert_template :show
53     assert_select ".notice", /^Preferences updated/
54     assert_select "dd", "Default (currently iD)"
55   end
56 end