Skip to content

Commit 2c3cb36

Browse files
authored
Fixed API bug when creating binary submission files (#7647)
1 parent 1a494af commit 2c3cb36

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### 🐛 Bug fixes
1010
- Fixed group member filtering in assignment summary table (#7644)
1111
- Fixed spacing issue for the remote authentication login button (#7646)
12+
- Fixed API bug when creating binary submission files (#7647)
1213

1314
### 🔧 Internal changes
1415
- Updated the assignment summary table to use `@tanstack/react-table` v8 (#7630)

app/helpers/submissions_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def upload_file(grouping, only_required_files: false)
8585
content = params[:file_content]
8686
end
8787

88-
tmpfile = Tempfile.new
88+
tmpfile = Tempfile.new(binmode: true)
8989
begin
9090
tmpfile.write(content)
9191
tmpfile.rewind

spec/controllers/api/submission_files_controller_spec.rb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,41 @@
5757

5858
context 'POST create' do
5959
context 'when the file does not exist yet' do
60+
let(:filename) { 'v1/x/y/test.txt' }
61+
let(:content) { 'This is a test file' }
62+
let(:mime_type) { 'text/plain' }
63+
6064
before do
61-
post :create, params: { assignment_id: assignment.id, group_id: group.id, filename: 'v1/x/y/test.txt',
62-
mime_type: 'text', file_content: 'This is a test file', course_id: course.id }
65+
post :create, params: { assignment_id: assignment.id, group_id: group.id, filename: filename,
66+
mime_type: mime_type, file_content: content, course_id: course.id }
6367
end
6468

65-
it 'should create a file in the corresponding directory' do
66-
path = Pathname.new('v1/x/y')
67-
success, _messages = group.access_repo do |repo|
68-
file_path = Pathname.new(assignment.repository_folder).join path
69-
files = repo.get_latest_revision.files_at_path(file_path.to_s)
70-
files.key? 'test.txt'
69+
context 'when the file is plaintext' do
70+
it 'should create the file in the corresponding directory' do
71+
path = Pathname.new('v1/x/y')
72+
success, _messages = group.access_repo do |repo|
73+
file_path = Pathname.new(assignment.repository_folder).join path
74+
files = repo.get_latest_revision.files_at_path(file_path.to_s)
75+
files.key? File.basename(filename)
76+
end
77+
expect(success).to be_truthy
78+
end
79+
end
80+
81+
context 'when the file is binary' do
82+
let(:filename) { 'v1/x/y/test.pdf' }
83+
let(:content) { file_fixture('submission_files/pdf.pdf') }
84+
let(:mime_type) { 'application/pdf' }
85+
86+
it 'should create the file in the corresponding directory' do
87+
path = Pathname.new('v1/x/y')
88+
success, _messages = group.access_repo do |repo|
89+
file_path = Pathname.new(assignment.repository_folder).join path
90+
files = repo.get_latest_revision.files_at_path(file_path.to_s)
91+
files.key? File.basename(filename)
92+
end
93+
expect(success).to be_truthy
7194
end
72-
expect(success).to be_truthy
7395
end
7496

7597
it_behaves_like 'for a different course'

0 commit comments

Comments
 (0)