Verified Commit a5f41131 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

fix(semester_process_volunteer): mail and reminder relations and spec added

parent 18b61467
......@@ -16,8 +16,10 @@ class SemesterProcessVolunteer < ApplicationRecord
has_many :hours, dependent: :nullify
has_many :semester_process_mails, dependent: :destroy
has_many :mails, -> { mail }, through: :semester_process_mails
has_many :reminders, -> { reminder }, through: :semester_process_mails
has_many :mails, -> { where(kind: 'mail') }, class_name: 'SemesterProcessMail',
foreign_key: 'semester_process_volunteer_id', inverse_of: 'semester_process_volunteer'
has_many :reminders, -> { where(kind: 'reminder') }, class_name: 'SemesterProcessMail',
foreign_key: 'semester_process_volunteer_id', inverse_of: 'semester_process_volunteer'
# will only return an array, not a AD-result
def missions
......
require 'test_helper'
class SemesterProcessVolunteerTest < ActiveSupport::TestCase
def setup
@volunteer = create(:volunteer_with_user)
@assignment = create(:assignment, volunteer: @volunteer)
@group_assignment = create(:group_assignment, volunteer: @volunteer)
@subject = create(:semester_process_volunteer, volunteer: @volunteer)
end
test '#mission returns array with all kind of related assignment or group_assignments' do
volunteer = create(:volunteer_with_user)
assignment = create(:assignment, volunteer: volunteer)
group_assignment = create(:group_assignment, volunteer: volunteer)
subject = create(:semester_process_volunteer, volunteer: volunteer,
semester_process_volunteer_missions: [
build(:semester_process_volunteer_mission, mission: assignment),
build(:semester_process_volunteer_mission, mission: group_assignment)
@subject.update(semester_process_volunteer_missions: [
build(:semester_process_volunteer_mission, mission: @assignment),
build(:semester_process_volunteer_mission, mission: @group_assignment)
])
result = @subject.missions
assert result.include? @assignment
assert result.include? @group_assignment
end
test 'has_many mails and reminders relations work' do
mail = create(:semester_process_mail, semester_process_volunteer: @subject)
reminder = create(:semester_process_mail, :as_reminder, semester_process_volunteer: @subject)
assert @subject.reload.mails.include? mail
assert_not @subject.reload.mails.include? reminder
result = subject.missions
assert result.include? assignment
assert result.include? group_assignment
assert_not @subject.reload.reminders.include? mail
assert @subject.reload.reminders.include? reminder
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