Commit c64cd677 authored by Jiri Strojil's avatar Jiri Strojil 💬

Feat/cancellation of clients

parent 1767d558
......@@ -81,7 +81,7 @@ class Client < ApplicationRecord
}
def terminatable?
assignments.unterminated.none?
assignments.active_or_not_yet_active.none?
end
def self.acceptences_restricted
......
......@@ -17,6 +17,7 @@ module TerminationScopes
date_between_inclusion(:termination_submitted_at, start_date, end_date)
}
scope :no_active_assignments, -> { joins(:clients).where("period_end < ?", Time.zone.now)}
scope :unterminated, (-> { field_nil(:termination_verified_by_id) })
scope :terminated, (-> { field_not_nil(:termination_verified_by_id) })
......
......@@ -65,5 +65,6 @@ nav.navbar.section-navigation.hidden-print
- else
= link_to 'Dossier Freiwillig Engagiert', volunteer_certificate_path(assignment.volunteer, assignment.volunteer.certificates.last)
= link_to 'Freiwillige/n beenden', terminate_volunteer_path(assignment.volunteer), method: :put unless assignment.volunteer.resigned?
= link_to 'Klient/in beenden', set_terminated_client_path(assignment.client), method: :patch unless assignment.client.resigned?
= bootstrap_paginate(@assignments)
......@@ -33,6 +33,40 @@ class AssignmentTerminationIndexTest < ApplicationSystemTestCase
refute_text termination_index_table_text(@verified)
end
test 'client with no active assignments can be terminated' do
Assignment.destroy_all
client = create :client
assignment1 = create :assignment, client: client, period_start: 3.weeks.ago, period_end: 2.days.ago, period_end_set_by: @superadmin
assignment2 = create :assignment, client: client, period_start: 3.weeks.ago, period_end: nil
refute client.resigned?
visit assignments_path
click_link 'Beendete Begleitungen'
assert_text termination_index_table_text(assignment1)
refute_text termination_index_table_text(assignment2)
click_link 'Klient/in beenden'
assert_text 'Beenden fehlgeschlagen.'
refute client.resigned?
assert page.has_link? 'Klient/in beenden'
assignment2.update(period_end: 4.days.ago, period_end_set_by: @superadmin)
visit current_url
assert_text termination_index_table_text(assignment1)
assert_text termination_index_table_text(assignment2)
click_link 'Klient/in beenden', match: :first
refute page.has_link? 'Klient/in beenden'
assert_text 'Klient/in wurde erfolgreich beendet.'
assert client.reload.resigned?
end
test 'filtering_submitted_terminations' do
visit terminated_index_assignments_path
click_link 'Ende Bestätigt'
......
......@@ -145,6 +145,27 @@ class ClientsTest < ApplicationSystemTestCase
I18n.l(with_assignment.created_at.to_date)
end
test 'client cannot be terminated if has active missions' do
client = create :client
assignment1 = create :assignment, client: client, period_start: 3.weeks.ago, period_end: 2.days.ago, period_end_set_by: @superadmin
assignment2 = create :assignment, client: client, period_start: 3.weeks.ago, period_end: nil
refute client.resigned?
login_as @superadmin
visit client_path(client)
find_all("a[href='#{set_terminated_client_path(client)}']").first.click
page.driver.browser.switch_to.alert.accept
assert_text 'Klient/in kann nicht beendet werden, solange noch ein laufendes Tandem existiert.'
assignment2.update(period_end: 1.day.ago)
find_all("a[href='#{set_terminated_client_path(client)}']").last.click
page.driver.browser.switch_to.alert.accept
assert_text 'Klient/in wurde erfolgreich beendet.'
assert client.reload.resigned?
end
test 'all_needed_actions_are_available_in_the_index' do
use_rack_driver
client = create :client
......
Markdown is supported
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