1
0
Fork 0

Add attribute Person#member_since

This commit is contained in:
Alex Kotov 2019-01-29 06:42:25 +05:00
parent 2a110bd975
commit 276d9131bc
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 32 additions and 1 deletions

View file

@ -12,6 +12,7 @@ class Person < ApplicationRecord
source: :own_membership_app source: :own_membership_app
validate :supporter_since_not_in_future validate :supporter_since_not_in_future
validate :member_since_not_in_future
def related_to_party? def related_to_party?
party_supporter? || party_member? || excluded_from_party? party_supporter? || party_member? || excluded_from_party?
@ -36,4 +37,10 @@ private
errors.add :supporter_since unless supporter_since <= Time.zone.today errors.add :supporter_since unless supporter_since <= Time.zone.today
end end
def member_since_not_in_future
return if member_since.nil?
errors.add :member_since unless member_since <= Time.zone.today
end
end end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddMemberSinceToPeople < ActiveRecord::Migration[5.2]
def change
add_column :people, :member_since, :date
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_12_15_053720) do ActiveRecord::Schema.define(version: 2019_01_29_013754) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -128,6 +128,7 @@ ActiveRecord::Schema.define(version: 2018_12_15_053720) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.bigint "regional_office_id" t.bigint "regional_office_id"
t.date "supporter_since" t.date "supporter_since"
t.date "member_since"
t.index ["regional_office_id"], name: "index_people_on_regional_office_id" t.index ["regional_office_id"], name: "index_people_on_regional_office_id"
end end

View file

@ -41,6 +41,22 @@ RSpec.describe Person do
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date } it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
end end
describe '#member_since' do
def allow_value(*)
super.for :member_since
end
it { is_expected.not_to validate_presence_of :member_since }
it { is_expected.to allow_value Time.zone.today }
it { is_expected.to allow_value Time.zone.yesterday }
it { is_expected.to allow_value rand(10_000).days.ago.to_date }
it { is_expected.not_to allow_value Time.zone.tomorrow }
it { is_expected.not_to allow_value 1.day.from_now.to_date }
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
end
describe '#party_supporter?' do describe '#party_supporter?' do
let(:result) { subject.party_supporter? } let(:result) { subject.party_supporter? }