Skip to content

Commit 0855103

Browse files
committed
remove unused method
add additional specs
1 parent 4670135 commit 0855103

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

app/models/code_ocean/file.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ def teacher_defined_assessment?
9191
teacher_defined_test? || teacher_defined_linter?
9292
end
9393

94-
def content_present?
95-
content? || attachment.attached?
96-
end
97-
private :content_present?
98-
9994
def filepath
10095
if path.present?
10196
::File.join(path, name_with_extension)

spec/controllers/code_ocean/files_controller_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,37 @@
8181
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
8282
end
8383
end
84+
85+
describe 'GET #render_protected_upload' do
86+
let(:exercise) { create(:audio_video) }
87+
let(:submission) { create(:submission, exercise:, contributor: create(:external_user)) }
88+
let(:file) { exercise.files.detect {|f| f.file_type.file_extension == '.mp4' } }
89+
let(:token) { Rack::Utils.parse_nested_query(URI.parse(signed_url).query)['token'] }
90+
91+
context 'with a valid signed URL and matching filename' do
92+
let(:signed_url) { AuthenticatedUrlHelper.sign(render_protected_upload_url(id: file, filename: file.filepath), file) }
93+
94+
before do
95+
get :render_protected_upload, params: {id: file.id, filename: file.filepath, token:}
96+
end
97+
98+
expect_assigns(file: :file)
99+
expect_redirect
100+
101+
it 'redirects to ActiveStorage blob with inline disposition' do
102+
location = response.headers['Location'] || response.location
103+
expect(location).to include('disposition=inline')
104+
expect(location).to include(file.attachment.filename.to_s)
105+
end
106+
end
107+
108+
context 'with a mismatching filename' do
109+
let(:signed_url) { AuthenticatedUrlHelper.sign(render_protected_upload_url(id: file, filename: file.filepath), file) }
110+
111+
it 'returns unauthorized' do
112+
get :render_protected_upload, params: {id: file.id, filename: 'wrong/name.mp4', token:}
113+
expect(response).to have_http_status(:unauthorized)
114+
end
115+
end
116+
end
84117
end

spec/models/code_ocean/file_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,21 @@
108108
end
109109
end
110110
end
111+
112+
describe '#size' do
113+
subject { file.size }
114+
115+
let(:content) { 'file content' }
116+
let(:file) { create(:file, :image, content:) }
117+
118+
after { file.attachment.purge }
119+
120+
it { is_expected.to be file.attachment.byte_size }
121+
122+
context 'when the file is not attached' do
123+
before { file.attachment.purge }
124+
125+
it { is_expected.to be content.length }
126+
end
127+
end
111128
end

0 commit comments

Comments
 (0)