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