1
0
Fork 0

Add association Person#regional_office

This commit is contained in:
Alex Kotov 2018-12-15 09:09:43 +05:00
parent 05915d2b68
commit d229db4bc1
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
7 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
class Person < ApplicationRecord
belongs_to :regional_office
has_one :account, dependent: :restrict_with_exception
end

View File

@ -5,5 +5,7 @@ class RegionalOffice < ApplicationRecord
has_many :membership_apps, through: :country_state
has_many :people, dependent: :restrict_with_exception
validates :country_state_id, uniqueness: true
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddRegionalOfficeToPeople < ActiveRecord::Migration[5.2]
def change
add_reference :people, :regional_office, foreign_key: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_12_13_053336) do
ActiveRecord::Schema.define(version: 2018_12_15_040559) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -126,6 +126,8 @@ ActiveRecord::Schema.define(version: 2018_12_13_053336) do
create_table "people", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "regional_office_id"
t.index ["regional_office_id"], name: "index_people_on_regional_office_id"
end
create_table "regional_offices", force: :cascade do |t|
@ -214,6 +216,7 @@ ActiveRecord::Schema.define(version: 2018_12_13_053336) do
add_foreign_key "passport_confirmations", "accounts"
add_foreign_key "passport_confirmations", "passports"
add_foreign_key "passport_maps", "passports"
add_foreign_key "people", "regional_offices"
add_foreign_key "regional_offices", "country_states"
add_foreign_key "user_omniauths", "users"
add_foreign_key "users", "accounts"

View File

@ -2,5 +2,6 @@
FactoryBot.define do
factory :person do
association :regional_office
end
end

View File

@ -5,11 +5,13 @@ require 'rails_helper'
RSpec.describe Person do
subject { create :person }
it { is_expected.to belong_to(:regional_office) }
it do
is_expected.to \
have_one(:account)
.dependent(:restrict_with_exception)
end
pending "add some examples to (or delete) #{__FILE__}"
it { is_expected.not_to validate_presence_of :regional_office }
end

View File

@ -9,6 +9,8 @@ RSpec.describe RegionalOffice do
it { is_expected.to have_many(:membership_apps).through(:country_state) }
it { is_expected.to have_many(:people).dependent(:restrict_with_exception) }
it do
is_expected.to \
validate_presence_of(:country_state)