X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/297d05c63b742ff3e851f4d2514fe0043f57a29e..0ab8d954ad6d6e4cee5c1238973b8f693c788fcb:/test/controllers/preferences_controller_test.rb diff --git a/test/controllers/preferences_controller_test.rb b/test/controllers/preferences_controller_test.rb index 6bc609e6a..86fc89a71 100644 --- a/test/controllers/preferences_controller_test.rb +++ b/test/controllers/preferences_controller_test.rb @@ -9,11 +9,6 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest { :controller => "preferences", :action => "show" } ) - assert_routing( - { :path => "/preferences/edit", :method => :get }, - { :controller => "preferences", :action => "edit" } - ) - assert_routing( { :path => "/preferences", :method => :put }, { :controller => "preferences", :action => "update" } @@ -22,35 +17,85 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest def test_update_preferred_editor user = create(:user, :languages => []) + user.preferences.create(:k => "site.color_scheme", :v => "light") + user.preferences.create(:k => "map.color_scheme", :v => "light") session_for(user) # Changing to a invalid editor should fail - user.preferred_editor = "unknown" - put preferences_path, :params => { :user => user.attributes } + put preferences_path, :params => { :user => { :preferred_editor => "unknown", :languages => [] } } assert_response :success - assert_template :edit - assert_select ".notice", false - assert_select ".error", true - assert_select "form > div > select#user_preferred_editor > option[selected]", false + assert_template :show + assert_select ".alert-success", false + assert_select ".alert-danger", true + user.reload + assert_nil user.preferred_editor + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v + assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v # Changing to a valid editor should work - user.preferred_editor = "id" - put preferences_path, :params => { :user => user.attributes } - assert_response :redirect + put preferences_path, :params => { :user => { :preferred_editor => "id", :languages => [] } } assert_redirected_to preferences_path follow_redirect! assert_template :show - assert_select ".notice", /^Preferences updated/ - assert_select "dd", "iD (in-browser editor)" + assert_select ".alert-success", /^Preferences updated/ + user.reload + assert_equal "id", user.preferred_editor + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v + assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v # Changing to the default editor should work - user.preferred_editor = "default" - put preferences_path, :params => { :user => user.attributes } - assert_response :redirect + put preferences_path, :params => { :user => { :preferred_editor => "default", :languages => [] } } + assert_redirected_to preferences_path + follow_redirect! + assert_template :show + assert_select ".alert-success", /^Preferences updated/ + user.reload + assert_nil user.preferred_editor + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v + assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v + end + + def test_update_preferred_site_color_scheme + user = create(:user, :languages => []) + session_for(user) + assert_nil user.preferences.find_by(:k => "site.color_scheme") + + # Changing when previously not defined + put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "light" } + assert_redirected_to preferences_path + follow_redirect! + assert_template :show + assert_select ".alert-success", /^Preferences updated/ + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v + + # Changing when previously defined + put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "auto" } + assert_redirected_to preferences_path + follow_redirect! + assert_template :show + assert_select ".alert-success", /^Preferences updated/ + assert_equal "auto", user.preferences.find_by(:k => "site.color_scheme")&.v + end + + def test_update_preferred_map_color_scheme + user = create(:user, :languages => []) + session_for(user) + assert_nil user.preferences.find_by(:k => "map.color_scheme") + + # Changing when previously not defined + put preferences_path, :params => { :user => user.attributes, :map_color_scheme => "light" } + assert_redirected_to preferences_path + follow_redirect! + assert_template :show + assert_select ".alert-success", /^Preferences updated/ + assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v + + # Changing when previously defined + put preferences_path, :params => { :user => user.attributes, :map_color_scheme => "auto" } assert_redirected_to preferences_path follow_redirect! assert_template :show - assert_select ".notice", /^Preferences updated/ - assert_select "dd", "Default (currently iD)" + assert_select ".alert-success", /^Preferences updated/ + assert_equal "auto", user.preferences.find_by(:k => "map.color_scheme")&.v end end