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

change semester_feedback relation from polymorph to or relation

parent 51eeffa2
......@@ -2,11 +2,15 @@ class Assignment < ApplicationRecord
include AssignmentCommon
include VolunteersGroupAndTandemStateUpdate
has_one :assignment_log
has_many :hours, as: :hourable
has_many :feedbacks, as: :feedbackable
has_many :trial_feedbacks, as: :trial_feedbackable
has_many :semester_feedbacks, as: :semester_feedbackable
has_one :assignment_log
# Semester process relations
#
has_many :semester_feedbacks, dependent: :destroy
validates :client_id, uniqueness: {
scope: :volunteer_id, message: I18n.t('assignment_exists')
......
......@@ -8,7 +8,7 @@ module GroupAssignmentCommon
belongs_to :group_offer, -> { with_deleted } # include imported deleted group offers
has_many :reminder_mailing_volunteers, as: :reminder_mailable, dependent: :destroy
has_many :semester_feedbacks, as: :semester_feedbackable
has_many :semester_feedbacks, dependent: :destroy
has_one :group_offer_category, through: :group_offer
has_one :creator, -> { with_deleted }, through: :group_offer
......
......@@ -5,5 +5,18 @@ class SemesterFeedback < ApplicationRecord
has_one :volunteer, through: :semester_process_volunteer
# relates to either Assignment or GroupAssignment (not GroupOffer!)
belongs_to :semester_feedbackable, polymorphic: true, optional: true
belongs_to :assignment, optional: true
belongs_to :group_assignment, optional: true
validate :validate_group_assignment_or_assignment_present
def mission
group_assignment || assignment
end
private
def validate_group_assignment_or_assignment_present
errors.add(:association_insuficient) if assignment.blank? && group_assignment.blank?
end
end
......@@ -4,8 +4,9 @@ class CreateSemesterFeedbacks < ActiveRecord::Migration[5.1]
t.references :author, references: :users, index: true
t.references :semester_process_volunteer, index: false
# for relations to either Assignment or GroupAssignment (not GroupOffer!)
t.integer :semester_feedbackable_id
t.string :semester_feedbackable_type
t.references :assignment, foreign_key: true
t.references :group_assignment, foreign_key: true
t.text :goals
t.text :achievements
t.text :future
......
FactoryBot.define do
factory :semester_feedback do
association :author, factory: :user
volunteer
semester_process_volunteer
volunteer
goals 'Goals text'
achievements 'Achievements text'
future 'Future text'
comments 'Comments text'
association :semester_feedbackable, factory: :group_assignment
after(:build) do |sem_fb|
if sem_fb.assignment.blank?
sem_fb.group_assignment ||= FactoryBot.build(:group_assignment)
end
end
end
end
FactoryBot.define do
factory :semester_process_volunteer do
volunteer
semester_process
semester_process_volunteer_missions
hours
semester_feedbacks
notes { ['some note', 'another note'] }
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