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

test(mission_either_one_relation_concern): add tests for semester_feedback and...

test(mission_either_one_relation_concern): add tests for semester_feedback and semester_process_mission implementation of the concern
parent 8f5f2b89
......@@ -6,6 +6,16 @@ FactoryBot.define do
future 'Future text'
comments 'Comments text'
transient do
add_mission { true }
end
# feedback has to be created with mission, and then the resulting instance has it removed
# because otherwise test/models/factory_test.rb will fail
trait :no_mission do
add_mission { false }
end
trait :with_assignment do
association :assignment
end
......@@ -14,12 +24,19 @@ FactoryBot.define do
association :group_assignment
end
after(:build) do |sem_fb|
after(:build) do |sem_fb, evl|
if sem_fb.assignment.blank?
sem_fb.group_assignment ||= FactoryBot.build(:group_assignment, volunteer: sem_fb.volunteer)
end
sem_fb.volunteer = sem_fb.semester_process_volunteer.volunteer
sem_fb.author = sem_fb.volunteer.user
end
after(:create) do |sem_fb, evl|
unless evl.add_mission
sem_fb.group_assignment = nil
sem_fb.assignment = nil
end
end
end
end
......@@ -2,6 +2,18 @@ FactoryBot.define do
factory :semester_process_volunteer_mission do
semester_process_volunteer
transient do
add_mission { true }
end
# feedback has to be created with mission, and then the resulting instance has it removed
# because otherwise test/models/factory_test.rb will fail
trait :no_mission do
transient do
add_mission { false }
end
end
after(:build) do |spvm|
if spvm.assignment.blank?
spvm.group_assignment ||= FactoryBot.build(:group_assignment,
......@@ -9,5 +21,11 @@ FactoryBot.define do
end
end
after(:create) do |spvm, evl|
unless evl.add_mission
spvm.group_assignment = nil
spvm.assignment = nil
end
end
end
end
......@@ -50,15 +50,15 @@ FactoryBot.define do
end
if ev.add_feedbacks
spv.semester_process_volunteer_missions.map do |sem_proc_vol_mission|
create(:semester_feedback, mission: sem_proc_vol_mission.mission,
spv.semester_process_volunteer_missions.map do |sem_proc_mission|
create(:semester_feedback, mission: sem_proc_mission.mission,
semester_process_volunteer: spv)
end
end
if ev.add_hours
spv.semester_process_volunteer_missions.map do |sem_proc_vol_mission|
create(:hour, hourable: sem_proc_vol_mission.mission, volunteer: spv.volunteer,
spv.semester_process_volunteer_missions.map do |sem_proc_mission|
create(:hour, hourable: sem_proc_mission.mission, volunteer: spv.volunteer,
semester_process_volunteer: spv)
end
end
......
require 'test_helper'
class SemesterFeedbackTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@assignment = create(:assignment)
@volunteer = @assignment.volunteer
@group_assignment = create(:group_assignment, volunteer: @volunteer)
@sem_proc_vol = create(:semester_process_volunteer, volunteer: @volunteer)
@subject = create(:semester_feedback, :no_mission, semester_process_volunteer: @sem_proc_vol,
volunteer: @volunteer)
end
test 'its_invalid_if_no_mission_is_assigned' do
assert_not @subject.valid?
assert_equal :insuficient_relation, @subject.errors.details[:assignment].first[:error]
assert_equal :insuficient_relation, @subject.errors.details[:group_assignment].first[:error]
end
test 'its invalid if it has assignment and group assignment' do
@subject.assignment = @assignment
@subject.group_assignment = @group_assignment
assert_not @subject.valid?
assert_equal :too_many_relations, @subject.errors.details[:assignment].first[:error]
assert_equal :too_many_relations, @subject.errors.details[:group_assignment].first[:error]
end
test 'its_valid_if_it_has_assignment with #mission' do
@subject.mission = @assignment
assert @subject.valid?
end
test 'its_valid_if_it_has_group_assignment with #mission' do
@subject.mission = @group_assignment
assert @subject.valid?
end
test 'its_valid_if_it_has_assignment with' do
@subject.assignment = @assignment
assert @subject.valid?
end
test 'its_valid_if_it_has_group_assignment with' do
@subject.group_assignment = @group_assignment
assert @subject.valid?
end
end
require 'test_helper'
class SemesterProcessVolunteerMissionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@assignment = create(:assignment)
@volunteer = @assignment.volunteer
@group_assignment = create(:group_assignment, volunteer: @volunteer)
@sem_proc_vol = create(:semester_process_volunteer, volunteer: @volunteer)
@subject = create(:semester_process_volunteer_mission, :no_mission,
semester_process_volunteer: @sem_proc_vol)
end
test 'its_invalid_if_no_mission_is_assigned' do
assert_not @subject.valid?
assert_equal :insuficient_relation, @subject.errors.details[:assignment].first[:error]
assert_equal :insuficient_relation, @subject.errors.details[:group_assignment].first[:error]
end
test 'its invalid if it has assignment and group assignment' do
@subject.assignment = @assignment
@subject.group_assignment = @group_assignment
assert_not @subject.valid?
assert_equal :too_many_relations, @subject.errors.details[:assignment].first[:error]
assert_equal :too_many_relations, @subject.errors.details[:group_assignment].first[:error]
end
test 'its_valid_if_it_has_assignment with #mission' do
@subject.mission = @assignment
assert @subject.valid?
end
test 'its_valid_if_it_has_group_assignment with #mission' do
@subject.mission = @group_assignment
assert @subject.valid?
end
test 'its_valid_if_it_has_assignment with' do
@subject.assignment = @assignment
assert @subject.valid?
end
test 'its_valid_if_it_has_group_assignment with' do
@subject.group_assignment = @group_assignment
assert @subject.valid?
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