1
0
Fork 0

Add columns Person#sex, #date_of_birth, #place_of_birth

This commit is contained in:
Alex Kotov 2019-03-27 01:09:10 +05:00
parent f717f3ba60
commit d163b38069
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 26 additions and 1 deletions

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class Person < ApplicationRecord class Person < ApplicationRecord
enum sex: %i[male female]
################ ################
# Associations # # Associations #
################ ################
@ -31,6 +33,9 @@ class Person < ApplicationRecord
validates :first_name, presence: true validates :first_name, presence: true
validates :last_name, presence: true validates :last_name, presence: true
validates :sex, presence: true
validates :date_of_birth, presence: true
validates :place_of_birth, presence: true
validate :membership_is_possible validate :membership_is_possible
validate :membership_dates_are_not_in_future validate :membership_dates_are_not_in_future

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
class AddPersonalDataToPeople < ActiveRecord::Migration[6.0]
def change
# rubocop:disable Rails/NotNullColumn
add_column :people, :sex, :integer, null: false
add_column :people, :date_of_birth, :date, null: false
add_column :people, :place_of_birth, :string, null: false
# rubocop:enable Rails/NotNullColumn
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_03_26_004506) do ActiveRecord::Schema.define(version: 2019_03_26_200244) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -133,6 +133,9 @@ ActiveRecord::Schema.define(version: 2019_03_26_004506) do
t.string "first_name", null: false t.string "first_name", null: false
t.string "middle_name" t.string "middle_name"
t.string "last_name", null: false t.string "last_name", null: false
t.integer "sex", null: false
t.date "date_of_birth", null: false
t.string "place_of_birth", null: false
t.index ["regional_office_id"], name: "index_people_on_regional_office_id" t.index ["regional_office_id"], name: "index_people_on_regional_office_id"
end end

View file

@ -5,6 +5,9 @@ FactoryBot.define do
first_name { Faker::Name.first_name } first_name { Faker::Name.first_name }
middle_name { Faker::Name.first_name } middle_name { Faker::Name.first_name }
last_name { Faker::Name.last_name } last_name { Faker::Name.last_name }
sex { Person.sexes.keys.sample }
date_of_birth { Faker::Date.backward }
place_of_birth { Faker::Address.city }
end end
factory :supporter_person, parent: :initial_person do factory :supporter_person, parent: :initial_person do

View file

@ -35,6 +35,9 @@ RSpec.describe Person do
it { is_expected.to validate_presence_of :first_name } it { is_expected.to validate_presence_of :first_name }
it { is_expected.not_to validate_presence_of :middle_name } it { is_expected.not_to validate_presence_of :middle_name }
it { is_expected.to validate_presence_of :last_name } it { is_expected.to validate_presence_of :last_name }
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 }
describe '#middle_name' do describe '#middle_name' do
context 'when it is empty' do context 'when it is empty' do