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

add semester process to volunteer join model with all relations and such

parent 79774bff
class SemesterProcess < ApplicationRecord class SemesterProcess < ApplicationRecord
belongs_to :creator, -> { with_deleted }, class_name: 'User', inverse_of: 'semester_processes' belongs_to :creator, -> { with_deleted }, class_name: 'User', inverse_of: 'semester_processes'
belongs_to :mail_posted_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_process_mails_posted', optional: true
belongs_to :semester_process_reminder_mail_posted, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_process_mails_posted', optional: true
has_many :semester_process_volunteers, dependent: :destroy
has_many :volunteers, through: :semester_process_volunteers
end end
class SemesterProcessVolunteer < ApplicationRecord
belongs_to :volunteer
belongs_to :semester_process
belongs_to :responsible, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_processes', optional: true
belongs_to :reviewed_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_processes', optional: true
belongs_to :commited_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_processes', optional: true
has_many :semester_feedbacks, dependent: :destroy
end
...@@ -79,7 +79,24 @@ class User < ApplicationRecord ...@@ -79,7 +79,24 @@ class User < ApplicationRecord
has_many :mailing_processes_submitted, through: :mailing_volunteer_processes_submitted, has_many :mailing_processes_submitted, through: :mailing_volunteer_processes_submitted,
source: :process_submitted_by source: :process_submitted_by
has_many :semester_processes, inverse_of: 'creator', foreign_key: 'creator_id' # Semester Process relations
#
has_many :semester_processes, inverse_of: 'creator', foreign_key: 'creator_id', dependent: :destroy
has_many :semester_process_mails_posted, inverse_of: 'mail_posted_by',
foreign_key: 'mail_posted_by_id', dependent: :nullify
has_many :semester_process_reminder_mail_posted, inverse_of: 'reminder_mail_posted_by',
foreign_key: 'reminder_mail_posted_by_id', dependent: :nullify
has_many :semester_process_mails, dependent: :nullify
has_many :semester_process_reminders, -> { reminder }, through: :semester_process_mails
has_many :semester_process_responsibilities, inverse_of: 'responsible',
class_name: 'SemesterProcessVolunteer', foreign_key: 'responsible_id', dependent: :nullify
has_many :semester_process_reviews, inverse_of: 'reviewed_by',
class_name: 'SemesterProcessVolunteer', foreign_key: 'reviewed_by_id', dependent: :nullify
has_many :semester_process_commits, inverse_of: 'commited_by',
class_name: 'SemesterProcessVolunteer', foreign_key: 'commited_by_id', dependent: :nullify
has_and_belongs_to_many :department has_and_belongs_to_many :department
......
...@@ -69,6 +69,11 @@ class Volunteer < ApplicationRecord ...@@ -69,6 +69,11 @@ class Volunteer < ApplicationRecord
has_many :event_volunteers, dependent: :delete_all has_many :event_volunteers, dependent: :delete_all
has_many :events, through: :event_volunteers has_many :events, through: :event_volunteers
# Semester Process relations
#
has_many :semester_process_volunteers, dependent: :destroy
has_many :semester_processes, through: :semester_process_volunteers
has_attached_file :avatar, styles: { thumb: '100x100#' } has_attached_file :avatar, styles: { thumb: '100x100#' }
# Validations # Validations
......
class CreateSemesterProcessVolunteers < ActiveRecord::Migration[5.1]
def change
create_table :semester_process_volunteers do |t|
t.references :volunteer, foreign_key: true
t.references :semester_process, foreign_key: true
# volunteers "Bestätigen"
t.datetime :commit_visited_at
t.datetime :commited_at
t.references :commited_by, references: :users, index: true
# superadmins "Uebernehmen"
t.references :responsible, references: :users, index: true
t.datetime :responsibility_taken_at
# superadmins "Quittieren"
t.references :reviewed_by, references: :users, index: true
t.datetime :reviewed_at
# Superadmin takes notes
t.jsonb :notes
t.datetime :deleted_at, index: true
t.timestamps
end
end
end
class AddSemesterColumnToSemesterProcess < ActiveRecord::Migration[5.1]
def change
change_table :semester_processes do |t|
t.remove :period_start
t.remove :period_end
t.daterange :semester
t.string :mail_subject_template
t.text :mail_body_template
t.datetime :mail_posted_at
t.references :mail_posted_by, references: :users, index: true
t.string :reminder_mail_subject_template
t.text :reminder_mail_body_template
t.datetime :reminder_mail_posted_at
t.references :reminder_mail_posted_by, references: :users, index: true
end
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181004121332) do ActiveRecord::Schema.define(version: 20181004134604) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -624,15 +624,46 @@ ActiveRecord::Schema.define(version: 20181004121332) do ...@@ -624,15 +624,46 @@ ActiveRecord::Schema.define(version: 20181004121332) do
t.index ["deleted_at"], name: "index_reminder_mailings_on_deleted_at" t.index ["deleted_at"], name: "index_reminder_mailings_on_deleted_at"
end end
create_table "semester_process_volunteers", force: :cascade do |t|
t.bigint "volunteer_id"
t.bigint "semester_process_id"
t.datetime "commit_visited_at"
t.datetime "commited_at"
t.bigint "commited_by_id"
t.bigint "responsible_id"
t.datetime "responsibility_taken_at"
t.bigint "reviewed_by_id"
t.datetime "reviewed_at"
t.jsonb "notes"
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["commited_by_id"], name: "index_semester_process_volunteers_on_commited_by_id"
t.index ["deleted_at"], name: "index_semester_process_volunteers_on_deleted_at"
t.index ["responsible_id"], name: "index_semester_process_volunteers_on_responsible_id"
t.index ["reviewed_by_id"], name: "index_semester_process_volunteers_on_reviewed_by_id"
t.index ["semester_process_id"], name: "index_semester_process_volunteers_on_semester_process_id"
t.index ["volunteer_id"], name: "index_semester_process_volunteers_on_volunteer_id"
end
create_table "semester_processes", force: :cascade do |t| create_table "semester_processes", force: :cascade do |t|
t.bigint "creator_id" t.bigint "creator_id"
t.datetime "period_start"
t.datetime "period_end"
t.datetime "deleted_at" t.datetime "deleted_at"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.daterange "semester"
t.string "mail_subject_template"
t.text "mail_body_template"
t.datetime "mail_posted_at"
t.bigint "mail_posted_by_id"
t.string "reminder_mail_subject_template"
t.text "reminder_mail_body_template"
t.datetime "reminder_mail_posted_at"
t.bigint "reminder_mail_posted_by_id"
t.index ["creator_id"], name: "index_semester_processes_on_creator_id" t.index ["creator_id"], name: "index_semester_processes_on_creator_id"
t.index ["deleted_at"], name: "index_semester_processes_on_deleted_at" t.index ["deleted_at"], name: "index_semester_processes_on_deleted_at"
t.index ["mail_posted_by_id"], name: "index_semester_processes_on_mail_posted_by_id"
t.index ["reminder_mail_posted_by_id"], name: "index_semester_processes_on_reminder_mail_posted_by_id"
end end
create_table "trial_feedbacks", force: :cascade do |t| create_table "trial_feedbacks", force: :cascade do |t|
...@@ -779,6 +810,8 @@ ActiveRecord::Schema.define(version: 20181004121332) do ...@@ -779,6 +810,8 @@ ActiveRecord::Schema.define(version: 20181004121332) do
add_foreign_key "journals", "users" add_foreign_key "journals", "users"
add_foreign_key "performance_reports", "users" add_foreign_key "performance_reports", "users"
add_foreign_key "profiles", "users" add_foreign_key "profiles", "users"
add_foreign_key "semester_process_volunteers", "semester_processes"
add_foreign_key "semester_process_volunteers", "volunteers"
add_foreign_key "trial_feedbacks", "users", column: "author_id" add_foreign_key "trial_feedbacks", "users", column: "author_id"
add_foreign_key "volunteers", "departments" add_foreign_key "volunteers", "departments"
add_foreign_key "volunteers", "users" add_foreign_key "volunteers", "users"
......
FactoryBot.define do
factory :semester_process_volunteer do
volunteer
semester_process
notes { ['some note', 'another note'] }
end
end
FactoryBot.define do FactoryBot.define do
factory :semester_process do factory :semester_process do
association :creator, factory: :user association :creator, factory: :user
mail_subject_template 'mail subject template'
mail_body_template 'mail body template'
mail_posted_at { Time.zone.local(2018, 6, 10) }
association :mail_posted_by, factory: :user
period_start { Time.zone.local(2017, 12, 1).beginning_of_day } semester { Time.zone.local(2017, 12, 1).beginning_of_day..Time.zone.local(2018, 5, 30).end_of_month }
period_end { Time.zone.local(2018, 5, 30).end_of_month }
end end
end end
require 'test_helper'
class SemesterProcessVolunteerTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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