Skip to content

Commit

Permalink
[205] Evaluator Submission Assignments (#233)
Browse files Browse the repository at this point in the history
* model and migration

---------

Co-authored-by: Stephen Chudleigh <stepchud@users.noreply.github.com>
  • Loading branch information
stonefilipczak and stepchud authored Oct 28, 2024
1 parent beb7426 commit def8ca1
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/evaluator_submission_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class EvaluatorSubmissionAssignment < ApplicationRecord
belongs_to :submission
belongs_to :evaluator, class_name: "User", foreign_key: :user_id, inverse_of: :assigned_submissions

enum :status, { assigned: 0, unassigned: 1, recused: 2 }
end
2 changes: 2 additions & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Submission < ApplicationRecord
belongs_to :challenge
belongs_to :phase
belongs_to :manager, class_name: 'User'
has_many :evaluator_submission_assignments, dependent: :destroy
has_many :evaluators, through: :evaluator_submission_assignments, class_name: "User"

# Fields
attribute :title, :string
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class User < ApplicationRecord
has_many :members, dependent: :destroy
has_many :supporting_documents, class_name: 'Document', dependent: :destroy
has_many :submissions, foreign_key: :submitter_id, inverse_of: :submitter, dependent: :destroy
has_many :evaluator_submission_assignments, dependent: :destroy
has_many :assigned_submissions, through: :evaluator_submission_assignments, source: :submission
has_many :managed_submissions,
class_name: 'Submission',
foreign_key: :manager_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateEvaluatorSubmissionAssignments < ActiveRecord::Migration[7.2]
def change
create_table :evaluator_submission_assignments do |t|
t.references :user, null: false, foreign_key: true
t.references :submission, null: false, foreign_key: true
t.integer :status, null: false

t.timestamps
end
end
end
79 changes: 79 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,39 @@ CREATE SEQUENCE public.evaluator_invitations_id_seq
ALTER SEQUENCE public.evaluator_invitations_id_seq OWNED BY public.evaluator_invitations.id;


--
-- Name: evaluator_submission_assignments; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.evaluator_submission_assignments (
id bigint NOT NULL,
user_id bigint NOT NULL,
submission_id bigint NOT NULL,
status integer NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);


--
-- Name: evaluator_submission_assignments_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.evaluator_submission_assignments_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: evaluator_submission_assignments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.evaluator_submission_assignments_id_seq OWNED BY public.evaluator_submission_assignments.id;


--
-- Name: federal_partners; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1272,6 +1305,13 @@ ALTER TABLE ONLY public.evaluation_forms ALTER COLUMN id SET DEFAULT nextval('pu
ALTER TABLE ONLY public.evaluator_invitations ALTER COLUMN id SET DEFAULT nextval('public.evaluator_invitations_id_seq'::regclass);


--
-- Name: evaluator_submission_assignments id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.evaluator_submission_assignments ALTER COLUMN id SET DEFAULT nextval('public.evaluator_submission_assignments_id_seq'::regclass);


--
-- Name: federal_partners id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1493,6 +1533,14 @@ ALTER TABLE ONLY public.evaluator_invitations
ADD CONSTRAINT evaluator_invitations_pkey PRIMARY KEY (id);


--
-- Name: evaluator_submission_assignments evaluator_submission_assignments_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.evaluator_submission_assignments
ADD CONSTRAINT evaluator_submission_assignments_pkey PRIMARY KEY (id);


--
-- Name: federal_partners federal_partners_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1753,6 +1801,20 @@ CREATE INDEX index_evaluator_invitations_on_challenge_id ON public.evaluator_inv
CREATE INDEX index_evaluator_invitations_on_phase_id ON public.evaluator_invitations USING btree (phase_id);


--
-- Name: index_evaluator_submission_assignments_on_submission_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_evaluator_submission_assignments_on_submission_id ON public.evaluator_submission_assignments USING btree (submission_id);


--
-- Name: index_evaluator_submission_assignments_on_user_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_evaluator_submission_assignments_on_user_id ON public.evaluator_submission_assignments USING btree (user_id);


--
-- Name: message_contexts_context_context_id_audience_parent_id_index; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1937,6 +1999,22 @@ ALTER TABLE ONLY public.evaluation_forms
ADD CONSTRAINT fk_rails_28ad57fb81 FOREIGN KEY (challenge_id) REFERENCES public.challenges(id);


--
-- Name: evaluator_submission_assignments fk_rails_3b40ec8e27; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.evaluator_submission_assignments
ADD CONSTRAINT fk_rails_3b40ec8e27 FOREIGN KEY (submission_id) REFERENCES public.submissions(id);


--
-- Name: evaluator_submission_assignments fk_rails_67111ac897; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.evaluator_submission_assignments
ADD CONSTRAINT fk_rails_67111ac897 FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: evaluation_criteria fk_rails_a39b8fa483; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2184,6 +2262,7 @@ ALTER TABLE ONLY public.winners
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
(20241023195356),
(20241018150049),
(20241015140056),
(20241014214843),
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/evaluator_submission_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :evaluator_submission_assignment do
# Associations
association :evaluator, factory: :user
association :submission

status { %w[assigned unassigned recused].sample }
end
end
11 changes: 11 additions & 0 deletions spec/factories/submission.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FactoryBot.define do
factory :submission do
# Associations
association :challenge
association :phase
association :submitter, factory: :user
association :manager, factory: :user

title { Faker::Lorem.sentence }
end
end
27 changes: 27 additions & 0 deletions spec/models/evaluator_submission_assignment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rails_helper'

RSpec.describe EvaluatorSubmissionAssignment, type: :model do
let(:submission) { create(:submission) }
let(:user) { create(:user, role: :evaluator) }

it "can be created with valid attributes" do
assignment = build(:evaluator_submission_assignment, submission:, evaluator: user)
expect(assignment).to be_valid
expect { assignment.save! }.to change { described_class.count }.by(1)
end

it "can be destroyed" do
assignment = create(:evaluator_submission_assignment, submission:, evaluator: user)
expect { assignment.destroy }.to change { described_class.count }.by(-1)
end

it "associates the user as an evaluator for the submission" do
create(:evaluator_submission_assignment, submission:, evaluator: user)
expect(submission.evaluators).to include(user)
end

it "associates the submission as an assigned submission for the evaluator" do
create(:evaluator_submission_assignment, submission:, evaluator: user)
expect(user.assigned_submissions).to include(submission)
end
end

0 comments on commit def8ca1

Please sign in to comment.