Add model Relationship
This commit is contained in:
parent
786e0ae223
commit
f6f1c32f21
5 changed files with 45 additions and 1 deletions
9
app/models/relationship.rb
Normal file
9
app/models/relationship.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Relationship < ApplicationRecord
|
||||
################
|
||||
# Associations #
|
||||
################
|
||||
|
||||
belongs_to :person
|
||||
end
|
11
db/migrate/20190427141639_create_relationships.rb
Normal file
11
db/migrate/20190427141639_create_relationships.rb
Normal 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
|
10
db/schema.rb
10
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: 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"
|
||||
|
|
7
factories/relationships.rb
Normal file
7
factories/relationships.rb
Normal 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
|
9
spec/models/relationship_spec.rb
Normal file
9
spec/models/relationship_spec.rb
Normal 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
|
Reference in a new issue