Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second Batch of Submissions Tests #2132

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,18 @@ def destroyConfirm; end
## THIS MARKS THE END OF RESTful ROUTES
##

# TODONE? THIS MAY DELETE MOST OF YOUR USERS. USE WITH CAUTION.
action_auth_level :missing, :instructor
def missing
@submissions = @assessment.submissions

cuds = @course.students.to_a
missing_submission_students = @course.students.to_a
@missing = []

@submissions.each do |submission|
cuds.delete(submission.course_user_datum)
missing_submission_students.delete(submission.course_user_datum)
end

cuds.each_with_index do |c, i|
missing_submission_students.each_with_index do |c, i|
@missing[i] = {}
@missing[i][:id] = c.id
@missing[i][:email] = c.email
Expand Down
16 changes: 16 additions & 0 deletions spec/contexts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ def create_course_with_users(asmt_name: "testassessment")
puts "Built submissions"
end

def create_course_no_submissions_hash(asmt_name: "testasmtnosubs")
if @instructor_user.nil?
create_users
puts "Built users"
end
create_course
puts "Built courses"
create_assessment(asmt_name:)
puts "Built assessments"
create_problems
puts "Built problems"
{ course: @course, admin_user: @admin_user,
instructor_user: @instructor_user, course_assistant_user: @course_assistant_user,
students_cud: @students, assessment: @assessment }
end

def create_autograded_course_with_users
create_users
puts "Built users"
Expand Down
185 changes: 185 additions & 0 deletions spec/controllers/submissions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,52 @@
end
end

shared_examples "destroyConfirm_failure" do
it "renders with failure" do
sign_in(user)
get :destroyConfirm, params: { course_name: @course.name, assessment_name: @assessment.name,
id: get_first_submission_by_assessment(@assessment).id }
expect(response).not_to be_successful
expect(response.body).not_to match(/Deleting a student's submission/m)
end
end

shared_examples "destroyConfirm_success" do
it "renders with success" do
sign_in(user)
get :destroyConfirm, params: { course_name: @course.name, assessment_name: @assessment.name,
id: get_first_submission_by_assessment(@assessment).id }
expect(response).to be_successful
expect(response.body).to match(/Deleting a student's submission/m)
end
end

shared_examples "destroy_success" do
it "destroys a student's submission" do
sign_in(user)
submission = get_first_submission_by_assessment(@assessment)
expect do
post :destroy, params: { course_name: @course.name, assessment_name: @assessment.name,
id: submission.id }
end.to change(Submission, :count).by(-1)
expect(response).to have_http_status(302)
expect(flash[:success])
end
end

shared_examples "destroy_failure" do
it "fails to destroy submission" do
sign_in(user)
submission = Submission.where(course_user_datum_id: get_first_cud_by_uid(user.id)).first
expect do
post :destroy, params: { course_name: @course.name, assessment_name: @assessment.name,
id: submission.id }
end.to change(Submission, :count).by(0)
expect(response).to have_http_status(302)
expect(flash[:error])
end
end

describe "#index" do
include_context "controllers shared context"
context "when user is Autolab admin" do
Expand Down Expand Up @@ -209,4 +255,143 @@
it_behaves_like "edit_failure"
end
end

describe "#downloadAll" do
include_context "controllers shared context"
context "when user is Instructor of class with submissions" do
let!(:user) { instructor_user }
it "downloads all submissions for an assessment" do
sign_in(user)
get :downloadAll, params: { course_name: @course.name, assessment_name: @assessment.name }
expect(response).to be_successful
Zip::File.open_buffer(response.parsed_body) do |zip_file|
zip_file.each do |entry|
if entry.file?
content = entry.get_input_stream.read
expect(content).to match(/Hello Dave/m)
end
end
end
end
end
end

describe "#download" do
include_context "controllers shared context"
context "when user is Instructor of class with submissions" do
let!(:user) { instructor_user }
it "downloads a student's submission" do
sign_in(user)
get :download, params: { course_name: @course.name, assessment_name: @assessment.name,
id: get_first_submission_by_assessment(@assessment).id }
expect(response).to be_successful
file_data = response.parsed_body
expect(file_data).to match(/Hello Dave/m)
end
end
context "when user is student and downloads own submission" do
let!(:user) { student_user }
it "downloads submission" do
sign_in(user)
submission = Submission.where(course_user_datum_id: get_first_cud_by_uid(user.id)).first
get :download, params: { course_name: @course.name, assessment_name: @assessment.name,
id: submission.id }
expect(response).to be_successful
file_data = response.parsed_body
expect(file_data).to match(/Hello Dave/m)
end
end
end

describe "#missing" do
include_context "controllers shared context"
context "when user is student" do
let!(:user) { student_user }
it "fails to get missing submissions" do
sign_in(user)
get :missing, params: { course_name: @course.name, assessment_name: @assessment.name }
expect(response).not_to be_successful
expect(response.body).not_to match(/Missing Submissions/m)
end
end
context "when user is Instructor of class with submissions" do
let!(:user) { instructor_user }
it "doesn't show missing submissions" do
sign_in(user)
get :missing, params: { course_name: @course.name, assessment_name: @assessment.name }
expect(response).to be_successful
expect(response.body).to match(/Missing Submissions/m)
expect(response.body).to match(/No Missing Submissions!/m)
@students.each do |student|
expect(response.body).not_to match(/#{student.email}/m)
end
end
end
context "when user is Instructor of asmt no submissions" do
let!(:hash) { create_course_no_submissions_hash }
let!(:user) { instructor_user }
it "shows missing submissions" do
sign_in(user)
get :missing, params: { course_name: @course.name, assessment_name: @assessment.name }
expect(response).to be_successful
expect(response.body).to match(/Missing Submissions/m)
expect(response.body).not_to match(/No Missing Submissions!/m)
@students.each do |student|
expect(response.body).to match(/#{student.email}/m)
end
end
end
end

describe "#destroyConfirm" do
include_context "controllers shared context"
context "when user is Autolab admin" do
let!(:user) { admin_user }
it_behaves_like "destroyConfirm_success"
end

context "when user is Instructor" do
let!(:user) { instructor_user }
it_behaves_like "destroyConfirm_success"
end

context "when user is student" do
let!(:user) { student_user }
it_behaves_like "destroyConfirm_failure"
end

context "when user is Course Assistant" do
let!(:user) { course_assistant_user }
it_behaves_like "destroyConfirm_failure"
end
end

describe "#destroy" do
include_context "controllers shared context"
context "when user is Autolab admin" do
let!(:user) { admin_user }
it_behaves_like "destroy_success"
end
context "when user is Instructor" do
let!(:user) { instructor_user }
it_behaves_like "destroy_success"
end
context "when user is student" do
let!(:user) { student_user }
it_behaves_like "destroy_failure"
end
context "when user is Course Assistant" do
let!(:user) { course_assistant_user }
it "fails to destroy submission" do
sign_in(user)
submission = get_first_submission_by_assessment(@assessment)
expect do
post :destroy, params: { course_name: @course.name, assessment_name: @assessment.name,
id: submission.id }
end.to change(Submission, :count).by(0)
expect(response).to have_http_status(302)
expect(flash[:error])
end
end
end
end