Add model Passport
This commit is contained in:
parent
b5794b89ff
commit
fabdc586eb
7 changed files with 150 additions and 1 deletions
20
app/models/passport.rb
Normal file
20
app/models/passport.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Passport < ApplicationRecord
|
||||
enum sexes: %i[male female]
|
||||
|
||||
validates :surname, presence: true
|
||||
validates :given_name, presence: true
|
||||
validates :sex, presence: true
|
||||
validates :date_of_birth, presence: true
|
||||
validates :place_of_birth, presence: true
|
||||
validates :series, presence: true
|
||||
validates :number, presence: true
|
||||
validates :issued_by, presence: true
|
||||
validates :unit_code, presence: true
|
||||
validates :date_of_issue, presence: true
|
||||
|
||||
before_validation do
|
||||
self.patronymic = nil if patronymic.blank?
|
||||
end
|
||||
end
|
|
@ -4,6 +4,9 @@ en:
|
|||
membership_application:
|
||||
one: Membership application
|
||||
other: Membership applications
|
||||
passport:
|
||||
one: Passport
|
||||
other: Passports
|
||||
user:
|
||||
one: User
|
||||
other: Users
|
||||
|
@ -19,6 +22,21 @@ en:
|
|||
telegram_username: Telegram username
|
||||
organization_membership: Membership in other social organizations
|
||||
comment: Comment
|
||||
passport:
|
||||
surname: Surname
|
||||
given_name: Given names
|
||||
patronymic: Patronymic
|
||||
sex: Sex
|
||||
date_of_birth: Date of birth
|
||||
place_of_birth: Place of birth
|
||||
series: Series
|
||||
number: Number
|
||||
issued_by: Issued by
|
||||
unit_code: Unit code
|
||||
date_of_issue: Date of issue
|
||||
passport/sex:
|
||||
male: Male
|
||||
female: Female
|
||||
user:
|
||||
confirmation_sent_at: Confirmation sent at
|
||||
confirmation_token: Confirmation token
|
||||
|
|
|
@ -4,6 +4,9 @@ ru:
|
|||
membership_application:
|
||||
one: Заявление на вступление
|
||||
other: Заявления на вступление
|
||||
passport:
|
||||
one: Паспорт
|
||||
other: Паспорта
|
||||
user:
|
||||
one: Пользователь
|
||||
other: Пользователи
|
||||
|
@ -19,6 +22,21 @@ ru:
|
|||
telegram_username: Имя пользователя в Telegram
|
||||
organization_membership: Членство в других общественных организациях
|
||||
comment: Комментарий
|
||||
passport:
|
||||
surname: Фамилия
|
||||
given_name: Имя
|
||||
patronymic: Отчество
|
||||
sex: Пол
|
||||
date_of_birth: Дата рождения
|
||||
place_of_birth: Место рождения
|
||||
series: Серия
|
||||
number: Номер
|
||||
issued_by: Кем выдан
|
||||
unit_code: Код подразделения
|
||||
date_of_issue: Дата выдачи
|
||||
passport/sex:
|
||||
male: Мужской
|
||||
female: Женский
|
||||
user:
|
||||
confirmation_sent_at: Дата отправки подтверждения
|
||||
confirmation_token: Токен подтверждения
|
||||
|
|
21
db/migrate/20181130010029_create_passports.rb
Normal file
21
db/migrate/20181130010029_create_passports.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreatePassports < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :passports do |t|
|
||||
t.timestamps null: false
|
||||
|
||||
t.string :surname, null: false
|
||||
t.string :given_name, null: false
|
||||
t.string :patronymic
|
||||
t.integer :sex, null: false
|
||||
t.date :date_of_birth, null: false
|
||||
t.string :place_of_birth, null: false
|
||||
t.integer :series, null: false
|
||||
t.integer :number, null: false
|
||||
t.string :issued_by, null: false
|
||||
t.string :unit_code, null: false
|
||||
t.date :date_of_issue, null: false
|
||||
end
|
||||
end
|
||||
end
|
18
db/schema.rb
18
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: 2018_11_29_231814) do
|
||||
ActiveRecord::Schema.define(version: 2018_11_30_010029) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -30,6 +30,22 @@ ActiveRecord::Schema.define(version: 2018_11_29_231814) do
|
|||
t.text "comment"
|
||||
end
|
||||
|
||||
create_table "passports", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "surname", null: false
|
||||
t.string "given_name", null: false
|
||||
t.string "patronymic"
|
||||
t.integer "sex", null: false
|
||||
t.date "date_of_birth", null: false
|
||||
t.string "place_of_birth", null: false
|
||||
t.integer "series", null: false
|
||||
t.integer "number", null: false
|
||||
t.string "issued_by", null: false
|
||||
t.string "unit_code", null: false
|
||||
t.date "date_of_issue", null: false
|
||||
end
|
||||
|
||||
create_table "roles", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
|
|
19
factories/passports.rb
Normal file
19
factories/passports.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :passport do
|
||||
surname { Faker::Name.last_name }
|
||||
given_name { Faker::Name.first_name }
|
||||
patronymic { Faker::Name.first_name }
|
||||
sex { Passport.sexes.keys.sample }
|
||||
date_of_birth { Faker::Date.backward }
|
||||
place_of_birth { Faker::Address.city }
|
||||
series { rand 0..9999 }
|
||||
number { rand 0..999_999 }
|
||||
issued_by { Faker::Lorem.sentence }
|
||||
unit_code do
|
||||
"#{rand(0..999).to_s.rjust(3, '0')}-#{rand(0..999).to_s.rjust(3, '0')}"
|
||||
end
|
||||
date_of_issue { Faker::Date.backward }
|
||||
end
|
||||
end
|
37
spec/models/passport_spec.rb
Normal file
37
spec/models/passport_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Passport, type: :model do
|
||||
subject { create :passport }
|
||||
|
||||
it { is_expected.to validate_presence_of :surname }
|
||||
it { is_expected.to validate_presence_of :given_name }
|
||||
it { is_expected.not_to validate_presence_of :patronymic }
|
||||
it { is_expected.to validate_presence_of :sex }
|
||||
it { is_expected.to validate_presence_of :date_of_birth }
|
||||
it { is_expected.to validate_presence_of :place_of_birth }
|
||||
it { is_expected.to validate_presence_of :series }
|
||||
it { is_expected.to validate_presence_of :number }
|
||||
it { is_expected.to validate_presence_of :issued_by }
|
||||
it { is_expected.to validate_presence_of :unit_code }
|
||||
it { is_expected.to validate_presence_of :date_of_issue }
|
||||
|
||||
describe '#patronymic' do
|
||||
context 'when it is empty' do
|
||||
subject { create :passport, patronymic: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.patronymic).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :passport, patronymic: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.patronymic).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue