Commit 3a384574 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou
Browse files

fix volunteer show if group offer gets deleted

parent e2fbcd95
......@@ -9,7 +9,7 @@ class GroupOffer < ApplicationRecord
belongs_to :department, optional: true
belongs_to :group_offer_category
has_many :group_assignments
has_many :group_assignments, dependent: :destroy
has_many :volunteers, through: :group_assignments
has_many :hours, as: :hourable, dependent: :destroy
......
......@@ -16,15 +16,20 @@ table.table.table-striped.group-assignments-table
tbody
- group_assignments.each do |group_assignment|
tr
td= link_to group_assignment.group_offer.title, group_offer_path(group_assignment.group_offer)
td
- if group_assignment.group_offer
= link_to group_assignment.group_offer.title, group_offer_path(group_assignment.group_offer)
- else
= group_assignment.title
- if group_assignment.responsible
td= t_attr(:responsible, GroupAssignment)
- else
td= t_attr(:member, GroupAssignment)
td= l(group_assignment.period_start) if group_assignment.period_start
td= l(group_assignment.period_end) if group_assignment.period_end
td= link_to t_action(:show), group_offer_path(group_assignment.group_offer)
td= link_to t('download'), group_offer_path(group_assignment.group_offer, format: :pdf)
- if group_assignment.group_offer
td= link_to t_action(:show), group_offer_path(group_assignment.group_offer)
td= link_to t('download'), group_offer_path(group_assignment.group_offer, format: :pdf)
- if editable
- if policy(GroupOffer).edit?
td= link_to t_action(:edit), edit_group_offer_path(group_assignment.group_offer)
......
......@@ -190,7 +190,7 @@ de:
acceptance: *id-volunteer-acceptance
state: *id-volunteer-active-states
availability: Verfügbarkeit
group_assignments: Gruppenangebote
group_assignments: Aktuelle Gruppenangebote
hour_reports: Stunden Rapporte
new_certificate: Nachweis ausstellen
old_group_assignments: Gruppenangebote Archiv
......
......@@ -182,7 +182,7 @@ en:
inactive: Inactive
show_assignments: Show Assignments
availability: Availability for voluntary engagement
group_assignments: Group offers
group_assignments: Active group offers
hour_reports: Hour reports
new_certificate: Create certificate
old_group_assignments: Group offers log
......
......@@ -90,11 +90,10 @@ class GroupOffersTest < ApplicationSystemTestCase
test 'deleting volunteer from group offer creates log entry' do
login_as create(:user)
volunteer = create :volunteer
user_volunteer = create :user_volunteer, volunteer: volunteer
group_offer = create :group_offer, volunteers: [volunteer]
visit volunteer_path(volunteer)
assert page.has_text? 'Group offers'
assert page.has_text? 'Active group offers'
assert page.has_link? group_offer.title
refute page.has_text? 'Group offers log'
......@@ -103,6 +102,7 @@ class GroupOffersTest < ApplicationSystemTestCase
click_button 'Update Group offer'
visit volunteer_path(volunteer)
refute page.has_text? 'Active group offers'
assert page.has_text? 'Group offers log'
assert page.has_link? group_offer.title
end
......@@ -110,24 +110,44 @@ class GroupOffersTest < ApplicationSystemTestCase
test 'modifying volunteer dates creates log entry' do
login_as create(:user)
volunteer = create :volunteer
user_volunteer = create :user_volunteer, volunteer: volunteer
group_offer = create :group_offer, volunteers: [volunteer]
visit volunteer_path(volunteer)
assert page.has_text? 'Group offers'
assert page.has_text? 'Active group offers'
assert page.has_link? group_offer.title
refute page.has_text? 'Group offers log'
group_offer.group_assignments.last.update(period_start: 7.months.ago, period_end: 2.months.ago)
visit volunteer_path(volunteer)
assert page.has_text? 'Active group offers'
assert page.has_text? 'Group offers log'
assert page.has_link? group_offer.title, count: 2
group_offer.group_assignments.last.update(period_end: 3.months.ago)
visit volunteer_path(volunteer)
assert page.has_text? 'Active group offers'
assert page.has_text? 'Group offers log'
assert page.has_link? group_offer.title, count: 3
end
test 'deleting group offer creates log and does not crash volunteer show' do
login_as create(:user)
volunteer = create :volunteer
group_offer = create :group_offer, volunteers: [volunteer]
title = group_offer.title
visit volunteer_path(volunteer)
assert page.has_text? 'Active group offers'
assert page.has_link? group_offer.title
refute page.has_text? 'Group offers log'
GroupOffer.last.destroy
visit volunteer_path(volunteer)
refute page.has_text? 'Active group offers'
assert page.has_text? 'Group offers log'
assert page.has_text? title
end
end
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