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

add semester process mail model with all relations

parent 37534fb5
......@@ -8,4 +8,7 @@ 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 :semester_process_mails, through: :semester_process_volunteers
has_many :mails, -> { mail }, through: :semester_process_mails
has_many :reminders, -> { reminder }, through: :semester_process_mails
end
class SemesterProcessMail < ApplicationRecord
belongs_to :semester_process_volunteer
belongs_to :sent_by, references: :users, class_name: 'User', inverse_of: 'semester_process_mails'
enum kind: { mail: 0, reminder: 1 }
scope :mail, -> { where(kind: 'mail') }
scope :reminder, -> { where(kind: 'reminder') }
end
class CreateSemesterProcessMails < ActiveRecord::Migration[5.1]
def change
create_table :semester_process_mails do |t|
t.references :semester_process_volunteer, foreign_key: true
t.references :sent_by, references: :users, index: true
t.datetime :sent_at
t.string :subject
t.text :body
t.integer :type
t.datetime :deleted_at, index: true
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181004141844) do
ActiveRecord::Schema.define(version: 20181004144449) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -641,6 +641,21 @@ ActiveRecord::Schema.define(version: 20181004141844) do
t.index ["deleted_at"], name: "index_semester_feedbacks_on_deleted_at"
end
create_table "semester_process_mails", force: :cascade do |t|
t.bigint "semester_process_volunteer_id"
t.bigint "sent_by_id"
t.datetime "sent_at"
t.string "subject"
t.text "body"
t.integer "type"
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["deleted_at"], name: "index_semester_process_mails_on_deleted_at"
t.index ["semester_process_volunteer_id"], name: "index_semester_process_mails_on_semester_process_volunteer_id"
t.index ["sent_by_id"], name: "index_semester_process_mails_on_sent_by_id"
end
create_table "semester_process_volunteers", force: :cascade do |t|
t.bigint "volunteer_id"
t.bigint "semester_process_id"
......@@ -827,6 +842,7 @@ ActiveRecord::Schema.define(version: 20181004141844) do
add_foreign_key "journals", "users"
add_foreign_key "performance_reports", "users"
add_foreign_key "profiles", "users"
add_foreign_key "semester_process_mails", "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
sent_at { Time.zone.local(2018, 8, 12) }
subject 'mail subject'
body 'Mail body'
association :sent_by, factory: :user
end
end
require 'test_helper'
class SemesterProcessMailTest < 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