1
0
Fork 0

Add attribute Person#supporter_since

This commit is contained in:
Alex Kotov 2018-12-15 10:51:44 +05:00
parent 7a3856cc52
commit c00e1fdf18
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
4 changed files with 35 additions and 1 deletions

View File

@ -11,6 +11,8 @@ class Person < ApplicationRecord
through: :account,
source: :own_membership_app
validate :supporter_since_not_in_future
def related_to_party?
party_supporter? || party_member? || excluded_from_party?
end
@ -26,4 +28,12 @@ class Person < ApplicationRecord
def excluded_from_party?
false
end
private
def supporter_since_not_in_future
return if supporter_since.nil?
errors.add :supporter_since unless supporter_since <= Time.zone.today
end
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddSupporterSinceToPeople < ActiveRecord::Migration[5.2]
def change
add_column :people, :supporter_since, :date
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: 2018_12_15_040559) do
ActiveRecord::Schema.define(version: 2018_12_15_053720) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 2018_12_15_040559) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "regional_office_id"
t.date "supporter_since"
t.index ["regional_office_id"], name: "index_people_on_regional_office_id"
end

View File

@ -24,4 +24,20 @@ RSpec.describe Person do
pending '#party_supporter?'
pending '#party_member?'
pending '#excluded_from_party?'
describe '#supporter_since' do
def allow_value(*)
super.for :supporter_since
end
it { is_expected.not_to validate_presence_of :supporter_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
end