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

add join relation between semester process volunteer and assignment or group assignment

- call it mission
parent 467f109f
......@@ -11,6 +11,9 @@ class Assignment < ApplicationRecord
# Semester process relations
#
has_many :semester_feedbacks, dependent: :destroy
has_many :semester_process_volunteer_missions, dependent: :destroy
has_many :semester_process_volunteers, through: :semester_process_volunteer_missions
has_many :semester_processes, through: :semester_process_volunteers
validates :client_id, uniqueness: {
scope: :volunteer_id, message: I18n.t('assignment_exists')
......
......@@ -9,6 +9,10 @@ module GroupAssignmentCommon
has_many :reminder_mailing_volunteers, as: :reminder_mailable, dependent: :destroy
has_many :semester_feedbacks, dependent: :destroy
has_many :semester_process_volunteer_missions, dependent: :destroy
has_many :semester_process_volunteers, through: :semester_process_volunteer_missions
has_many :semester_processes, through: :semester_process_volunteers
has_one :group_offer_category, through: :group_offer
has_one :creator, -> { with_deleted }, through: :group_offer
......
......@@ -8,6 +8,10 @@ class SemesterProcess < ApplicationRecord
has_many :semester_process_volunteers, dependent: :destroy
has_many :volunteers, through: :semester_process_volunteers
has_many :semester_feedbacks, through: :semester_process_volunteers
has_many :hours, through: :semester_process_volunteers
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
......
......@@ -8,6 +8,11 @@ class SemesterProcessVolunteer < ApplicationRecord
belongs_to :commited_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_processes', optional: true
has_many :semester_process_volunteer_missions, dependent: :destroy
has_many :semester_feedbacks, dependent: :destroy
has_many :hours, dependent: :nullify
has_many :semester_process_mails, dependent: :destroy
has_many :mails, -> { mail }, through: :semester_process_mails
has_many :reminders, -> { reminder }, through: :semester_process_mails
end
class SemesterProcessVolunteerMission < ApplicationRecord
belongs_to :semester_process_volunteer
# relates to either Assignment or GroupAssignment (not GroupOffer!)
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
class CreateSemesterProcessVolunteerMissions < ActiveRecord::Migration[5.1]
def change
create_table :semester_process_volunteer_missions do |t|
t.references :semester_process_volunteer, foreign_key: true,
index: { name: 'semester_proc_volunteer_mission_index' }
# can be either Assignment or GroupAssignment (not GroupOffer!)
t.references :assignment, foreign_key: true,
index: { name: 'semester_proc_volunteer_mission_assignment_index' }
t.references :group_assignment, foreign_key: true,
index: { name: 'semester_proc_volunteer_mission_group_assignment_index' }
t.datetime :deleted_at, index: true
t.timestamps
end
end
end
......@@ -284,7 +284,7 @@ ActiveRecord::Schema.define(version: 20181004163636) do
end
create_table "events", force: :cascade do |t|
t.integer "kind", null: false
t.integer "kind"
t.date "date"
t.time "start_time"
t.time "end_time"
......@@ -495,6 +495,7 @@ ActiveRecord::Schema.define(version: 20181004163636) do
t.index ["hourable_type", "hourable_id"], name: "index_hours_on_hourable_type_and_hourable_id"
t.index ["meeting_date"], name: "index_hours_on_meeting_date"
t.index ["reviewer_id"], name: "index_hours_on_reviewer_id"
t.index ["semester_process_volunteer_id"], name: "index_hours_on_semester_process_volunteer_id"
t.index ["volunteer_id"], name: "index_hours_on_volunteer_id"
end
......@@ -628,8 +629,8 @@ ActiveRecord::Schema.define(version: 20181004163636) do
create_table "semester_feedbacks", force: :cascade do |t|
t.bigint "author_id"
t.bigint "semester_process_volunteer_id"
t.integer "semester_feedbackable_id"
t.string "semester_feedbackable_type"
t.bigint "assignment_id"
t.bigint "group_assignment_id"
t.text "goals"
t.text "achievements"
t.text "future"
......@@ -638,8 +639,10 @@ ActiveRecord::Schema.define(version: 20181004163636) do
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["assignment_id"], name: "index_semester_feedbacks_on_assignment_id"
t.index ["author_id"], name: "index_semester_feedbacks_on_author_id"
t.index ["deleted_at"], name: "index_semester_feedbacks_on_deleted_at"
t.index ["group_assignment_id"], name: "index_semester_feedbacks_on_group_assignment_id"
end
create_table "semester_process_mails", force: :cascade do |t|
......@@ -657,6 +660,19 @@ ActiveRecord::Schema.define(version: 20181004163636) do
t.index ["sent_by_id"], name: "index_semester_process_mails_on_sent_by_id"
end
create_table "semester_process_volunteer_missions", force: :cascade do |t|
t.bigint "semester_process_volunteer_id"
t.bigint "assignment_id"
t.bigint "group_assignment_id"
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["assignment_id"], name: "semester_proc_volunteer_mission_assignment_index"
t.index ["deleted_at"], name: "index_semester_process_volunteer_missions_on_deleted_at"
t.index ["group_assignment_id"], name: "semester_proc_volunteer_mission_group_assignment_index"
t.index ["semester_process_volunteer_id"], name: "semester_proc_volunteer_mission_index"
end
create_table "semester_process_volunteers", force: :cascade do |t|
t.bigint "volunteer_id"
t.bigint "semester_process_id"
......@@ -839,11 +855,17 @@ ActiveRecord::Schema.define(version: 20181004163636) do
add_foreign_key "group_offers", "departments"
add_foreign_key "group_offers", "group_offer_categories"
add_foreign_key "hours", "billing_expenses"
add_foreign_key "hours", "semester_process_volunteers"
add_foreign_key "journals", "assignments"
add_foreign_key "journals", "users"
add_foreign_key "performance_reports", "users"
add_foreign_key "profiles", "users"
add_foreign_key "semester_feedbacks", "assignments"
add_foreign_key "semester_feedbacks", "group_assignments"
add_foreign_key "semester_process_mails", "semester_process_volunteers"
add_foreign_key "semester_process_volunteer_missions", "assignments"
add_foreign_key "semester_process_volunteer_missions", "group_assignments"
add_foreign_key "semester_process_volunteer_missions", "semester_process_volunteers"
add_foreign_key "semester_process_volunteers", "semester_processes"
add_foreign_key "semester_process_volunteers", "volunteers"
add_foreign_key "trial_feedbacks", "users", column: "author_id"
......
FactoryBot.define do
factory :semester_process_mail do
semester_process_volunteer
association :sent_by, factory: :user
sent_at { Time.zone.local(2018, 8, 12) }
subject 'mail subject'
body 'Mail body'
association :sent_by, factory: :user
end
end
FactoryBot.define do
factory :semester_process_volunteer_mission do
semester_process_volunteer
after(:build) do |spvm|
if spvm.assignment.blank?
spvm.group_assignment ||= FactoryBot.build(:group_assignment)
end
end
end
end
......@@ -5,6 +5,7 @@ FactoryBot.define do
mail_body_template 'mail body template'
mail_posted_at { Time.zone.local(2018, 6, 10) }
association :mail_posted_by, factory: :user
semester_process_volunteers
semester { Time.zone.local(2017, 12, 1).beginning_of_day..Time.zone.local(2018, 5, 30).end_of_month }
end
......
require 'test_helper'
class SemesterProcessVolunteerMissionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
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