diff --git a/app/models/account.rb b/app/models/account.rb index 2f7f81c..d0fc1fc 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -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 diff --git a/config/locales/activerecord/en.yml b/config/locales/activerecord/en.yml index b1b2ef1..871d91b 100644 --- a/config/locales/activerecord/en.yml +++ b/config/locales/activerecord/en.yml @@ -35,6 +35,7 @@ en: account: id: ID username: Username + public_name: Public name biography: Bio account_telegram_contact: id: ID diff --git a/config/locales/activerecord/ru.yml b/config/locales/activerecord/ru.yml index 3c0b1f3..7738aef 100644 --- a/config/locales/activerecord/ru.yml +++ b/config/locales/activerecord/ru.yml @@ -35,6 +35,7 @@ ru: account: id: ID username: Имя пользователя + public_name: Публичное имя biography: Биография account_telegram_contact: id: ID diff --git a/db/migrate/20190201214347_add_public_name_to_accounts.rb b/db/migrate/20190201214347_add_public_name_to_accounts.rb new file mode 100644 index 0000000..64f3631 --- /dev/null +++ b/db/migrate/20190201214347_add_public_name_to_accounts.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddPublicNameToAccounts < ActiveRecord::Migration[6.0] + def change + add_column :accounts, :public_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 32fa24c..68689df 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/factories/accounts.rb b/factories/accounts.rb index 845c99b..83c68f8 100644 --- a/factories/accounts.rb +++ b/factories/accounts.rb @@ -2,6 +2,7 @@ FactoryBot.define do factory :guest_account, class: Account do + public_name { Faker::Lorem.name } biography { Faker::Lorem.paragraph } end diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 89a6b58..c3f7dc7 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -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) }