From b4cbfed1302666eeddc56cbddecdc7068339ae49 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 25 Mar 2019 00:27:06 +0500 Subject: [PATCH] Rename Account#username to #nickname --- app/controllers/accounts_controller.rb | 4 ++-- app/models/account.rb | 14 +++++++------- app/policies/settings/profile_policy.rb | 2 +- app/views/accounts/show.html.erb | 2 +- app/views/application/_navbar.html.erb | 2 +- app/views/settings/profiles/edit.html.erb | 2 +- config/routes.rb | 2 +- config/settings/superuser.yml | 4 ++-- ...92022_rename_accounts_username_to_nickname.rb | 7 +++++++ db/schema.rb | 4 ++-- db/seeds.rb | 2 +- features/desktop/account.feature | 8 ++++---- features/step_definitions/account.rb | 8 ++++---- features/step_definitions/user.rb | 16 ++++++++-------- spec/models/account_spec.rb | 12 ++++++------ spec/requests/accounts/show_spec.rb | 4 ++-- spec/requests/settings/profile/update_spec.rb | 8 ++++---- 17 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 db/migrate/20190324192022_rename_accounts_username_to_nickname.rb diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index aba1428..b425ccc 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -3,7 +3,7 @@ class AccountsController < ApplicationController before_action :set_account - # GET /accounts/:username + # GET /accounts/:nickname def show authorize @account end @@ -11,6 +11,6 @@ class AccountsController < ApplicationController private def set_account - @account = Account.find_by! username: params[:username] + @account = Account.find_by! nickname: params[:nickname] end end diff --git a/app/models/account.rb b/app/models/account.rb index 24c9235..ca74f30 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -4,7 +4,7 @@ class Account < ApplicationRecord include Rolify::Role extend Rolify::Dynamic if Rolify.dynamic_shortcuts - USERNAME_RE = /\A[a-z][_a-z0-9]*[a-z0-9]\z/.freeze + NICKNAME_RE = /\A[a-z][_a-z0-9]*[a-z0-9]\z/.freeze self.role_cname = 'Role' self.role_table_name = 'roles' @@ -45,7 +45,7 @@ class Account < ApplicationRecord # Callbacks # ############# - after_initialize :generate_username + after_initialize :generate_nickname before_validation :turn_blanks_into_nils before_validation :strip_extra_spaces @@ -58,10 +58,10 @@ class Account < ApplicationRecord validates :person, allow_nil: true, uniqueness: true - validates :username, + validates :nickname, presence: true, length: { in: 3..36 }, - format: USERNAME_RE, + format: NICKNAME_RE, uniqueness: { case_sensitive: false } validates :public_name, allow_nil: true, length: { in: 3..255 } @@ -73,7 +73,7 @@ class Account < ApplicationRecord ########### def to_param - username + nickname end def guest? @@ -109,8 +109,8 @@ class Account < ApplicationRecord private - def generate_username - self.username = "noname_#{SecureRandom.hex(8)}" if username.nil? + def generate_nickname + self.nickname = "noname_#{SecureRandom.hex(8)}" if nickname.nil? end def generate_guest_token diff --git a/app/policies/settings/profile_policy.rb b/app/policies/settings/profile_policy.rb index 5e159c0..67b797f 100644 --- a/app/policies/settings/profile_policy.rb +++ b/app/policies/settings/profile_policy.rb @@ -6,6 +6,6 @@ class Settings::ProfilePolicy < ApplicationPolicy end def permitted_attributes_for_update - %i[username public_name biography avatar] + %i[nickname public_name biography avatar] end end diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index 99cc8bf..ce6c6dc 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -9,7 +9,7 @@

<%= @account.public_name %>

<% end %> -

<%= @account.username %>

+

<%= @account.nickname %>

diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index 9507967..e780280 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -17,7 +17,7 @@