1
0
Fork 0

Rename column Relationship#start_date to #from_date

This commit is contained in:
Alex Kotov 2019-07-20 11:22:47 +05:00
parent 0870c42319
commit 73db63f590
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
7 changed files with 23 additions and 23 deletions

View File

@ -14,12 +14,12 @@ class Person < ApplicationRecord
has_one :account, dependent: :restrict_with_exception
has_many :relationships,
-> { order(start_date: :asc) },
-> { order(from_date: :asc) },
inverse_of: :person,
dependent: :restrict_with_exception
has_one :current_relationship,
-> { order(start_date: :desc) },
-> { order(from_date: :desc) },
class_name: 'Relationship',
inverse_of: :person,
dependent: :restrict_with_exception

View File

@ -14,7 +14,7 @@ class Relationship < ApplicationRecord
# Validations #
###############
validates :start_date, presence: true, uniqueness: { scope: :person_id }
validates :from_date, presence: true, uniqueness: { scope: :person_id }
validates :status, presence: true
end

View File

@ -11,10 +11,10 @@ class CreateRelationships < ActiveRecord::Migration[6.0]
t.references :regional_office,
null: false, index: true, foreign_key: true
t.date :start_date, null: false, index: true
t.integer :status, null: false, index: true
t.date :from_date, null: false, index: true
t.integer :status, null: false, index: true
t.index %i[person_id start_date], unique: true
t.index %i[person_id from_date], unique: true
end
end
end

View File

@ -399,7 +399,7 @@ CREATE TABLE public.relationships (
updated_at timestamp(6) without time zone NOT NULL,
person_id bigint NOT NULL,
regional_office_id bigint NOT NULL,
start_date date NOT NULL,
from_date date NOT NULL,
status integer NOT NULL
);
@ -893,10 +893,10 @@ CREATE UNIQUE INDEX index_regional_offices_on_federal_subject_id ON public.regio
--
-- Name: index_relationships_on_person_id_and_start_date; Type: INDEX; Schema: public; Owner: -
-- Name: index_relationships_on_person_id_and_from_date; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_relationships_on_person_id_and_start_date ON public.relationships USING btree (person_id, start_date);
CREATE UNIQUE INDEX index_relationships_on_person_id_and_from_date ON public.relationships USING btree (person_id, from_date);
--
@ -907,10 +907,10 @@ CREATE INDEX index_relationships_on_regional_office_id ON public.relationships U
--
-- Name: index_relationships_on_start_date; Type: INDEX; Schema: public; Owner: -
-- Name: index_relationships_on_from_date; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_relationships_on_start_date ON public.relationships USING btree (start_date);
CREATE INDEX index_relationships_on_from_date ON public.relationships USING btree (from_date);
--

View File

@ -5,7 +5,7 @@ FactoryBot.define do
association :person, factory: :initial_person
association :regional_office
sequence :start_date do |n|
sequence :from_date do |n|
Date.new rand((10 * n)...(11 * n)), rand(1..12), rand(1..28)
end

View File

@ -18,7 +18,7 @@ RSpec.describe Person do
have_many(:relationships)
.inverse_of(:person)
.dependent(:restrict_with_exception)
.order(start_date: :asc)
.order(from_date: :asc)
end
it do
@ -27,7 +27,7 @@ RSpec.describe Person do
.class_name('Relationship')
.inverse_of(:person)
.dependent(:restrict_with_exception)
.order(start_date: :desc)
.order(from_date: :desc)
end
it do
@ -48,19 +48,19 @@ RSpec.describe Person do
let! :relationship_2 do
create :supporter_relationship,
person: subject,
start_date: 4.days.ago
from_date: 4.days.ago
end
let! :relationship_3 do
create :supporter_relationship,
person: subject,
start_date: 2.days.ago
from_date: 2.days.ago
end
let! :relationship_1 do
create :supporter_relationship,
person: subject,
start_date: 6.days.ago
from_date: 6.days.ago
end
specify do
@ -76,19 +76,19 @@ RSpec.describe Person do
let! :relationship_2 do
create :supporter_relationship,
person: subject,
start_date: 4.days.ago
from_date: 4.days.ago
end
let! :relationship_3 do
create :supporter_relationship,
person: subject,
start_date: 2.days.ago
from_date: 2.days.ago
end
let! :relationship_1 do
create :supporter_relationship,
person: subject,
start_date: 6.days.ago
from_date: 6.days.ago
end
specify do

View File

@ -8,12 +8,12 @@ RSpec.describe Relationship do
it { is_expected.to belong_to(:person).required }
it { is_expected.to belong_to(:regional_office).required }
describe '#start_date' do
it { is_expected.to validate_presence_of :start_date }
describe '#from_date' do
it { is_expected.to validate_presence_of :from_date }
it do
is_expected.to \
validate_uniqueness_of(:start_date)
validate_uniqueness_of(:from_date)
.scoped_to(:person_id)
end
end