From: Tom Hughes Date: Wed, 21 Jul 2021 18:24:31 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/3257' X-Git-Tag: live~2056 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f1935b1c5786de8f27bee9b6b2da2f28f650468f?hp=0bbdadd727a37ee71d4a8c89b50ce2060d6a6240 Merge remote-tracking branch 'upstream/pull/3257' --- diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index c03ab288c..018ce0096 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -46,6 +46,8 @@ class Ability can [:make_friend, :remove_friend], Friendship can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message can [:close, :reopen], Note + can [:show, :edit, :update], :preference + can [:edit, :update], :profile can [:new, :create], Report can [:mine, :new, :create, :edit, :update, :destroy], Trace can [:account, :go_public], User diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2a1c3d675..0884964ed 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -172,8 +172,7 @@ class ApplicationController < ActionController::Base end end - def preferred_languages(reset: false) - @preferred_languages = nil if reset + def preferred_languages @preferred_languages ||= if params[:locale] Locale.list(params[:locale]) elsif current_user @@ -185,13 +184,13 @@ class ApplicationController < ActionController::Base helper_method :preferred_languages - def set_locale(reset: false) + def set_locale if current_user&.languages&.empty? && !http_accept_language.user_preferred_languages.empty? current_user.languages = http_accept_language.user_preferred_languages current_user.save end - I18n.locale = Locale.available.preferred(preferred_languages(:reset => reset)) + I18n.locale = Locale.available.preferred(preferred_languages) response.headers["Vary"] = "Accept-Language" response.headers["Content-Language"] = I18n.locale.to_s diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index 372ac2a70..7b1c52ca6 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -129,9 +129,9 @@ class ConfirmationsController < ApplicationController # display a message about th current status of the gravatar setting def gravatar_status_message(user) if user.image_use_gravatar - t "users.account.gravatar.enabled" + t "profiles.edit.gravatar.enabled" else - t "users.account.gravatar.disabled" + t "profiles.edit.gravatar.disabled" end end end diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb new file mode 100644 index 000000000..e098a8acc --- /dev/null +++ b/app/controllers/preferences_controller.rb @@ -0,0 +1,33 @@ +class PreferencesController < ApplicationController + layout "site" + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => false + + before_action :check_database_readable + before_action :check_database_writable, :only => [:update] + + def show; end + + def edit; end + + def update + current_user.languages = params[:user][:languages].split(",") + + current_user.preferred_editor = if params[:user][:preferred_editor] == "default" + nil + else + params[:user][:preferred_editor] + end + if current_user.save + # Use a partial so that it is rendered during the next page load in the correct language. + flash[:notice] = { :partial => "preferences/update_success_flash" } + redirect_to preferences_path + else + flash[:error] = t ".failure" + render :edit + end + end +end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb new file mode 100644 index 000000000..b48d08ad2 --- /dev/null +++ b/app/controllers/profiles_controller.rb @@ -0,0 +1,43 @@ +class ProfilesController < ApplicationController + layout "site" + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => false + + before_action :check_database_readable + before_action :check_database_writable, :only => [:update] + + def edit; end + + def update + if params[:user][:description] != current_user.description + current_user.description = params[:user][:description] + current_user.description_format = "markdown" + end + + case params[:avatar_action] + when "new" + current_user.avatar.attach(params[:user][:avatar]) + current_user.image_use_gravatar = false + when "delete" + current_user.avatar.purge_later + current_user.image_use_gravatar = false + when "gravatar" + current_user.avatar.purge_later + current_user.image_use_gravatar = true + end + + current_user.home_lat = params[:user][:home_lat] + current_user.home_lon = params[:user][:home_lon] + + if current_user.save + flash[:notice] = t ".success" + redirect_to user_path(current_user) + else + flash[:error] = t ".failure" + render :edit + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3101e5af2..ec30eb4e7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -363,34 +363,6 @@ class UsersController < ApplicationController user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation] end - if params[:user][:description] != user.description - user.description = params[:user][:description] - user.description_format = "markdown" - end - - user.languages = params[:user][:languages].split(",") - - case params[:avatar_action] - when "new" - user.avatar.attach(params[:user][:avatar]) - user.image_use_gravatar = false - when "delete" - user.avatar.purge_later - user.image_use_gravatar = false - when "gravatar" - user.avatar.purge_later - user.image_use_gravatar = true - end - - user.home_lat = params[:user][:home_lat] - user.home_lon = params[:user][:home_lon] - - user.preferred_editor = if params[:user][:preferred_editor] == "default" - nil - else - params[:user][:preferred_editor] - end - if params[:user][:auth_provider].nil? || params[:user][:auth_provider].blank? user.auth_provider = nil user.auth_uid = nil @@ -399,8 +371,6 @@ class UsersController < ApplicationController if user.save session[:fingerprint] = user.fingerprint - set_locale(:reset => true) - if user.new_email.blank? || user.new_email == user.email flash[:notice] = t "users.account.flash update success" else diff --git a/app/models/user.rb b/app/models/user.rb index cca894a6b..8b8f31676 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -118,7 +118,6 @@ class User < ApplicationRecord before_save :encrypt_password before_save :update_tile after_save :spam_check - after_save :reset_preferred_languages def to_param display_name @@ -179,10 +178,6 @@ class User < ApplicationRecord @preferred_languages ||= Locale.list(languages) end - def reset_preferred_languages - @preferred_languages = nil - end - def nearby(radius = Settings.nearby_radius, num = Settings.nearby_users) if home_lon && home_lat gc = OSM::GreatCircle.new(home_lat, home_lon) diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index fe5bf23c5..6b6271c2b 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -96,6 +96,7 @@ <% end %> <%= link_to t("users.show.my profile"), user_path(current_user), :class => "dropdown-item" %> <%= link_to t("users.show.my settings"), { :controller => "users", :action => "account", :display_name => current_user.display_name }, { :class => "dropdown-item" } %> + <%= link_to t("users.show.my_preferences"), preferences_path, :class => "dropdown-item" %> <%= yield :greeting %> <%= link_to t("layouts.logout"), logout_path(:referer => request.fullpath), :method => "post", :class => "geolink dropdown-item" %> diff --git a/app/views/preferences/_update_success_flash.html.erb b/app/views/preferences/_update_success_flash.html.erb new file mode 100644 index 000000000..8fd1095ac --- /dev/null +++ b/app/views/preferences/_update_success_flash.html.erb @@ -0,0 +1 @@ +<%= t ".message" %> diff --git a/app/views/preferences/edit.html.erb b/app/views/preferences/edit.html.erb new file mode 100644 index 000000000..07d89fbb5 --- /dev/null +++ b/app/views/preferences/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :heading do %> +

