1
0
Fork 0

Add attribute Relationship#active_since

This commit is contained in:
Alex Kotov 2019-06-05 06:37:55 +05:00
parent ae6cff39cc
commit d6bb7ea4bd
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 23 additions and 1 deletions

View file

@ -19,4 +19,6 @@ class Relationship < ApplicationRecord
only_integer: true,
greater_than_or_equal_to: 0,
}
validates :active_since, presence: true
end

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
class AddActiveSinceToRelationships < ActiveRecord::Migration[6.0]
def change
# rubocop:disable Rails/NotNullColumn
add_column :relationships, :active_since, :date, null: false
# rubocop:enable Rails/NotNullColumn
add_index :relationships, :active_since
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_06_05_011616) do
ActiveRecord::Schema.define(version: 2019_06_05_012813) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -133,6 +133,8 @@ ActiveRecord::Schema.define(version: 2019_06_05_011616) do
t.bigint "person_id", null: false
t.bigint "regional_office_id", null: false
t.integer "number", null: false
t.date "active_since", 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"
end

View file

@ -6,6 +6,10 @@ FactoryBot.define do
association :regional_office
sequence :number
sequence :active_since do |n|
Date.new rand((10 * n)...(11 * n)), rand(1..12), rand(1..28)
end
end
factory :member_relationship, parent: :supporter_relationship

View file

@ -20,4 +20,8 @@ RSpec.describe Relationship do
.is_greater_than_or_equal_to(0)
end
end
describe '#active_since' do
it { is_expected.to validate_presence_of :active_since }
end
end