Commit 63fd39d7 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

Merge branch 'terminating_group_offer_toggles_inactive_flag_as_well' into 'develop'

Terminating group offer toggles inactive flag as well

See merge request !617
parents ca3d2fa1 4b32c14f
Pipeline #18825 failed with stage
in 60 minutes
......@@ -15,8 +15,6 @@ class GroupOffer < ApplicationRecord
# termination record relations
belongs_to :period_end_set_by, -> { with_deleted }, class_name: 'User', optional: true,
inverse_of: 'group_offer_period_ends_set'
belongs_to :termination_verified_by, -> { with_deleted }, class_name: 'User', optional: true,
inverse_of: 'group_offer_terminations_verified'
has_many :group_assignments, dependent: :destroy
accepts_nested_attributes_for :group_assignments, allow_destroy: true
......@@ -42,6 +40,7 @@ class GroupOffer < ApplicationRecord
validates :department, presence: true, if: :internal?
validates :organization, :location, presence: true, if: :external?
validates :active, inclusion: { in: [false] }, if: :terminated?
scope :active, (-> { where(active: true) })
scope :inactive, (-> { where(active: false) })
......@@ -72,12 +71,18 @@ class GroupOffer < ApplicationRecord
date_between_inclusion(:period_end, start_date, end_date)
}
def active_group_assignments_between?(start_date, end_date)
group_assignments.active_between(start_date, end_date).any?
end
scope :terminated, (-> { field_not_nil(:period_end_set_by) })
def terminatable?
group_assignments.have_start.any? || group_assignment_logs.any?
group_assignments.unterminated.none?
end
def terminated?
period_end_set_by.present? && period_end.present?
end
def active_group_assignments_between?(start_date, end_date)
group_assignments.active_between(start_date, end_date).any?
end
def all_group_assignments_ended_within?(start_date, end_date)
......
......@@ -55,9 +55,9 @@ table.table.table-striped
= button_link navigation_glyph(offer.active? ? :deactivate : :activate),
change_active_state_group_offer_path(offer), method: :put,
title: (offer.active? ? 'Deaktivieren' : 'Aktivieren')
- if policy(offer).initiate_termination? && offer.terminatable?
= button_link navigation_glyph(:terminate),
initiate_termination_group_offer_path(offer), title: 'Beenden'
- if policy(offer).initiate_termination?
= button_link navigation_glyph(:terminate),
initiate_termination_group_offer_path(offer), title: 'Beenden'
td.button-acceptance= assignment_status_badge(offer)
td= offer.title
td
......
......@@ -57,7 +57,7 @@ FactoryBot.define do
end
after(:build) do |client|
client.user ||= create(:user_fake_email)
client.user ||= create(:user)
if client.salutation == 'mrs'
client.contact.first_name = I18n.t('faker.name.female_first_name').sample
elsif client.salutation == 'mr'
......
FactoryBot.define do
factory :event_volunteer do
association :creator, factory: :user_fake_email
association :creator, factory: :user
association :volunteer, factory: :volunteer_with_user
association :event, factory: :event
......
......@@ -7,7 +7,7 @@ FactoryBot.define do
end_time { FFaker::Time.between(20.hours.ago, 4.hours.ago) }
date { FFaker::Time.between(300.days.ago, 10.days.ago) }
association :creator, factory: :user_fake_email
association :creator, factory: :user
trait :with_department do
association :department
......
......@@ -18,7 +18,7 @@ FactoryBot.define do
feedback.volunteer = create(:volunteer_with_user)
feedback.feedbackable = create(:assignment, volunteer: feedback.volunteer)
end
feedback.author ||= feedback.volunteer&.user || create(:user_fake_email)
feedback.author ||= feedback.volunteer&.user || create(:user)
end
end
end
......@@ -11,5 +11,19 @@ FactoryBot.define do
group_assignment.volunteer = create(:volunteer_with_user) if group_assignment.volunteer.blank?
group_assignment.group_offer = create(:group_offer) if group_assignment.group_offer.blank?
end
factory :terminated_group_assignment do
period_end { 4.days.ago }
termination_submitted_at { 3.days.ago }
termination_verified_at { 2.days.ago }
association :period_end_set_by, factory: :user
after(:build) do |group_assignment|
group_assignment.volunteer ||= create(:volunteer_with_user)
group_assignment.termination_submitted_by = group_assignment.volunteer.user
group_assignment.termination_verified_by = group_assignment.period_end_set_by
group_assignment.group_offer ||= create(:group_offer)
end
after(:create, &:create_log_of_self)
end
end
end
FactoryBot.define do
factory :group_offer do
association :creator, factory: :user_fake_email
association :creator, factory: :user
association :department
title { FFaker::Lorem.unique.sentence }
......@@ -21,5 +21,11 @@ FactoryBot.define do
location { FFaker::Address.city }
organization { FFaker::Company.name }
end
trait :terminated do
period_end { 2.days.ago }
association :period_end_set_by, factory: :user
active { false }
end
end
end
FactoryBot.define do
factory :reminder_mailing do
association :creator, factory: :user_fake_email
association :creator, factory: :user
body { FFaker::Lorem.paragraph }
subject { FFaker::Lorem.sentence }
......
......@@ -15,7 +15,7 @@ FactoryBot.define do
trial_feedback.trial_feedbackable = create(:assignment, period_end: nil,
period_start: 6.weeks.ago, volunteer: trial_feedback.volunteer)
end
trial_feedback.author ||= trial_feedback.volunteer&.user || create(:user_fake_email)
trial_feedback.author ||= trial_feedback.volunteer&.user || create(:user)
end
end
end
......@@ -34,10 +34,6 @@ FactoryBot.define do
profile {}
end
trait :fake_email do
end
after(:create) do |user|
next unless user.email.include?('my-user@temporary-mail.com')
user.email = user.role + '_' + FFaker::Internet.unique.email(
......@@ -51,6 +47,5 @@ FactoryBot.define do
factory :department_manager, traits: [:department_manager, :with_department]
factory :department_manager_without_department, traits: [:department_manager]
factory :user_volunteer, traits: [:volunteer]
factory :user_fake_email, traits: [:fake_email]
end
end
......@@ -65,4 +65,12 @@ class GroupOfferScopesTest < ActiveSupport::TestCase
assert query.include? created_before
refute query.include? created_after
end
test 'terminated' do
terminated_go = create :group_offer, :terminated
unterminated_go = create :group_offer
query = GroupOffer.terminated
assert query.include? terminated_go
refute query.include? unterminated_go
end
end
require 'test_helper'
class GroupOfferTest < ActiveSupport::TestCase
test 'terminated? method' do
terminated = create :group_offer, :terminated
unterminated = create :group_offer
assert terminated.terminated?
refute unterminated.terminated?
end
test 'terminatable? method' do
terminatable = create :group_offer
create :terminated_group_assignment, group_offer: terminatable
unterminatable = create :group_offer
create :group_assignment, group_offer: unterminatable, period_start: 2.months.ago,
period_end: nil
assert terminatable.terminatable?
refute unterminatable.terminatable?
end
test 'terminated_and_active_group_offer_is_not_valid' do
still_active = build :group_offer, period_end: 2.days.ago, period_end_set_by: create(:user)
refute still_active.valid?
assert still_active.errors.messages[:active].any?
still_active.active = false
assert still_active.valid?
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment