Add new CodeOcean::File#read method
* With a new method, we can simplify our code to handle differences between file.content and file.native_file.read
This commit is contained in:
@ -131,7 +131,7 @@ describe SubmissionsController do
|
||||
expect_http_status(:ok)
|
||||
|
||||
it 'renders the file content' do
|
||||
expect(response.body).to eq(file.native_file.read)
|
||||
expect(response.body).to eq(file.read)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -160,7 +160,7 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
let(:files) { [build(:file, :image)] }
|
||||
|
||||
it 'copies the file inside the workspace' do
|
||||
expect(FileUtils).to receive(:cp).with(files.first.native_file.path, local_path.join(files.first.filepath))
|
||||
expect(File).to receive(:write).with(local_path.join(files.first.filepath), files.first.read)
|
||||
container_pool.copy_files(files)
|
||||
end
|
||||
end
|
||||
|
@ -56,4 +56,24 @@ describe CodeOcean::File do
|
||||
expect(file.errors[:weight]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a native file' do
|
||||
let(:file) { create(:file, :image) }
|
||||
|
||||
after { file.native_file.remove! }
|
||||
|
||||
context 'when the path has not been modified' do
|
||||
it 'reads the native file' do
|
||||
expect(file.read).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the path has been modified' do
|
||||
before { file.update(native_file: '../../../../secrets.yml') }
|
||||
|
||||
it 'does not read the native file' do
|
||||
expect(file.read).not_to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user