<%= t ".title" %>

+<% end %> + +<%= bootstrap_form_for current_user, :url => { :action => :update } do |f| %> + <%= f.select :preferred_editor, [[t("editor.default", :name => t("editor.#{Settings.default_editor}.name")), "default"]] + Editors::AVAILABLE_EDITORS.collect { |e| [t("editor.#{e}.description"), e] } %> + + <%= f.text_field :languages %> + + <%= f.primary t(".save") %> + <%= link_to t(".cancel"), preferences_path, :class => "btn btn-link" %> +<% end %> diff --git a/app/views/preferences/show.html.erb b/app/views/preferences/show.html.erb new file mode 100644 index 000000000..7a63d0be8 --- /dev/null +++ b/app/views/preferences/show.html.erb @@ -0,0 +1,28 @@ +<% content_for :heading do %> +

<%= t ".title" %>

+<% end %> + +
+
<%= t ".preferred_editor" %>
+ + <% if current_user.preferred_editor? %> +
<%= t("editor.#{current_user.preferred_editor}.description") %>
+ <% else %> +
<%= t("editor.default", :name => t("editor.#{Settings.default_editor}.name")) %>
+ <% end %> + +
<%= t ".preferred_languages" %>
+ +
+
    + <% current_user.preferred_languages.each do |locale| %> +
  • <%= locale %>
  • + <% end %> +
+ +
+
+ +
+ <%= link_to t(".edit_preferences"), edit_preferences_path, :class => "btn btn-outline-primary" %> +
diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb new file mode 100644 index 000000000..8eca6f4f7 --- /dev/null +++ b/app/views/profiles/edit.html.erb @@ -0,0 +1,61 @@ +<% content_for :head do %> + <%= javascript_include_tag "user" %> +<% end %> + +<% content_for :heading do %> +

<%= t ".title" %>

