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

fix(semester_process): fix mails and reminders and add missions delegation + tests

parent a5f41131
Pipeline #28541 passed with stage
in 59 minutes and 43 seconds
......@@ -13,6 +13,15 @@ class SemesterProcess < ApplicationRecord
has_many :semester_process_volunteer_missions, through: :semester_process_volunteers
has_many :semester_process_mails, through: :semester_process_volunteers
has_many :mails, -> { mail }, through: :semester_process_mails
has_many :reminders, -> { reminder }, through: :semester_process_mails
def mails
semester_process_mails.where(kind: 'mail')
end
def reminders
semester_process_mails.where(kind: 'reminder')
end
# will only return an array, not a AD-result
delegate :missions, to: :semester_process_volunteers
end
......@@ -4,6 +4,11 @@ FactoryBot.define do
sent_at { Time.zone.local(2018, 8, 12) }
subject 'mail subject'
body 'Mail body'
kind 'mail'
trait :as_reminder do
kind 'reminder'
end
after(:build) do |sem_proc_mail|
sem_proc_mail.sent_by = sem_proc_mail.semester_process_volunteer.semester_process.creator
......
require 'test_helper'
class SemesterProcessTest < ActiveSupport::TestCase
# TODO: Write model test
def setup
@superadmin = create :user
@volunteer = create :volunteer_with_user
@assignment = create :assignment, volunteer: @volunteer
@group_assignment = create :group_assignment, volunteer: @volunteer
@subject = create :semester_process
@subject_volunteer = create(:semester_process_volunteer, :with_mission, volunteer: @volunteer,
semester_process: @subject)
@mission = @subject_volunteer.semester_process_volunteer_missions.first.assignment
@subject.reload
end
test 'through volunteers relation' do
assert @subject.volunteers.include? @volunteer
end
test 'through semester_feedbacks relation' do
semester_fb = create(:semester_feedback, semester_process_volunteer: @subject_volunteer,
volunteer: @volunteer)
@subject.reload
assert @subject.semester_feedbacks.include? semester_fb
end
test 'through hours relation' do
semester_hour = create(:hour, hourable: @mission, volunteer: @volunteer,
semester_process_volunteer: @subject_volunteer)
@subject.reload
assert @subject.hours.include? semester_hour
end
test '#mails and #reminders methods' do
semester_process_mail = create(:semester_process_mail,
semester_process_volunteer: @subject_volunteer)
semester_process_reminder = create(:semester_process_mail, :as_reminder,
semester_process_volunteer: @subject_volunteer)
@subject.reload
assert @subject.mails.include? semester_process_mail
assert_not @subject.mails.include? semester_process_reminder
assert @subject.reminders.include? semester_process_reminder
assert_not @subject.reminders.include? semester_process_mail
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