3 class PreferencesControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/preferences", :method => :get },
9 { :controller => "preferences", :action => "show" }
13 { :path => "/preferences/edit", :method => :get },
14 { :controller => "preferences", :action => "edit" }
18 { :path => "/preferences", :method => :put },
19 { :controller => "preferences", :action => "update" }
23 def test_update_preferred_editor
24 user = create(:user, :languages => [])
25 user.preferences.create(:k => "site.color_scheme", :v => "light")
26 user.preferences.create(:k => "map.color_scheme", :v => "light")
29 # Changing to a invalid editor should fail
30 user.preferred_editor = "unknown"
31 put preferences_path, :params => { :user => user.attributes }
32 assert_response :success
34 assert_select ".alert-success", false
35 assert_select ".alert-danger", true
36 assert_select "form > div > select#user_preferred_editor > option[selected]", false
37 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
38 assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
40 # Changing to a valid editor should work
41 user.preferred_editor = "id"
42 put preferences_path, :params => { :user => user.attributes }
43 assert_redirected_to preferences_path
46 assert_select ".alert-success", /^Preferences updated/
47 assert_select "dd", "iD (in-browser editor)"
48 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
49 assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
51 # Changing to the default editor should work
52 user.preferred_editor = "default"
53 put preferences_path, :params => { :user => user.attributes }
54 assert_redirected_to preferences_path
57 assert_select ".alert-success", /^Preferences updated/
58 assert_select "dd", "Default (currently iD)"
59 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
60 assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
63 def test_update_preferred_site_color_scheme
64 user = create(:user, :languages => [])
66 assert_nil user.preferences.find_by(:k => "site.color_scheme")
68 # Changing when previously not defined
69 put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "light" }
70 assert_redirected_to preferences_path
73 assert_select ".alert-success", /^Preferences updated/
74 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
76 # Changing when previously defined
77 put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "auto" }
78 assert_redirected_to preferences_path
81 assert_select ".alert-success", /^Preferences updated/
82 assert_equal "auto", user.preferences.find_by(:k => "site.color_scheme")&.v
85 def test_update_preferred_map_color_scheme
86 user = create(:user, :languages => [])
88 assert_nil user.preferences.find_by(:k => "map.color_scheme")
90 # Changing when previously not defined
91 put preferences_path, :params => { :user => user.attributes, :map_color_scheme => "light" }
92 assert_redirected_to preferences_path
95 assert_select ".alert-success", /^Preferences updated/
96 assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
98 # Changing when previously defined
99 put preferences_path, :params => { :user => user.attributes, :map_color_scheme => "auto" }
100 assert_redirected_to preferences_path
102 assert_template :show
103 assert_select ".alert-success", /^Preferences updated/
104 assert_equal "auto", user.preferences.find_by(:k => "map.color_scheme")&.v