Rename Account#username to #nickname
This commit is contained in:
parent
62d3c9102b
commit
b4cbfed130
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<h1><%= @account.public_name %></h1>
|
||||
<% end %>
|
||||
|
||||
<p class="h3 text-muted"><%= @account.username %></p>
|
||||
<p class="h3 text-muted"><%= @account.nickname %></p>
|
||||
|
||||
<div class="mb-2">
|
||||
<i class="fas fa-user-tag"></i>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<ul class="navbar-nav ml-auto mr-3">
|
||||
<% if current_account %>
|
||||
<li class="nav-item dropdown">
|
||||
<%= link_to current_account.username,
|
||||
<%= link_to current_account.nickname,
|
||||
'#',
|
||||
id: :navbarDropdown,
|
||||
role: :button,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :username, required: true %>
|
||||
<%= f.input :nickname, required: true %>
|
||||
<%= f.input :public_name %>
|
||||
<%= f.input :biography %>
|
||||
<%= f.input :avatar, direct_upload: true %>
|
||||
|
|
|
@ -13,7 +13,7 @@ Rails.application.routes.draw do
|
|||
get :join, to: 'membership_apps#new'
|
||||
post :join, to: 'membership_apps#create'
|
||||
|
||||
resources :accounts, param: :username, only: :show
|
||||
resources :accounts, param: :nickname, only: :show
|
||||
|
||||
resources :country_states, only: %i[index show]
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
development:
|
||||
email: admin@example.com
|
||||
password: password
|
||||
username: admin
|
||||
nickname: admin
|
||||
public_name: Just Admin
|
||||
biography: I am creator of the website you read this text on.
|
||||
|
||||
production:
|
||||
email: <%= Rails.application.credentials.superuser_email %>
|
||||
password: <%= Rails.application.credentials.superuser_password %>
|
||||
username: kotovalexarian
|
||||
nickname: kotovalexarian
|
||||
public_name: Alex Kotov
|
||||
biography: I am creator of the website you read this text on.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RenameAccountsUsernameToNickname < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
rename_column :accounts, :username, :nickname
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_03_24_172539) do
|
||||
ActiveRecord::Schema.define(version: 2019_03_24_192022) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -32,7 +32,7 @@ ActiveRecord::Schema.define(version: 2019_03_24_172539) do
|
|||
t.datetime "updated_at", null: false
|
||||
t.string "guest_token", null: false
|
||||
t.bigint "person_id"
|
||||
t.string "username", null: false
|
||||
t.string "nickname", null: false
|
||||
t.text "biography"
|
||||
t.string "public_name"
|
||||
t.index ["person_id"], name: "index_accounts_on_person_id", unique: true
|
||||
|
|
|
@ -15,7 +15,7 @@ Rails.application.settings(:superuser).tap do |config|
|
|||
new_user.password = config[:password]
|
||||
new_user.confirmed_at = Time.zone.now
|
||||
new_user.account = Account.create!(
|
||||
username: config[:username],
|
||||
nickname: config[:nickname],
|
||||
public_name: config[:public_name],
|
||||
biography: config[:biography],
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Feature: Account
|
||||
Scenario: of a user
|
||||
Given there is a usual account with the following data:
|
||||
| username | kotovalexarian |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
When I visit "/accounts/kotovalexarian"
|
||||
|
@ -12,7 +12,7 @@ Feature: Account
|
|||
|
||||
Scenario: of a supporter
|
||||
Given there is a supporter account with the following data:
|
||||
| username | kotovalexarian |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| country_state | Москва |
|
||||
|
@ -25,7 +25,7 @@ Feature: Account
|
|||
|
||||
Scenario: of a member
|
||||
Given there is a member account with the following data:
|
||||
| username | kotovalexarian |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| country_state | Москва |
|
||||
|
@ -38,7 +38,7 @@ Feature: Account
|
|||
|
||||
Scenario: of an excluded member
|
||||
Given there is an excluded member account with the following data:
|
||||
| username | kotovalexarian |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| country_state | Москва |
|
||||
|
|
|
@ -4,7 +4,7 @@ When 'there is a usual account with the following data:' do |table|
|
|||
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
|
||||
|
||||
create :usual_account,
|
||||
username: options[:username],
|
||||
nickname: options[:nickname],
|
||||
public_name: options[:public_name],
|
||||
biography: options[:biography]
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ When 'there is a supporter account with the following data:' do |table|
|
|||
person = create :supporter_person, regional_office: regional_office
|
||||
|
||||
create :personal_account,
|
||||
username: options[:username],
|
||||
nickname: options[:nickname],
|
||||
public_name: options[:public_name],
|
||||
biography: options[:biography],
|
||||
person: person
|
||||
|
@ -31,7 +31,7 @@ When 'there is a member account with the following data:' do |table|
|
|||
person = create :member_person, regional_office: regional_office
|
||||
|
||||
create :personal_account,
|
||||
username: options[:username],
|
||||
nickname: options[:nickname],
|
||||
public_name: options[:public_name],
|
||||
biography: options[:biography],
|
||||
person: person
|
||||
|
@ -45,7 +45,7 @@ When 'there is an excluded member account with the following data:' do |table|
|
|||
person = create :excluded_person, regional_office: regional_office
|
||||
|
||||
create :personal_account,
|
||||
username: options[:username],
|
||||
nickname: options[:nickname],
|
||||
public_name: options[:public_name],
|
||||
biography: options[:biography],
|
||||
person: person
|
||||
|
|
|
@ -21,7 +21,7 @@ Given 'I am signed in as superuser' do
|
|||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @account.user.account.username
|
||||
expect(page).to have_css 'ul > li > a', text: @account.nickname
|
||||
end
|
||||
|
||||
Given 'I am signed in with email {string}' do |email|
|
||||
|
@ -36,7 +36,7 @@ Given 'I am signed in with email {string}' do |email|
|
|||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @account.username
|
||||
expect(page).to have_css 'ul > li > a', text: @account.nickname
|
||||
end
|
||||
|
||||
Given 'I am signed in with email {string} ' \
|
||||
|
@ -52,7 +52,7 @@ Given 'I am signed in with email {string} ' \
|
|||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @account.username
|
||||
expect(page).to have_css 'ul > li > a', text: @account.nickname
|
||||
end
|
||||
|
||||
Given 'I am signed in as party supporter' do
|
||||
|
@ -69,7 +69,7 @@ Given 'I am signed in as party supporter' do
|
|||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @account.username
|
||||
expect(page).to have_css 'ul > li > a', text: @account.nickname
|
||||
end
|
||||
|
||||
Given 'I am signed in as party member' do
|
||||
|
@ -86,7 +86,7 @@ Given 'I am signed in as party member' do
|
|||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @account.username
|
||||
expect(page).to have_css 'ul > li > a', text: @account.nickname
|
||||
end
|
||||
|
||||
Given 'I am signed in as excluded party member' do
|
||||
|
@ -103,7 +103,7 @@ Given 'I am signed in as excluded party member' do
|
|||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @account.username
|
||||
expect(page).to have_css 'ul > li > a', text: @account.nickname
|
||||
end
|
||||
|
||||
When 'I try to sign in with email {string} ' \
|
||||
|
@ -119,7 +119,7 @@ When 'I try to sign in with email {string} ' \
|
|||
end
|
||||
|
||||
When 'I try to sign out' do
|
||||
click_on @account.username
|
||||
click_on @account.nickname
|
||||
click_on 'Выйти'
|
||||
end
|
||||
|
||||
|
@ -130,7 +130,7 @@ end
|
|||
|
||||
Then 'I am signed in as {string}' do |email|
|
||||
user = User.find_by! email: email
|
||||
expect(page).to have_css 'ul > li > a', text: user.account.username
|
||||
expect(page).to have_css 'ul > li > a', text: user.account.nickname
|
||||
end
|
||||
|
||||
Then 'I fail to sign in' do
|
||||
|
|
|
@ -48,22 +48,22 @@ RSpec.describe Account do
|
|||
|
||||
describe '#to_param' do
|
||||
specify do
|
||||
expect(subject.to_param).to eq subject.username
|
||||
expect(subject.to_param).to eq subject.nickname
|
||||
end
|
||||
end
|
||||
|
||||
describe '#username' do
|
||||
describe '#nickname' do
|
||||
def allow_value(*)
|
||||
super.for :username
|
||||
super.for :nickname
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of :username }
|
||||
it { is_expected.to validate_presence_of :nickname }
|
||||
|
||||
it do
|
||||
is_expected.to validate_length_of(:username).is_at_least(3).is_at_most(36)
|
||||
is_expected.to validate_length_of(:nickname).is_at_least(3).is_at_most(36)
|
||||
end
|
||||
|
||||
it { is_expected.to validate_uniqueness_of(:username).case_insensitive }
|
||||
it { is_expected.to validate_uniqueness_of(:nickname).case_insensitive }
|
||||
|
||||
it { is_expected.not_to allow_value nil }
|
||||
it { is_expected.not_to allow_value '' }
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /accounts/:username' do
|
||||
RSpec.describe 'GET /accounts/:nickname' do
|
||||
let!(:account_record) { create :personal_account }
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
get "/accounts/#{account_record.username}"
|
||||
get "/accounts/#{account_record.nickname}"
|
||||
end
|
||||
|
||||
for_account_types nil, :guest, :usual, :superuser do
|
||||
|
|
|
@ -7,7 +7,7 @@ RSpec.describe 'PATCH/PUT /settings/profile' do
|
|||
|
||||
let :account_attributes do
|
||||
{
|
||||
username: Faker::Internet.username(3..36, %w[_]),
|
||||
nickname: Faker::Internet.username(3..36, %w[_]),
|
||||
public_name: Faker::Name.name,
|
||||
biography: Faker::Lorem.paragraph,
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ RSpec.describe 'PATCH/PUT /settings/profile' do
|
|||
for_account_types :usual, :superuser do
|
||||
specify do
|
||||
expect { make_request }.to \
|
||||
change { current_account.reload.username }
|
||||
.from(current_account.username)
|
||||
.to(account_attributes[:username])
|
||||
change { current_account.reload.nickname }
|
||||
.from(current_account.nickname)
|
||||
.to(account_attributes[:nickname])
|
||||
end
|
||||
|
||||
specify do
|
||||
|
|
Reference in New Issue