Add attribute Person#member_since
This commit is contained in:
parent
2a110bd975
commit
276d9131bc
4 changed files with 32 additions and 1 deletions
|
@ -12,6 +12,7 @@ class Person < ApplicationRecord
|
|||
source: :own_membership_app
|
||||
|
||||
validate :supporter_since_not_in_future
|
||||
validate :member_since_not_in_future
|
||||
|
||||
def related_to_party?
|
||||
party_supporter? || party_member? || excluded_from_party?
|
||||
|
@ -36,4 +37,10 @@ private
|
|||
|
||||
errors.add :supporter_since unless supporter_since <= Time.zone.today
|
||||
end
|
||||
|
||||
def member_since_not_in_future
|
||||
return if member_since.nil?
|
||||
|
||||
errors.add :member_since unless member_since <= Time.zone.today
|
||||
end
|
||||
end
|
||||
|
|
7
db/migrate/20190129013754_add_member_since_to_people.rb
Normal file
7
db/migrate/20190129013754_add_member_since_to_people.rb
Normal 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
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# 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
|
||||
enable_extension "plpgsql"
|
||||
|
@ -128,6 +128,7 @@ ActiveRecord::Schema.define(version: 2018_12_15_053720) do
|
|||
t.datetime "updated_at", null: false
|
||||
t.bigint "regional_office_id"
|
||||
t.date "supporter_since"
|
||||
t.date "member_since"
|
||||
t.index ["regional_office_id"], name: "index_people_on_regional_office_id"
|
||||
end
|
||||
|
||||
|
|
|
@ -41,6 +41,22 @@ RSpec.describe Person do
|
|||
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
|
||||
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
|
||||
let(:result) { subject.party_supporter? }
|
||||
|
||||
|
|
Reference in a new issue