Add attribute Person#excluded_since; method Person#excluded_from_party?
This commit is contained in:
parent
baf32da0e3
commit
c191c8bda7
|
@ -13,17 +13,18 @@ class Person < ApplicationRecord
|
|||
|
||||
validate :supporter_since_not_in_future
|
||||
validate :member_since_not_in_future
|
||||
validate :excluded_since_not_in_future
|
||||
|
||||
def party_supporter?
|
||||
supporter_since.present?
|
||||
supporter_since.present? && !excluded_from_party?
|
||||
end
|
||||
|
||||
def party_member?
|
||||
member_since.present?
|
||||
member_since.present? && !excluded_from_party?
|
||||
end
|
||||
|
||||
def excluded_from_party?
|
||||
false
|
||||
excluded_since.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -39,4 +40,10 @@ private
|
|||
|
||||
errors.add :member_since unless member_since <= Time.zone.today
|
||||
end
|
||||
|
||||
def excluded_since_not_in_future
|
||||
return if excluded_since.nil?
|
||||
|
||||
errors.add :excluded_since unless excluded_since <= Time.zone.today
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<% elsif @membership_app.person&.party_supporter? %>
|
||||
<h1><%= translate '.congratulations' %></h1>
|
||||
<p class="lead"><%= translate '.lead_congratulations_supporter' %></p>
|
||||
<% elsif @membership_app.person&.excluded_from_party? %>
|
||||
<h1><%= translate '.excluded' %></h1>
|
||||
<p class="lead"><%= translate '.lead_excluded' %></p>
|
||||
<% else %>
|
||||
<h1><%= translate '.header' %></h1>
|
||||
<p class="lead"><%= translate '.lead_text' %></p>
|
||||
|
|
|
@ -14,6 +14,11 @@ en:
|
|||
You are already a party supporter!
|
||||
lead_congratulations_member: >
|
||||
You are already a party member!
|
||||
excluded: >
|
||||
You are excluded from party
|
||||
lead_excluded:
|
||||
You was excluded from Libertarian party of Russia
|
||||
and can not apply for entry.
|
||||
header: Your application is being processed
|
||||
lead_text: >
|
||||
You can track the status of your application on this page. Save it
|
||||
|
|
|
@ -14,6 +14,11 @@ ru:
|
|||
Вы уже являетесь сторонником Либертарианской партии России!
|
||||
lead_congratulations_member: >
|
||||
Вы уже являетесь членом Либертарианской партии России!
|
||||
excluded: >
|
||||
Вы исключены из партии
|
||||
lead_excluded:
|
||||
Вы были исключены из Либертарианской партии России
|
||||
и не можете подать заявление на вступление.
|
||||
header: Ваше заявление в обработке
|
||||
lead_text: >
|
||||
На данной странице вы можете отслеживать статус вашего заявления.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddExcludedSinceToPeople < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :people, :excluded_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: 2019_01_29_013754) do
|
||||
ActiveRecord::Schema.define(version: 2019_01_29_015721) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -129,6 +129,7 @@ ActiveRecord::Schema.define(version: 2019_01_29_013754) do
|
|||
t.bigint "regional_office_id"
|
||||
t.date "supporter_since"
|
||||
t.date "member_since"
|
||||
t.date "excluded_since"
|
||||
t.index ["regional_office_id"], name: "index_people_on_regional_office_id"
|
||||
end
|
||||
|
||||
|
|
|
@ -10,4 +10,8 @@ FactoryBot.define do
|
|||
factory :member_person, parent: :supporter_person do
|
||||
member_since { rand(10_000).days.ago.to_date }
|
||||
end
|
||||
|
||||
factory :excluded_person, parent: :member_person do
|
||||
excluded_since { rand(10_000).days.ago.to_date }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,3 +27,9 @@ Feature: Membership application
|
|||
When I visit the main page
|
||||
And I click the button "Ваше заявление"
|
||||
Then I see that I am already a party member
|
||||
|
||||
Scenario: as an excluded member
|
||||
Given I am signed in as excluded party member
|
||||
When I visit the main page
|
||||
And I click the button "Ваше заявление"
|
||||
Then I see that I am excluded from party
|
||||
|
|
|
@ -38,6 +38,15 @@ Then 'I see that I am already a party member' do
|
|||
'Либертарианской партии России!'
|
||||
end
|
||||
|
||||
Then 'I see that I am excluded from party' do
|
||||
expect(page.current_path).to eq '/application'
|
||||
expect(page).to have_css 'h1', text: 'Вы исключены из партии'
|
||||
expect(page).to have_css 'p.lead',
|
||||
text: 'Вы были исключены из ' \
|
||||
'Либертарианской партии России ' \
|
||||
'и не можете подать заявление на вступление.'
|
||||
end
|
||||
|
||||
When 'I send a membership application' do
|
||||
visit '/join'
|
||||
|
||||
|
|
|
@ -76,6 +76,24 @@ Given 'I am signed in as party member' do
|
|||
expect(page).to have_css 'ul > li > a', text: @user.email
|
||||
end
|
||||
|
||||
Given 'I am signed in as excluded party member' do
|
||||
@person = create :excluded_person
|
||||
@account = create :usual_account, person: @person
|
||||
create :membership_app, account: @account
|
||||
@user = @account.user
|
||||
|
||||
visit '/users/sign_in'
|
||||
|
||||
within 'form' do
|
||||
fill_in 'Email', with: @user.email
|
||||
fill_in 'Пароль', with: @user.password
|
||||
|
||||
click_on 'Войти'
|
||||
end
|
||||
|
||||
expect(page).to have_css 'ul > li > a', text: @user.email
|
||||
end
|
||||
|
||||
When 'I try to sign in with email {string} ' \
|
||||
'and password {string}' do |email, password|
|
||||
visit '/users/sign_in'
|
||||
|
|
|
@ -20,8 +20,6 @@ RSpec.describe Person do
|
|||
|
||||
it { is_expected.not_to validate_presence_of :regional_office }
|
||||
|
||||
pending '#excluded_from_party?'
|
||||
|
||||
describe '#supporter_since' do
|
||||
def allow_value(*)
|
||||
super.for :supporter_since
|
||||
|
@ -54,6 +52,22 @@ RSpec.describe Person do
|
|||
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
|
||||
end
|
||||
|
||||
describe '#excluded_since' do
|
||||
def allow_value(*)
|
||||
super.for :excluded_since
|
||||
end
|
||||
|
||||
it { is_expected.not_to validate_presence_of :excluded_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? }
|
||||
|
||||
|
@ -70,6 +84,12 @@ RSpec.describe Person do
|
|||
|
||||
specify { expect(result).to eq true }
|
||||
end
|
||||
|
||||
context 'for excluded party member' do
|
||||
subject { create :excluded_person }
|
||||
|
||||
specify { expect(result).to eq false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#party_member?' do
|
||||
|
@ -88,5 +108,35 @@ RSpec.describe Person do
|
|||
|
||||
specify { expect(result).to eq true }
|
||||
end
|
||||
|
||||
context 'for excluded party member' do
|
||||
subject { create :excluded_person }
|
||||
|
||||
specify { expect(result).to eq false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#excluded_from_party?' do
|
||||
let(:result) { subject.excluded_from_party? }
|
||||
|
||||
specify { expect(result).to eq false }
|
||||
|
||||
context 'for party supporter' do
|
||||
subject { create :supporter_person }
|
||||
|
||||
specify { expect(result).to eq false }
|
||||
end
|
||||
|
||||
context 'for party member' do
|
||||
subject { create :member_person }
|
||||
|
||||
specify { expect(result).to eq false }
|
||||
end
|
||||
|
||||
context 'for excluded party member' do
|
||||
subject { create :excluded_person }
|
||||
|
||||
specify { expect(result).to eq true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue