added tests
This commit is contained in:
@ -1,9 +1,35 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe CodeOcean::FilesController do
|
||||
let(:user) { FactoryGirl.build(:admin) }
|
||||
let(:user) { FactoryGirl.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:submission) { FactoryGirl.create(:submission, user: user) }
|
||||
|
||||
context 'with a valid file' do
|
||||
let(:request) { Proc.new { post :create, code_ocean_file: FactoryGirl.build(:file, context: submission).attributes, format: :json } }
|
||||
before(:each) { request.call }
|
||||
|
||||
expect_assigns(file: CodeOcean::File)
|
||||
|
||||
it 'creates the file' do
|
||||
expect { request.call }.to change(CodeOcean::File, :count)
|
||||
end
|
||||
|
||||
expect_json
|
||||
expect_status(201)
|
||||
end
|
||||
|
||||
context 'with an invalid file' do
|
||||
before(:each) { post :create, code_ocean_file: {context_id: submission.id, context_type: Submission}, format: :json }
|
||||
|
||||
expect_assigns(file: CodeOcean::File)
|
||||
expect_json
|
||||
expect_status(422)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:exercise) { FactoryGirl.create(:fibonacci) }
|
||||
let(:request) { Proc.new { delete :destroy, id: exercise.files.first.id } }
|
||||
|
Reference in New Issue
Block a user