+<% end %> + +<%= bootstrap_form_for current_user, :url => { :action => :update }, :html => { :multipart => true, :autocomplete => :off } do |f| %> + <%= f.richtext_field :description, :cols => 80, :rows => 20 %> + +
+ <%= f.label t(".image") %> +
+
+ <%= user_image current_user %> +
+
+ <% if current_user.avatar.attached? %> + <%= f.radio_button "avatar_action", "keep", :name => "avatar_action", :label => t(".keep image"), :checked => !current_user.image_use_gravatar %> + <% end %> + <% if current_user.avatar.attached? || current_user.image_use_gravatar? %> + <%= f.radio_button "avatar_action", "delete", :name => "avatar_action", :label => t(".delete image"), :checked => false %> + <% end %> + <% if current_user.avatar.attached? %> + <%= f.form_group :help => t(".image size hint"), :class => "mb-0" do %> + <%= f.radio_button "avatar_action", "new", :name => "avatar_action", :label => t(".replace image"), :checked => false %> + <%= f.file_field :avatar, :hide_label => true, :wrapper => { :class => "mb-0" } %> + <% end %> + <% else %> + <%= f.form_group :help => t(".image size hint"), :class => "mb-0" do %> + <%= f.radio_button "avatar_action", "new", :name => "avatar_action", :label => t(".new image"), :checked => false %> + <%= f.file_field :avatar, :hide_label => true, :wrapper => { :class => "mb-0" } %> + <% end %> + <% end %> + <%= f.form_group :help => link_to(t(".gravatar.what_is_gravatar"), t(".gravatar.link")) do %> + <%= f.radio_button "avatar_action", "gravatar", :name => "avatar_action", :label => t(".gravatar.gravatar"), :checked => current_user.image_use_gravatar %> + <% end %> +
+
+
+ +
+ <%= t ".home location" -%> +
class="nohome"<% end %>> +

<%= t ".no home location" %>

+
+ <%= f.text_field :home_lat, :wrapper_class => "col-sm-4", :id => "home_lat" %> + <%= f.text_field :home_lon, :wrapper_class => "col-sm-4", :id => "home_lon" %> +
+
+
+ checked="checked" <% end %> id="updatehome" /> + +
+ <%= tag.div "", :id => "map", :class => "content_map set_location" %> +
+ + <%= f.primary t(".save") %> + <%= link_to t(".cancel"), user_path(current_user), :class => "btn btn-link" %> +<% end %> diff --git a/app/views/users/account.html.erb b/app/views/users/account.html.erb index dc31de97a..26d840210 100644 --- a/app/views/users/account.html.erb +++ b/app/views/users/account.html.erb @@ -58,57 +58,6 @@ - <%= f.select :preferred_editor, [[t("editor.default", :name => t("editor.#{Settings.default_editor}.name")), "default"]] + Editors::AVAILABLE_EDITORS.collect { |e| [t("editor.#{e}.description"), e] } %> - <%= f.richtext_field :description, :cols => 80, :rows => 20 %> - <%= f.text_field :languages %> - -
- <%= f.label t(".image") %> -
-
- <%= user_image current_user %> -
-
- <% if current_user.avatar.attached? %> - <%= f.radio_button "avatar_action", "keep", :name => "avatar_action", :label => t(".keep image"), :checked => !current_user.image_use_gravatar %> - <% end %> - <% if current_user.avatar.attached? || current_user.image_use_gravatar? %> - <%= f.radio_button "avatar_action", "delete", :name => "avatar_action", :label => t(".delete image"), :checked => false %> - <% end %> - <% if current_user.avatar.attached? %> - <%= f.form_group :help => t(".image size hint"), :class => "mb-0" do %> - <%= f.radio_button "avatar_action", "new", :name => "avatar_action", :label => t(".replace image"), :checked => false %> - <%= f.file_field :avatar, :hide_label => true, :wrapper => { :class => "mb-0" } %> - <% end %> - <% else %> - <%= f.form_group :help => t(".image size hint"), :class => "mb-0" do %> - <%= f.radio_button "avatar_action", "new", :name => "avatar_action", :label => t(".new image"), :checked => false %> - <%= f.file_field :avatar, :hide_label => true, :wrapper => { :class => "mb-0" } %> - <% end %> - <% end %> - <%= f.form_group :help => link_to(t(".gravatar.what_is_gravatar"), t(".gravatar.link")) do %> - <%= f.radio_button "avatar_action", "gravatar", :name => "avatar_action", :label => t(".gravatar.gravatar"), :checked => current_user.image_use_gravatar %> - <% end %> -
-
-
- -
- <%= t ".home location" -%> -
class="nohome"<% end %>> -

