added tests

This commit is contained in:
Hauke Klement
2015-02-10 15:36:03 +01:00
parent 59ca0a57c3
commit 6fbeb574e3
3 changed files with 79 additions and 29 deletions

View File

@ -107,39 +107,48 @@ describe Lti do
let(:consumer) { FactoryGirl.create(:consumer) }
let(:score) { 0.5 }
before(:each) do
controller.session[:consumer_id] = consumer.id
controller.session[:lti_parameters] = {}
end
context 'when grading is not supported' do
it 'returns a corresponding status' do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
expect(controller.send(:send_score, score)[:status]).to eq('unsupported')
end
end
context 'when grading is supported' do
let(:response) { double }
context 'with a tool provider' do
before(:each) do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score).and_return(response)
expect(response).to receive(:response_code).at_least(:once).and_return(200)
expect(response).to receive(:post_response).and_return(response)
expect(response).to receive(:body).at_least(:once).and_return('')
expect(response).to receive(:code_major).at_least(:once).and_return('success')
controller.session[:consumer_id] = consumer.id
controller.session[:lti_parameters] = {}
end
it 'sends the score' do
controller.send(:send_score, score)
context 'when grading is not supported' do
it 'returns a corresponding status' do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
expect(controller.send(:send_score, score)[:status]).to eq('unsupported')
end
end
it 'returns code, message, and status' do
result = controller.send(:send_score, score)
expect(result[:code]).to eq(response.response_code)
expect(result[:message]).to eq(response.body)
expect(result[:status]).to eq(response.code_major)
context 'when grading is supported' do
let(:response) { double }
before(:each) do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score).and_return(response)
expect(response).to receive(:response_code).at_least(:once).and_return(200)
expect(response).to receive(:post_response).and_return(response)
expect(response).to receive(:body).at_least(:once).and_return('')
expect(response).to receive(:code_major).at_least(:once).and_return('success')
end
it 'sends the score' do
controller.send(:send_score, score)
end
it 'returns code, message, and status' do
result = controller.send(:send_score, score)
expect(result[:code]).to eq(response.response_code)
expect(result[:message]).to eq(response.body)
expect(result[:status]).to eq(response.code_major)
end
end
end
context 'without a tool provider' do
it 'returns a corresponding status' do
expect(controller).to receive(:build_tool_provider).and_return(nil)
expect(controller.send(:send_score, score)[:status]).to eq('error')
end
end
end

View File

@ -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 } }

View File

@ -0,0 +1,15 @@
require 'rails_helper'
describe ExerciseHelper do
describe '#embedding_parameters' do
let(:exercise) { FactoryGirl.build(:dummy) }
it 'contains the locale' do
expect(embedding_parameters(exercise)).to start_with("locale=#{I18n.locale}")
end
it 'contains the token' do
expect(embedding_parameters(exercise)).to end_with("token=#{exercise.token}")
end
end
end