Add attribute Relationship#status
This commit is contained in:
parent
d6bb7ea4bd
commit
027de3914e
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue