sped up some tests
This commit is contained in:
@ -5,12 +5,15 @@ class Controller < AnonymousController
|
||||
end
|
||||
|
||||
describe SubmissionScoring do
|
||||
before(:all) do
|
||||
@submission = FactoryGirl.create(:submission, cause: 'submit')
|
||||
end
|
||||
|
||||
let(:controller) { Controller.new }
|
||||
let(:submission) { FactoryGirl.create(:submission, cause: 'submit') }
|
||||
before(:each) { controller.instance_variable_set(:@current_user, FactoryGirl.create(:external_user)) }
|
||||
|
||||
describe '#score_submission' do
|
||||
let(:score_submission) { Proc.new { controller.score_submission(submission) } }
|
||||
let(:score_submission) { Proc.new { controller.score_submission(@submission) } }
|
||||
before(:each) { score_submission.call }
|
||||
|
||||
it 'assigns @assessor' do
|
||||
@ -22,14 +25,14 @@ describe SubmissionScoring do
|
||||
end
|
||||
|
||||
it 'executes the teacher-defined test cases' do
|
||||
submission.collect_files.select(&:teacher_defined_test?).each do |file|
|
||||
expect_any_instance_of(DockerClient).to receive(:execute_test_command).with(submission, file.name_with_extension).and_return({})
|
||||
@submission.collect_files.select(&:teacher_defined_test?).each do |file|
|
||||
expect_any_instance_of(DockerClient).to receive(:execute_test_command).with(@submission, file.name_with_extension).and_return({})
|
||||
end
|
||||
score_submission.call
|
||||
end
|
||||
|
||||
it 'updates the submission' do
|
||||
expect(submission).to receive(:update).with(score: anything)
|
||||
expect(@submission).to receive(:update).with(score: anything)
|
||||
score_submission.call
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ describe ErrorsController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:errors) { FactoryGirl.create_pair(:error) }
|
||||
before(:all) { FactoryGirl.create_pair(:error) }
|
||||
before(:each) { get :index, execution_environment_id: execution_environment.id }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
|
@ -72,7 +72,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:execution_environments) { FactoryGirl.create_pair(:ruby) }
|
||||
before(:all) { FactoryGirl.create_pair(:ruby) }
|
||||
before(:each) { get :index }
|
||||
|
||||
expect_assigns(execution_environments: ExecutionEnvironment.all)
|
||||
|
@ -1,12 +1,12 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExercisesController do
|
||||
let(:exercise) { FactoryGirl.create(:fibonacci) }
|
||||
let(:exercise) { FactoryGirl.create(:dummy) }
|
||||
let(:user) { FactoryGirl.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:exercise_attributes) { FactoryGirl.build(:fibonacci).attributes }
|
||||
let(:exercise_attributes) { FactoryGirl.build(:dummy).attributes }
|
||||
|
||||
context 'with a valid exercise' do
|
||||
let(:request) { Proc.new { post :create, exercise: exercise_attributes } }
|
||||
@ -61,7 +61,7 @@ describe ExercisesController do
|
||||
expect_assigns(exercise: :exercise)
|
||||
|
||||
it 'destroys the exercise' do
|
||||
exercise = FactoryGirl.create(:fibonacci)
|
||||
exercise = FactoryGirl.create(:dummy)
|
||||
expect { delete :destroy, id: exercise.id }.to change(Exercise, :count).by(-1)
|
||||
end
|
||||
|
||||
@ -102,8 +102,8 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:exercises) { FactoryGirl.create_pair(:fibonacci) }
|
||||
let(:scope) { Pundit.policy_scope!(user, Exercise) }
|
||||
before(:all) { FactoryGirl.create_pair(:dummy) }
|
||||
before(:each) { get :index }
|
||||
|
||||
expect_assigns(exercises: :scope)
|
||||
@ -195,7 +195,7 @@ describe ExercisesController do
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid exercise' do
|
||||
let(:exercise_attributes) { FactoryGirl.build(:fibonacci).attributes }
|
||||
let(:exercise_attributes) { FactoryGirl.build(:dummy).attributes }
|
||||
before(:each) { put :update, exercise: exercise_attributes, id: exercise.id }
|
||||
|
||||
expect_assigns(exercise: Exercise)
|
||||
|
@ -53,7 +53,7 @@ describe FileTypesController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:file_types) { FactoryGirl.create_pair(:dot_rb) }
|
||||
before(:all) { FactoryGirl.create_pair(:dot_rb) }
|
||||
before(:each) { get :index }
|
||||
|
||||
expect_assigns(file_types: FileType.all)
|
||||
|
@ -55,7 +55,7 @@ describe HintsController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:hints) { FactoryGirl.create_pair(:ruby_syntax_error) }
|
||||
before(:all) { FactoryGirl.create_pair(:ruby_syntax_error) }
|
||||
before(:each) { get :index, execution_environment_id: execution_environment.id }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
|
@ -27,7 +27,7 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
describe 'POST #create_through_lti' do
|
||||
let(:exercise) { FactoryGirl.create(:fibonacci) }
|
||||
let(:exercise) { FactoryGirl.create(:dummy) }
|
||||
let(:nonce) { SecureRandom.hex }
|
||||
|
||||
context 'without OAuth parameters' do
|
||||
@ -125,7 +125,7 @@ describe SessionsController do
|
||||
|
||||
describe 'GET #destroy_through_lti' do
|
||||
let(:request) { Proc.new { get :destroy_through_lti, consumer_id: consumer.id, submission_id: submission.id } }
|
||||
let(:submission) { FactoryGirl.create(:submission) }
|
||||
let(:submission) { FactoryGirl.create(:submission, exercise: FactoryGirl.create(:dummy)) }
|
||||
|
||||
before(:each) do
|
||||
session[:consumer_id] = consumer.id
|
||||
|
@ -57,7 +57,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:submissions) { FactoryGirl.create_pair(:submission) }
|
||||
before(:all) { FactoryGirl.create_pair(:submission) }
|
||||
before(:each) { get :index }
|
||||
|
||||
expect_assigns(submissions: Submission.all)
|
||||
|
@ -50,7 +50,7 @@ describe TeamsController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:teams) { FactoryGirl.create_pair(:team) }
|
||||
before(:all) { FactoryGirl.create_pair(:team) }
|
||||
before(:each) { get :index }
|
||||
|
||||
expect_assigns(teams: Team.all)
|
||||
|
@ -32,6 +32,14 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :dummy, class: Exercise do
|
||||
created_by_teacher
|
||||
description 'Dummy'
|
||||
association :execution_environment, factory: :ruby
|
||||
instructions
|
||||
title 'Dummy'
|
||||
end
|
||||
|
||||
factory :even_odd, class: Exercise do
|
||||
created_by_teacher
|
||||
description 'Implement two methods even and odd which return whether a given number is even or odd, respectively.'
|
||||
|
@ -1,29 +1,30 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Submission do
|
||||
let(:submission) { Submission.create }
|
||||
before(:all) do
|
||||
@submission = FactoryGirl.create(:submission)
|
||||
end
|
||||
|
||||
it 'validates the presence of a cause' do
|
||||
expect(submission.errors[:cause]).to be_present
|
||||
expect(Submission.create.errors[:cause]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of an exercise' do
|
||||
expect(submission.errors[:exercise_id]).to be_present
|
||||
expect(Submission.create.errors[:exercise_id]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of a user' do
|
||||
expect(submission.errors[:user_id]).to be_present
|
||||
expect(submission.errors[:user_type]).to be_present
|
||||
expect(Submission.create.errors[:user_id]).to be_present
|
||||
expect(Submission.create.errors[:user_type]).to be_present
|
||||
end
|
||||
|
||||
%w[download render run test].each do |action|
|
||||
describe "##{action}_url" do
|
||||
let(:submission) { FactoryGirl.create(:submission) }
|
||||
let(:url) { submission.send(:"#{action}_url") }
|
||||
let(:url) { @submission.send(:"#{action}_url") }
|
||||
|
||||
it "starts like the #{action} path" do
|
||||
filename = File.basename(__FILE__)
|
||||
expect(url).to start_with(Rails.application.routes.url_helpers.send(:"#{action}_submission_path", submission, filename).sub(filename, ''))
|
||||
expect(url).to start_with(Rails.application.routes.url_helpers.send(:"#{action}_submission_path", @submission, filename).sub(filename, ''))
|
||||
end
|
||||
|
||||
it 'ends with a placeholder' do
|
||||
|
@ -3,39 +3,41 @@ require 'rails_helper'
|
||||
describe CodeOcean::FilePolicy do
|
||||
subject { CodeOcean::FilePolicy }
|
||||
|
||||
let(:file) { FactoryGirl.build(:file) }
|
||||
let(:exercise) { FactoryGirl.create(:fibonacci) }
|
||||
let(:submission) { FactoryGirl.create(:submission) }
|
||||
|
||||
permissions :create? do
|
||||
context 'as part of an exercise' do
|
||||
before(:each) { file.context = exercise }
|
||||
before(:all) do
|
||||
@exercise = FactoryGirl.create(:fibonacci)
|
||||
@file = @exercise.files.first
|
||||
end
|
||||
|
||||
it 'grants access to admins' do
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), file)
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), @file)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
expect(subject).to permit(exercise.author, file)
|
||||
expect(subject).to permit(@exercise.author, @file)
|
||||
end
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
[:external_user, :teacher].each do |factory_name|
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), file)
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), @file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'as part of a submission' do
|
||||
before(:each) { file.context = submission }
|
||||
before(:all) do
|
||||
@submission = FactoryGirl.create(:submission)
|
||||
@file = @submission.files.first
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
expect(subject).to permit(submission.author, file)
|
||||
expect(subject).to permit(@submission.author, @file)
|
||||
end
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
[:admin, :external_user, :teacher].each do |factory_name|
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), file)
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), @file)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -43,29 +45,34 @@ describe CodeOcean::FilePolicy do
|
||||
|
||||
permissions :destroy? do
|
||||
context 'as part of an exercise' do
|
||||
before(:each) { file.context = exercise }
|
||||
before(:all) do
|
||||
@exercise = FactoryGirl.create(:fibonacci)
|
||||
@file = @exercise.files.first
|
||||
end
|
||||
|
||||
it 'grants access to admins' do
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), file)
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), @file)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
expect(subject).to permit(exercise.author, file)
|
||||
expect(subject).to permit(@exercise.author, @file)
|
||||
end
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
[:external_user, :teacher].each do |factory_name|
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), file)
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), @file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'as part of a submission' do
|
||||
before(:each) { file.context = submission }
|
||||
before(:all) do
|
||||
@file = FactoryGirl.create(:submission).files.first
|
||||
end
|
||||
|
||||
it 'does not grant access to anyone' do
|
||||
[:admin, :external_user, :teacher].each do |factory_name|
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), file)
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), @file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ describe ExercisePolicy do
|
||||
subject { ExercisePolicy }
|
||||
|
||||
before(:all) do
|
||||
@exercise = FactoryGirl.build(:fibonacci, team: FactoryGirl.create(:team))
|
||||
@exercise = FactoryGirl.build(:dummy, team: FactoryGirl.create(:team))
|
||||
end
|
||||
|
||||
[:create?, :index?, :new?].each do |action|
|
||||
@ -67,7 +67,7 @@ describe ExercisePolicy do
|
||||
[@admin, @teacher].each do |user|
|
||||
[true, false].each do |public|
|
||||
[@team, nil].each do |team|
|
||||
FactoryGirl.create(:fibonacci, public: public, team: team, user_id: user.id, user_type: InternalUser.class.name)
|
||||
FactoryGirl.create(:dummy, public: public, team: team, user_id: user.id, user_type: InternalUser.class.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ describe SubmissionPolicy do
|
||||
|
||||
it 'grants access to authors' do
|
||||
user = FactoryGirl.create(:external_user)
|
||||
expect(subject).to permit(user, FactoryGirl.build(:submission, user_id: user.id, user_type: user.class.name))
|
||||
expect(subject).to permit(user, FactoryGirl.build(:submission, exercise: Exercise.new, user_id: user.id, user_type: user.class.name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user