<%= t ".no home location" %>

-
- <%= f.text_field :home_lat, :wrapper_class => "col-sm-4", :id => "home_lat" %> - <%= f.text_field :home_lon, :wrapper_class => "col-sm-4", :id => "home_lon" %> -
-
-
- checked="checked" <% end %> id="updatehome" /> - -
- <%= tag.div "", :id => "map", :class => "content_map set_location" %> -
- <%= f.primary t(".save changes button") %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index dac0ff5b5..ac6938af7 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -165,6 +165,12 @@
<%= @user.description.to_html %>
+ <% if current_user and @user.id == current_user.id %> +
+ <%= link_to t(".edit_profile"), edit_profile_path, :class => "btn btn-outline-primary" %> +
+ <% end %> + <% if current_user and current_user.administrator? -%> diff --git a/config/locales/en.yml b/config/locales/en.yml index fce1f8913..83b697e8c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1645,6 +1645,43 @@ en: reset: "Reset Password" flash changed: "Your password has been changed." flash token bad: "Did not find that token, check the URL maybe?" + preferences: + show: + title: My Preferences + preferred_editor: Preferred Editor + preferred_languages: Preferred Languages + edit_preferences: Edit Preferences + edit: + title: Edit Preferences + save: Update Preferences + cancel: Cancel + update: + failure: Couldn't update preferences. + update_success_flash: + message: Preferences updated. + profiles: + edit: + title: Edit Profile + save: Update Profile + cancel: Cancel + image: Image + gravatar: + gravatar: "Use Gravatar" + link: "https://wiki.openstreetmap.org/wiki/Gravatar" + what_is_gravatar: "What is Gravatar?" + disabled: "Gravatar has been disabled." + enabled: "Display of your Gravatar has been enabled." + new image: "Add an image" + keep image: "Keep the current image" + delete image: "Remove the current image" + replace image: "Replace the current image" + image size hint: "(square images at least 100x100 work best)" + home location: "Home Location" + no home location: "You have not entered your home location." + update home location on click: "Update home location when I click on the map?" + update: + success: Profile updated. + failure: Couldn't update profile. sessions: new: title: "Login" @@ -2446,8 +2483,10 @@ en: my profile: My Profile my settings: My Settings my comments: My Comments + my_preferences: My Preferences blocks on me: Blocks on Me blocks by me: Blocks by Me + edit_profile: Edit Profile send message: Send Message diary: Diary edits: Edits @@ -2529,21 +2568,6 @@ en: agreed_with_pd: "You have also declared that you consider your edits to be in the Public Domain." link: "https://www.osmfoundation.org/wiki/License/Contributor_Terms" link text: "what is this?" - image: Image - gravatar: - gravatar: "Use Gravatar" - link: "https://wiki.openstreetmap.org/wiki/Gravatar" - what_is_gravatar: "What is Gravatar?" - disabled: "Gravatar has been disabled." - enabled: "Display of your Gravatar has been enabled." - new image: "Add an image" - keep image: "Keep the current image" - delete image: "Remove the current image" - replace image: "Replace the current image" - image size hint: "(square images at least 100x100 work best)" - home location: "Home Location" - no home location: "You have not entered your home location." - update home location on click: "Update home location when I click on the map?" save changes button: Save Changes make edits public button: Make all my edits public return to profile: Return to profile diff --git a/config/routes.rb b/config/routes.rb index 048db8b33..dc10818b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -240,6 +240,9 @@ OpenStreetMap::Application.routes.draw do match "/user/:display_name/account" => "users#account", :via => [:get, :post], :as => "user_account" post "/user/:display_name/set_status" => "users#set_status", :as => :set_status_user + resource :preferences, :only => [:show, :edit, :update] + resource :profile, :only => [:edit, :update] + # friendships match "/user/:display_name/make_friend" => "friendships#make_friend", :via => [:get, :post], :as => "make_friend" match "/user/:display_name/remove_friend" => "friendships#remove_friend", :via => [:get, :post], :as => "remove_friend" diff --git a/test/controllers/preferences_controller_test.rb b/test/controllers/preferences_controller_test.rb new file mode 100644 index 000000000..8c529e62a --- /dev/null +++ b/test/controllers/preferences_controller_test.rb @@ -0,0 +1,56 @@ +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 ".notice", false + assert_select ".error", true + assert_select "form > div.form-group > 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 ".notice", /^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 ".notice", /^Preferences updated/ + assert_select "dd", "Default (currently iD)" + end +end diff --git a/test/controllers/profiles_controller_test.rb b/test/controllers/profiles_controller_test.rb new file mode 100644 index 000000000..38e73a03f --- /dev/null +++ b/test/controllers/profiles_controller_test.rb @@ -0,0 +1,67 @@ +require "test_helper" + +class ProfilesControllerTest < ActionDispatch::IntegrationTest + ## + # test all routes which lead to this controller + def test_routes + assert_routing( + { :path => "/profile/edit", :method => :get }, + { :controller => "profiles", :action => "edit" } + ) + + assert_routing( + { :path => "/profile", :method => :put }, + { :controller => "profiles", :action => "update" } + ) + end + + def test_update + user = create(:user) + session_for(user) + + # Updating the description should work + put profile_path, :params => { :user => { :description => "new description" } } + assert_response :redirect + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_select ".notice", /^Profile updated./ + assert_select "div", "new description" + + # Changing to an uploaded image should work + image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif") + put profile_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } } + assert_response :redirect + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_select ".notice", /^Profile updated./ + get edit_profile_path + assert_select "form > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep" + + # Changing to a gravatar image should work + put profile_path, :params => { :avatar_action => "gravatar", :user => { :description => user.description } } + assert_response :redirect + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_select ".notice", /^Profile updated./ + get edit_profile_path + assert_select "form > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar" + + # Removing the image should work + put profile_path, :params => { :avatar_action => "delete", :user => { :description => user.description } } + assert_response :redirect + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_select ".notice", /^Profile updated./ + get edit_profile_path + assert_select "form > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked]", false + assert_select "form > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked]", false + end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 62eb79f0c..a73e48211 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -463,80 +463,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_template :account assert_not_equal user.description, User.find(user.id).description - # Updating the description should work - user.description = "new description" - user.preferred_editor = "default" - post user_account_path(user), :params => { :user => user.attributes } - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > div#user_description_container > div#user_description_content > textarea#user_description", user.description - - # Changing to a invalid editor should fail - user.preferred_editor = "unknown" - post user_account_path(user), :params => { :user => user.attributes } - assert_response :success - assert_template :account - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false - - # Changing to a valid editor should work - user.preferred_editor = "id" - post user_account_path(user), :params => { :user => user.attributes } - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected][value=?]", "id" - - # Changing to the default editor should work - user.preferred_editor = "default" - post user_account_path(user), :params => { :user => user.attributes } - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false - - # Changing to an uploaded image should work - image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif") - post user_account_path(user), :params => { :avatar_action => "new", :user => user.attributes.merge(:avatar => image) } - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep" - - # Changing to a gravatar image should work - post user_account_path(user), :params => { :avatar_action => "gravatar", :user => user.attributes } - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar" - - # Removing the image should work - post user_account_path(user), :params => { :avatar_action => "delete", :user => user.attributes } - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked]", false - assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked]", false - # Adding external authentication should redirect to the auth provider post user_account_path(user), :params => { :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") } assert_response :redirect diff --git a/test/system/preferences_test.rb b/test/system/preferences_test.rb new file mode 100644 index 000000000..e5bcd1092 --- /dev/null +++ b/test/system/preferences_test.rb @@ -0,0 +1,23 @@ +require "application_system_test_case" + +class PreferencesTest < ApplicationSystemTestCase + def test_flash_message_shows_in_original_language + sign_in_as(create(:user)) + + visit edit_preferences_path + click_on "Update Preferences" + + assert page.has_content?("Preferences updated") + end + + def test_flash_message_shows_in_new_language + sign_in_as(create(:user)) + + visit edit_preferences_path + fill_in "Preferred Languages", :with => "fr" + click_on "Update Preferences" + + # TODO: enable with french translation when that's available + # assert page.has_content?("Préférences mises à jour") # rubocop:disable Style/AsciiComments + end +end