Skip to content

Commit

Permalink
Add correct content type for pdf upload in exam_templates_controller_…
Browse files Browse the repository at this point in the history
…spec.rb (#7213)
  • Loading branch information
hemmatio authored Sep 18, 2024
1 parent db6b76d commit 006ad50
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

### 🔧 Internal changes

- Fix test coverage for ExamTemplate.create_with_file method (#7213)
- Upgrade Docker environment to use Ruby v3.3 (#7185)
- Upgrade to Rails v7.2 (#7185)
- Manually specify chromedriver port number in Github actions (#7209)
Expand Down
1 change: 1 addition & 0 deletions doc/markus-contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Nikhi Bhambra
Nina Huang
Noé Bedetti
Oloruntobi Ogunbiyi
Omid Hemmati
Ope Akanji
Oussama Ben Amar
Parker Hutcheson
Expand Down
34 changes: 33 additions & 1 deletion spec/controllers/exam_templates_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

describe '#create' do
let(:file_io) { fixture_file_upload('scanned_exams/midterm1-v2-test.pdf') }
let(:file_io) { fixture_file_upload('scanned_exams/midterm1-v2-test.pdf', 'application/pdf') }
let(:params) do
{ create_template: { file_io: file_io, name: 'Template 1' },
assignment_id: exam_template.assignment.id, course_id: course.id }
Expand All @@ -22,6 +22,38 @@
it('should respond with 302') { expect(response).to have_http_status :found }
end

describe '#create with empty filename' do
let(:file_io) { fixture_file_upload('scanned_exams/midterm1-v2-test.pdf', 'application/pdf') }
let(:params) do
{ create_template: { file_io: file_io, name: '' },
assignment_id: exam_template.assignment.id, course_id: course.id }
end

before { post_as user, :create, params: params }

it('should create an ExamTemplate with a default name') do
expect(ExamTemplate.count).to eq 1
created_template = ExamTemplate.last
expect(created_template.name).to eq 'midterm1-v2-test' # default name should be the filename w/ no extension
end

it('should respond with 302') { expect(response).to have_http_status :found }
end

describe '#create without specified content type' do
let(:file_io) { fixture_file_upload('scanned_exams/midterm1-v2-test.pdf') }
let(:params) do
{ create_template: { file_io: file_io, name: '' },
assignment_id: exam_template.assignment.id, course_id: course.id }
end

before { post_as user, :create, params: params }

it 'flashes an exam template create failure error message' do
expect(flash[:error].map { |f| extract_text f }).to eq [I18n.t('exam_templates.create.failure')]
end
end

describe '#edit' do
it 'should respond with 200 with html format' do
get_as user, :edit, format: 'html', params: { course_id: course.id, id: exam_template.id }
Expand Down

0 comments on commit 006ad50

Please sign in to comment.