Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
467f109f
Verified
Commit
467f109f
authored
Oct 04, 2018
by
Kaspar Vollenweider
👻
Browse files
change semester_feedback relation from polymorph to or relation
parent
51eeffa2
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/models/assignment.rb
View file @
467f109f
...
...
@@ -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'
)
...
...
app/models/concerns/group_assignment_common.rb
View file @
467f109f
...
...
@@ -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
...
...
app/models/semester_feedback.rb
View file @
467f109f
...
...
@@ -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
db/migrate/20181004141844_create_semester_feedbacks.rb
View file @
467f109f
...
...
@@ -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
...
...
test/factories/semester_feedbacks.rb
View file @
467f109f
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
test/factories/semester_process_volunteers.rb
View file @
467f109f
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment