openstreetmap-website/test/controllers/preferences_controller_test.rb
Dimitar 318064b2a7 Facelift offline.html and use Bootstrap classes for "notifications"
Update site_controller_test.rb

Update site_controller_test.rb

Remove whitespace

Reset Settings.status after test is done

Update test for offline page

Update site_controller.rb

Fix indentation

Update offline controller

Update offline.html.erb

Remove flash CSS classes and fix missed tests

Updated tests

Address most PR comments

Update _flash.html.erb

Update _flash.html.erb

Update edit.html.erb

Update offline.html.erb
2023-03-26 13:57:51 +03:00

56 lines
1.8 KiB
Ruby

require "test_helper"
class PreferencesControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
assert_routing(
{ :path => "/preferences", :method => :get },
{ :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" }
)
end
def test_update_preferred_editor
user = create(:user, :languages => [])
session_for(user)
# Changing to a invalid editor should fail
user.preferred_editor = "unknown"
put preferences_path, :params => { :user => user.attributes }
assert_response :success
assert_template :edit
assert_select ".alert-success", false
assert_select ".alert-danger", true
assert_select "form > div > select#user_preferred_editor > option[selected]", false
# Changing to a valid editor should work
user.preferred_editor = "id"
put preferences_path, :params => { :user => user.attributes }
assert_response :redirect
assert_redirected_to preferences_path
follow_redirect!
assert_template :show
assert_select ".alert-success", /^Preferences updated/
assert_select "dd", "iD (in-browser editor)"
# Changing to the default editor should work
user.preferred_editor = "default"
put preferences_path, :params => { :user => user.attributes }
assert_response :redirect
assert_redirected_to preferences_path
follow_redirect!
assert_template :show
assert_select ".alert-success", /^Preferences updated/
assert_select "dd", "Default (currently iD)"
end
end