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")
28 # Changing to a invalid editor should fail
29 user.preferred_editor = "unknown"
30 put preferences_path, :params => { :user => user.attributes }
31 assert_response :success
33 assert_select ".alert-success", false
34 assert_select ".alert-danger", true
35 assert_select "form > div > select#user_preferred_editor > option[selected]", false
36 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
38 # Changing to a valid editor should work
39 user.preferred_editor = "id"
40 put preferences_path, :params => { :user => user.attributes }
41 assert_redirected_to preferences_path
44 assert_select ".alert-success", /^Preferences updated/
45 assert_select "dd", "iD (in-browser editor)"
46 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
48 # Changing to the default editor should work
49 user.preferred_editor = "default"
50 put preferences_path, :params => { :user => user.attributes }
51 assert_redirected_to preferences_path
54 assert_select ".alert-success", /^Preferences updated/
55 assert_select "dd", "Default (currently iD)"
56 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
59 def test_update_preferred_site_color_scheme
60 user = create(:user, :languages => [])
62 assert_nil user.preferences.find_by(:k => "site.color_scheme")
64 # Changing when previously not defined
65 put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "light" }
66 assert_redirected_to preferences_path
69 assert_select ".alert-success", /^Preferences updated/
70 assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
72 # Changing when previously defined
73 put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "auto" }
74 assert_redirected_to preferences_path
77 assert_select ".alert-success", /^Preferences updated/
78 assert_equal "auto", user.preferences.find_by(:k => "site.color_scheme")&.v