Add columns Person#sex, #date_of_birth, #place_of_birth
This commit is contained in:
parent
f717f3ba60
commit
d163b38069
5 changed files with 26 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Person < ApplicationRecord
|
||||
enum sex: %i[male female]
|
||||
|
||||
################
|
||||
# Associations #
|
||||
################
|
||||
|
@ -31,6 +33,9 @@ class Person < ApplicationRecord
|
|||
|
||||
validates :first_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_dates_are_not_in_future
|
||||
|
|
11
db/migrate/20190326200244_add_personal_data_to_people.rb
Normal file
11
db/migrate/20190326200244_add_personal_data_to_people.rb
Normal 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
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# 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
|
||||
enable_extension "plpgsql"
|
||||
|
@ -133,6 +133,9 @@ ActiveRecord::Schema.define(version: 2019_03_26_004506) do
|
|||
t.string "first_name", null: false
|
||||
t.string "middle_name"
|
||||
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"
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@ FactoryBot.define do
|
|||
first_name { Faker::Name.first_name }
|
||||
middle_name { Faker::Name.first_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
|
||||
|
||||
factory :supporter_person, parent: :initial_person do
|
||||
|
|
|
@ -35,6 +35,9 @@ RSpec.describe Person do
|
|||
it { is_expected.to validate_presence_of :first_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 :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
|
||||
context 'when it is empty' do
|
||||
|
|
Reference in a new issue