From c191c8bda7a9a12a85ec57af5bcc731dcc8cbde7 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 29 Jan 2019 07:13:25 +0500 Subject: [PATCH] Add attribute Person#excluded_since; method Person#excluded_from_party? --- app/models/person.rb | 13 +++-- app/views/membership_apps/show.html.erb | 3 ++ config/locales/views/en.yml | 5 ++ config/locales/views/ru.yml | 5 ++ ...0129015721_add_excluded_since_to_people.rb | 7 +++ db/schema.rb | 3 +- factories/people.rb | 4 ++ features/desktop/membership_app.feature | 6 +++ .../membership_application.rb | 9 ++++ features/step_definitions/user.rb | 18 +++++++ spec/models/person_spec.rb | 54 ++++++++++++++++++- 11 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20190129015721_add_excluded_since_to_people.rb diff --git a/app/models/person.rb b/app/models/person.rb index 2ddcbca..f131818 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/views/membership_apps/show.html.erb b/app/views/membership_apps/show.html.erb index 5d77083..5a7a649 100644 --- a/app/views/membership_apps/show.html.erb +++ b/app/views/membership_apps/show.html.erb @@ -5,6 +5,9 @@ <% elsif @membership_app.person&.party_supporter? %>

<%= translate '.congratulations' %>

<%= translate '.lead_congratulations_supporter' %>

+ <% elsif @membership_app.person&.excluded_from_party? %> +

<%= translate '.excluded' %>

+

<%= translate '.lead_excluded' %>

<% else %>

<%= translate '.header' %>

<%= translate '.lead_text' %>

diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index e04c4b2..57cc811 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -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 diff --git a/config/locales/views/ru.yml b/config/locales/views/ru.yml index 0bb0b41..b6deb9b 100644 --- a/config/locales/views/ru.yml +++ b/config/locales/views/ru.yml @@ -14,6 +14,11 @@ ru: Вы уже являетесь сторонником Либертарианской партии России! lead_congratulations_member: > Вы уже являетесь членом Либертарианской партии России! + excluded: > + Вы исключены из партии + lead_excluded: + Вы были исключены из Либертарианской партии России + и не можете подать заявление на вступление. header: Ваше заявление в обработке lead_text: > На данной странице вы можете отслеживать статус вашего заявления. diff --git a/db/migrate/20190129015721_add_excluded_since_to_people.rb b/db/migrate/20190129015721_add_excluded_since_to_people.rb new file mode 100644 index 0000000..d961bb1 --- /dev/null +++ b/db/migrate/20190129015721_add_excluded_since_to_people.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddExcludedSinceToPeople < ActiveRecord::Migration[5.2] + def change + add_column :people, :excluded_since, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index cf743a6..38bd21b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/factories/people.rb b/factories/people.rb index 3a729f7..8074739 100644 --- a/factories/people.rb +++ b/factories/people.rb @@ -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 diff --git a/features/desktop/membership_app.feature b/features/desktop/membership_app.feature index bf0d1fe..eb8a639 100644 --- a/features/desktop/membership_app.feature +++ b/features/desktop/membership_app.feature @@ -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 diff --git a/features/step_definitions/membership_application.rb b/features/step_definitions/membership_application.rb index 8967a2d..06e7c23 100644 --- a/features/step_definitions/membership_application.rb +++ b/features/step_definitions/membership_application.rb @@ -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' diff --git a/features/step_definitions/user.rb b/features/step_definitions/user.rb index 76e1f41..0cc77bd 100644 --- a/features/step_definitions/user.rb +++ b/features/step_definitions/user.rb @@ -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' diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 43f1905..9c35988 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -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