1
0
Fork 0

Add model Relationship

This commit is contained in:
Alex Kotov 2019-04-27 19:24:04 +05:00
parent 786e0ae223
commit f6f1c32f21
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class Relationship < ApplicationRecord
################
# Associations #
################
belongs_to :person
end

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
class CreateRelationships < ActiveRecord::Migration[6.0]
def change
create_table :relationships do |t|
t.timestamps null: false
t.references :person, null: false, index: true, foreign_key: true
end
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: 2019_03_26_201603) do
ActiveRecord::Schema.define(version: 2019_04_27_141639) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -146,6 +146,13 @@ ActiveRecord::Schema.define(version: 2019_03_26_201603) do
t.index ["country_state_id"], name: "index_regional_offices_on_country_state_id", unique: true
end
create_table "relationships", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "person_id", null: false
t.index ["person_id"], name: "index_relationships_on_person_id"
end
create_table "resident_registrations", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
@ -213,6 +220,7 @@ ActiveRecord::Schema.define(version: 2019_03_26_201603) do
add_foreign_key "passports", "people"
add_foreign_key "people", "regional_offices"
add_foreign_key "regional_offices", "country_states"
add_foreign_key "relationships", "people"
add_foreign_key "resident_registrations", "people"
add_foreign_key "user_omniauths", "users"
add_foreign_key "users", "accounts"

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
FactoryBot.define do
factory :supporter_relationship, class: Relationship do
association :person, factory: :initial_person
end
end

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Relationship do
subject { create :supporter_relationship }
it { is_expected.to belong_to(:person).required }
end