forked from expertiza/reimplementation-back-end
-
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.
- Loading branch information
Showing
15 changed files
with
235 additions
and
26 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
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20241118204942_add_assignment_id_to_questionnaires.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,5 @@ | ||
class AddAssignmentIdToQuestionnaires < ActiveRecord::Migration[7.0] | ||
def change | ||
add_reference :questionnaires, :assignment, foreign_key: true | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 @@ | ||
# spec/factories/assignments.rb | ||
FactoryBot.define do | ||
factory :assignment do | ||
sequence(:name) { |n| "Assignment #{n}" } | ||
directory_path { "assignment_#{name.downcase.gsub(/\s+/, '_')}" } | ||
|
||
# Required associations | ||
association :instructor, factory: [:user, :instructor] | ||
|
||
# Default values | ||
num_reviews { 3 } | ||
num_reviews_required { 3 } | ||
num_reviews_allowed { 3 } | ||
num_metareviews_required { 3 } | ||
num_metareviews_allowed { 3 } | ||
rounds_of_reviews { 1 } # This is the correct attribute name | ||
|
||
# Boolean flags with default values | ||
is_calibrated { false } | ||
has_badge { false } | ||
enable_pair_programming { false } | ||
staggered_deadline { false } | ||
show_teammate_reviews { false } | ||
is_coding_assignment { false } | ||
|
||
# Optional association | ||
course { nil } | ||
|
||
trait :with_course do | ||
association :course | ||
end | ||
|
||
trait :with_badge do | ||
has_badge { true } | ||
end | ||
|
||
trait :with_teams do | ||
after(:create) do |assignment| | ||
create_list(:team, 2, assignment: assignment) | ||
end | ||
end | ||
|
||
trait :with_participants do | ||
after(:create) do |assignment| | ||
create_list(:participant, 2, assignment: assignment) | ||
end | ||
end | ||
|
||
trait :with_questionnaires do | ||
after(:create) do |assignment| | ||
create(:assignment_questionnaire, assignment: assignment) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FactoryBot.define do | ||
factory :course do | ||
sequence(:name) { |n| "Course #{n}" } | ||
sequence(:directory_path) { |n| "course_#{n}" } | ||
association :instructor, factory: [:user, :instructor] | ||
association :institution | ||
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,31 @@ | ||
# spec/factories/questionnaires.rb | ||
FactoryBot.define do | ||
factory :questionnaire do | ||
sequence(:name) { |n| "Questionnaire #{n}" } | ||
private { false } | ||
min_question_score { 0 } | ||
max_question_score { 10 } | ||
association :instructor | ||
association :assignment | ||
|
||
# Trait for questionnaire with questions | ||
trait :with_questions do | ||
after(:create) do |questionnaire| | ||
create(:question, questionnaire: questionnaire, weight: 1, seq: 1, txt: "que 1", question_type: "Scale") | ||
create(:question, questionnaire: questionnaire, weight: 10, seq: 2, txt: "que 2", question_type: "Checkbox") | ||
end | ||
end | ||
end | ||
end | ||
|
||
# spec/factories/questions.rb | ||
FactoryBot.define do | ||
factory :question do | ||
sequence(:txt) { |n| "Question #{n}" } | ||
sequence(:seq) { |n| n } | ||
weight { 1 } | ||
question_type { "Scale" } | ||
break_before { true } | ||
association :questionnaire | ||
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,53 @@ | ||
# spec/factories/roles.rb | ||
FactoryBot.define do | ||
factory :role do | ||
sequence(:name) { |n| "Role #{n}" } | ||
|
||
trait :student do | ||
id { Role::STUDENT } | ||
name { 'Student' } | ||
end | ||
|
||
trait :ta do | ||
id { Role::TEACHING_ASSISTANT } | ||
name { 'Teaching Assistant' } | ||
end | ||
|
||
trait :instructor do | ||
id { Role::INSTRUCTOR } | ||
name { 'Instructor' } | ||
end | ||
|
||
trait :administrator do | ||
id { Role::ADMINISTRATOR } | ||
name { 'Administrator' } | ||
end | ||
|
||
trait :super_administrator do | ||
id { Role::SUPER_ADMINISTRATOR } | ||
name { 'Super Administrator' } | ||
end | ||
end | ||
end | ||
|
||
# spec/factories/institutions.rb | ||
FactoryBot.define do | ||
factory :institution do | ||
sequence(:name) { |n| "Institution #{n}" } | ||
end | ||
end | ||
|
||
# spec/factories/teams_users.rb | ||
FactoryBot.define do | ||
factory :teams_user do | ||
association :user | ||
association :team | ||
end | ||
end | ||
|
||
# spec/factories/teams.rb | ||
FactoryBot.define do | ||
factory :team do | ||
sequence(:name) { |n| "Team #{n}" } | ||
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Course, type: :model do | ||
let(:course) { build(:course, id: 1, name: 'ECE517') } | ||
let(:user1) { User.new name: 'abc', fullname: 'abc bbc', email: '[email protected]', password: '123456789', password_confirmation: '123456789' } | ||
let(:institution) { build(:institution, id: 1) } | ||
describe Course, type: :model do | ||
let(:role) {Role.create(name: 'Instructor', parent_id: nil, id: 2, default_page_id: nil)} | ||
let(:instructor) { Instructor.create(name: 'testinstructor', email: '[email protected]', full_name: 'Test Instructor', password: '123456', role: role) } | ||
let(:institution) { create(:institution, id: 1) } | ||
let(:course) { create(:course, id: 1, name: 'ECE517', instructor: instructor, institution: institution) } | ||
let(:user1) { create(:user, name: 'abcdef', full_name:'abc bbc', email: '[email protected]', password: '123456789', password_confirmation: '123456789') } | ||
|
||
describe 'validations' do | ||
it 'validates presence of name' do | ||
course.name = '' | ||
|
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Invitation, type: :model do | ||
include ActiveJob::TestHelper | ||
let(:user1) { create :user, name: 'rohitgeddam' } | ||
let(:user2) { create :user, name: 'superman' } | ||
let(:invalid_user) { build :user, name: 'INVALID' } | ||
let(:assignment) { create(:assignment) } | ||
let(:role) {Role.create(name: 'Instructor', parent_id: nil, id: 3, default_page_id: nil)} | ||
let(:instructor) { Instructor.create(name: 'testinstructor', email: '[email protected]', full_name: 'Test Instructor', password: '123456', role: role) } | ||
let(:assignment) { create(:assignment, instructor: instructor) } | ||
before(:each) do | ||
ActiveJob::Base.queue_adapter = :test | ||
end | ||
|
||
after(:each) do | ||
clear_enqueued_jobs | ||
end | ||
|
||
|
||
it 'is invitation_factory returning new Invitation' do | ||
|
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 |
---|---|---|
|
@@ -4,12 +4,13 @@ | |
# Creating dummy objects for the test with the help of let statement | ||
let(:role) { Role.create(name: 'Instructor', parent_id: nil, id: 2, default_page_id: nil) } | ||
let(:instructor) do | ||
Instructor.create(id: 1234, name: 'testinstructor', email: '[email protected]', fullname: 'Test Instructor', | ||
Instructor.create(id: 1234, name: 'testinstructor', email: '[email protected]', full_name: 'test instructor', | ||
password: '123456', role:) | ||
end | ||
let(:assignment) { create(:assignment, instructor: instructor) } | ||
let(:questionnaire) do | ||
Questionnaire.new id: 1, name: 'abc', private: 0, min_question_score: 0, max_question_score: 10, | ||
instructor_id: instructor.id | ||
instructor_id: instructor.id, assignment: assignment | ||
end | ||
|
||
describe 'validations' do | ||
|
@@ -67,7 +68,7 @@ | |
instructor.save! | ||
questionnaire.save! | ||
question = Question.create(seq: 1, txt: 'Sample question', question_type: 'multiple_choice', | ||
break_before: true, questionnaire:) | ||
break_before: true, questionnaire:questionnaire) | ||
expect { question.delete }.to change { Question.count }.by(-1) | ||
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 |
---|---|---|
@@ -1,15 +1,39 @@ | ||
require 'rails_helper' | ||
describe Questionnaire, type: :model do | ||
|
||
# Creating dummy objects for the test with the help of let statement | ||
let(:role) {Role.create(name: 'Instructor', parent_id: nil, id: 2, default_page_id: nil)} | ||
let(:instructor) { Instructor.create(name: 'testinstructor', email: '[email protected]', fullname: 'Test Instructor', password: '123456', role: role) } | ||
let(:questionnaire) { Questionnaire.new id: 1, name: 'abc', private: 0, min_question_score: 0, max_question_score: 10, instructor_id: instructor.id } | ||
let(:instructor) { Instructor.create(name: 'testinstructor', email: '[email protected]', full_name: 'Test Instructor', password: '123456', role: role) } | ||
let(:assignment) do | ||
Assignment.create!( | ||
id: 1, | ||
name: 'Test Assignment', | ||
directory_path: 'test_assignment', | ||
instructor: instructor, | ||
rounds_of_reviews: 1, | ||
num_reviews: 3, | ||
num_reviews_required: 3, | ||
num_reviews_allowed: 3, | ||
num_metareviews_required: 3, | ||
num_metareviews_allowed: 3 | ||
) | ||
end | ||
let(:questionnaire) do | ||
Questionnaire.create!( | ||
id: 1, | ||
name: 'abc', | ||
private: false, | ||
min_question_score: 0, | ||
max_question_score: 10, | ||
instructor: instructor, | ||
assignment: assignment | ||
) | ||
end | ||
let(:questionnaire1) { Questionnaire.new name: 'xyz', private: 0, max_question_score: 20, instructor_id: instructor.id } | ||
let(:questionnaire2) { Questionnaire.new name: 'pqr', private: 0, max_question_score: 10, instructor_id: instructor.id } | ||
let(:question1) { questionnaire.questions.build(weight: 1, id: 1, seq: 1, txt: "que 1", question_type: "Scale", break_before: true) } | ||
let(:question2) { questionnaire.questions.build(weight: 10, id: 2, seq: 2, txt: "que 2", question_type: "Checkbox", break_before: true) } | ||
|
||
|
||
|
||
describe '#name' do | ||
|
@@ -28,14 +52,14 @@ | |
end | ||
|
||
describe '#instructor_id' do | ||
# Test validates the instructor id in the questionnaire | ||
# Test validates the instructor id in the questionnaire | ||
it 'returns the instructor id' do | ||
expect(questionnaire.instructor_id).to eq(instructor.id) | ||
end | ||
end | ||
|
||
describe '#maximum_score' do | ||
# Test validates the maximum score in the questionnaire | ||
# Test validates the maximum score in the questionnaire | ||
it 'validate maximum score' do | ||
expect(questionnaire.max_question_score).to eq(10) | ||
end | ||
|
@@ -96,15 +120,6 @@ | |
it 'has many questions' do | ||
expect(questionnaire.questions).to include(question1, question2) | ||
end | ||
|
||
# Test ensures that a questionnaire is not deleted when it has questions associated | ||
it 'restricts deletion of questionnaire when it has associated questions' do | ||
instructor.save! | ||
questionnaire.save! | ||
question1.save! | ||
question2.save! | ||
expect { questionnaire.destroy! }.to raise_error(ActiveRecord::RecordNotDestroyed) | ||
end | ||
end | ||
|
||
describe '.copy_questionnaire_details' do | ||
|
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