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

add SemesterFeedback with all relations

parent 790e29e0
......@@ -5,6 +5,7 @@ class Assignment < ApplicationRecord
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
validates :client_id, uniqueness: {
......
......@@ -7,6 +7,8 @@ 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_one :group_offer_category, through: :group_offer
has_one :creator, -> { with_deleted }, through: :group_offer
......
class SemesterFeedback < ApplicationRecord
belongs_to :author, -> { with_deleted }, class_name: 'User', inverse_of: 'semester_feedbacks'
belongs_to :semester_process_volunteer
has_one :semester_process, through: :semester_process_volunteer
has_one :volunteer, through: :semester_process_volunteer
# relates to either Assignment or GroupAssignment (not GroupOffer!)
belongs_to :semester_feedbackable, polymorphic: true, optional: true
end
......@@ -7,4 +7,5 @@ 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
end
......@@ -97,6 +97,7 @@ class User < ApplicationRecord
has_many :semester_process_commits, inverse_of: 'commited_by',
class_name: 'SemesterProcessVolunteer', foreign_key: 'commited_by_id', dependent: :nullify
has_many :semester_feedbacks, inverse_of: 'author', foreign_key: 'author_id', dependent: :destroy
has_and_belongs_to_many :department
......
......@@ -74,6 +74,8 @@ class Volunteer < ApplicationRecord
has_many :semester_process_volunteers, dependent: :destroy
has_many :semester_processes, through: :semester_process_volunteers
has_many :semester_feedbacks, through: :semester_process_volunteers
has_attached_file :avatar, styles: { thumb: '100x100#' }
# Validations
......
class CreateSemesterFeedbacks < ActiveRecord::Migration[5.1]
def change
create_table :semester_feedbacks do |t|
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.text :goals
t.text :achievements
t.text :future
t.text :comments
t.boolean :conversation, default: false
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: 20181004134604) do
ActiveRecord::Schema.define(version: 20181004141844) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -624,6 +624,23 @@ ActiveRecord::Schema.define(version: 20181004134604) do
t.index ["deleted_at"], name: "index_reminder_mailings_on_deleted_at"
end
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.text "goals"
t.text "achievements"
t.text "future"
t.text "comments"
t.boolean "conversation", default: false
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_id"], name: "index_semester_feedbacks_on_author_id"
t.index ["deleted_at"], name: "index_semester_feedbacks_on_deleted_at"
end
create_table "semester_process_volunteers", force: :cascade do |t|
t.bigint "volunteer_id"
t.bigint "semester_process_id"
......
FactoryBot.define do
factory :semester_feedback do
association :author, factory: :user
volunteer
semester_process_volunteer
goals 'Goals text'
achievements 'Achievements text'
future 'Future text'
comments 'Comments text'
association :semester_feedbackable, factory: :group_assignment
end
end
require 'test_helper'
class SemesterFeedbackTest < 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