Add attribute Account#public_name
This commit is contained in:
parent
d9a978504f
commit
a96c7cfd8a
7 changed files with 32 additions and 1 deletions
|
@ -32,6 +32,11 @@ class Account < ApplicationRecord
|
|||
format: USERNAME_RE,
|
||||
uniqueness: { case_sensitive: false }
|
||||
|
||||
validates :public_name,
|
||||
allow_nil: true,
|
||||
allow_blank: false,
|
||||
presence: true
|
||||
|
||||
validates :biography, length: { maximum: 10_000 }
|
||||
|
||||
def to_param
|
||||
|
|
|
@ -35,6 +35,7 @@ en:
|
|||
account:
|
||||
id: ID
|
||||
username: Username
|
||||
public_name: Public name
|
||||
biography: Bio
|
||||
account_telegram_contact:
|
||||
id: ID
|
||||
|
|
|
@ -35,6 +35,7 @@ ru:
|
|||
account:
|
||||
id: ID
|
||||
username: Имя пользователя
|
||||
public_name: Публичное имя
|
||||
biography: Биография
|
||||
account_telegram_contact:
|
||||
id: ID
|
||||
|
|
7
db/migrate/20190201214347_add_public_name_to_accounts.rb
Normal file
7
db/migrate/20190201214347_add_public_name_to_accounts.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPublicNameToAccounts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :accounts, :public_name, :string
|
||||
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_02_01_035804) do
|
||||
ActiveRecord::Schema.define(version: 2019_02_01_214347) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -41,6 +41,7 @@ ActiveRecord::Schema.define(version: 2019_02_01_035804) do
|
|||
t.bigint "person_id"
|
||||
t.string "username", null: false
|
||||
t.text "biography"
|
||||
t.string "public_name"
|
||||
t.index ["person_id"], name: "index_accounts_on_person_id", unique: true
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
FactoryBot.define do
|
||||
factory :guest_account, class: Account do
|
||||
public_name { Faker::Lorem.name }
|
||||
biography { Faker::Lorem.paragraph }
|
||||
end
|
||||
|
||||
|
|
|
@ -77,6 +77,21 @@ RSpec.describe Account do
|
|||
it { is_expected.not_to allow_value '1foo' }
|
||||
end
|
||||
|
||||
describe '#public_name' do
|
||||
def allow_value(*)
|
||||
super.for :public_name
|
||||
end
|
||||
|
||||
it { is_expected.to allow_value nil }
|
||||
|
||||
it { is_expected.not_to allow_value '' }
|
||||
it { is_expected.not_to allow_value ' ' }
|
||||
|
||||
it { is_expected.to allow_value Faker::Name.name }
|
||||
it { is_expected.to allow_value Faker::Name.first_name }
|
||||
it { is_expected.to allow_value 'Foo Bar' }
|
||||
end
|
||||
|
||||
describe '#biography' do
|
||||
it { is_expected.not_to validate_presence_of :biography }
|
||||
it { is_expected.to validate_length_of(:biography).is_at_most(10_000) }
|
||||
|
|
Reference in a new issue