-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[205] Evaluator Submission Assignments (#233)
* model and migration --------- Co-authored-by: Stephen Chudleigh <stepchud@users.noreply.github.com>
- Loading branch information
1 parent
beb7426
commit def8ca1
Showing
8 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
db/migrate/20241023195356_create_evaluator_submission_assignments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |