diff --git a/app/models/relationship.rb b/app/models/relationship.rb index 339b3da..7d4fc39 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Relationship < ApplicationRecord + enum status: %i[unrelated supporter member excluded] + ################ # Associations # ################ @@ -21,4 +23,6 @@ class Relationship < ApplicationRecord } validates :active_since, presence: true + + validates :status, presence: true end diff --git a/db/migrate/20190605022109_add_status_to_relationships.rb b/db/migrate/20190605022109_add_status_to_relationships.rb new file mode 100644 index 0000000..bae753e --- /dev/null +++ b/db/migrate/20190605022109_add_status_to_relationships.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddStatusToRelationships < ActiveRecord::Migration[6.0] + def change + # rubocop:disable Rails/NotNullColumn + add_column :relationships, :status, :integer, null: false + # rubocop:enable Rails/NotNullColumn + add_index :relationships, :status + end +end diff --git a/db/schema.rb b/db/schema.rb index 4a7fbec..a66fb69 100644 --- a/db/schema.rb +++ b/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_06_05_012813) do +ActiveRecord::Schema.define(version: 2019_06_05_022109) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -134,9 +134,11 @@ ActiveRecord::Schema.define(version: 2019_06_05_012813) do t.bigint "regional_office_id", null: false t.integer "number", null: false t.date "active_since", null: false + t.integer "status", null: false t.index ["active_since"], name: "index_relationships_on_active_since" t.index ["person_id", "number"], name: "index_relationships_on_person_id_and_number", unique: true t.index ["regional_office_id"], name: "index_relationships_on_regional_office_id" + t.index ["status"], name: "index_relationships_on_status" end create_table "resident_registrations", force: :cascade do |t| diff --git a/factories/relationships.rb b/factories/relationships.rb index 4d4b212..505f220 100644 --- a/factories/relationships.rb +++ b/factories/relationships.rb @@ -10,9 +10,19 @@ FactoryBot.define do sequence :active_since do |n| Date.new rand((10 * n)...(11 * n)), rand(1..12), rand(1..28) end + + status { :supporter } end - factory :member_relationship, parent: :supporter_relationship - factory :excluded_supporter_relationship, parent: :supporter_relationship - factory :excluded_member_relationship, parent: :member_relationship + factory :member_relationship, parent: :supporter_relationship do + status { :member } + end + + factory :excluded_supporter_relationship, parent: :supporter_relationship do + status { :excluded } + end + + factory :excluded_member_relationship, parent: :member_relationship do + status { :excluded } + end end diff --git a/spec/models/relationship_spec.rb b/spec/models/relationship_spec.rb index 351cf5a..0f6b03d 100644 --- a/spec/models/relationship_spec.rb +++ b/spec/models/relationship_spec.rb @@ -24,4 +24,8 @@ RSpec.describe Relationship do describe '#active_since' do it { is_expected.to validate_presence_of :active_since } end + + describe '#status' do + it { is_expected.to validate_presence_of :status } + end end