diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 412e2cd84..801791a4c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -59,8 +59,7 @@ class UsersController < ApplicationController @user.touch(:profile_updated_at) redirect_to "/settings/#{@tab}" else - Honeycomb.add_field("error", - @user.errors.messages.reject { |_, v| v.empty? }) + Honeycomb.add_field("error", @user.errors.messages.reject { |_, v| v.empty? }) Honeycomb.add_field("errored", true) render :edit, status: :bad_request end diff --git a/app/lib/url.rb b/app/lib/url.rb index e106c702f..bd7d4d011 100644 --- a/app/lib/url.rb +++ b/app/lib/url.rb @@ -60,6 +60,8 @@ module URL # @param user [User] the user to create the URL for def self.user(user) url(user.username) + rescue URI::InvalidURIError # invalid username containing spaces will result in an error + nil end def self.organization(organization) diff --git a/app/views/users/_profile.html.erb b/app/views/users/_profile.html.erb index ec66b896b..56d588471 100644 --- a/app/views/users/_profile.html.erb +++ b/app/views/users/_profile.html.erb @@ -4,7 +4,7 @@
- + <%= community_name %> badge

Add the <%= community_name %> badge to your personal site. Click here for the code.

diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index f17b6b64f..0e6e93c26 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -49,7 +49,7 @@ <% else %>

- Settings for @<%= @user.username.truncate(User::USERNAME_MAX_LENGTH) %> + Settings for @<%= @user.username.truncate(User::USERNAME_MAX_LENGTH) %>

<% end %> diff --git a/spec/system/user/user_edits_profile_spec.rb b/spec/system/user/user_edits_profile_spec.rb new file mode 100644 index 000000000..b3fb0a9f0 --- /dev/null +++ b/spec/system/user/user_edits_profile_spec.rb @@ -0,0 +1,20 @@ +require "rails_helper" + +RSpec.describe "User edits their profile", type: :system do + let(:user) { create(:user, saw_onboarding: true) } + + before do + sign_in user + end + + describe "visiting /settings/profile" do + it "renders an error if the username contains spaces and thus is invalid" do + visit "/settings/profile" + + fill_in "user[username]", with: "a b c" + click_button "Save" + + expect(page).to have_text("Username is invalid") + end + end +end