transferred Code Ocean from original repository to GitHub

This commit is contained in:
Hauke Klement
2015-01-22 09:51:49 +01:00
commit 4cbf9970b1
683 changed files with 11979 additions and 0 deletions

View File

@ -0,0 +1,52 @@
require 'rails_helper'
describe CodeOcean::File do
let(:file) { CodeOcean::File.create.tap { |file| file.update(content: nil, hidden: nil, read_only: nil) } }
it 'validates the presence of a file type' do
expect(file.errors[:file_type_id]).to be_present
end
it 'validates the presence of the hidden flag' do
expect(file.errors[:hidden]).to be_present
end
it 'validates the presence of a name' do
expect(file.errors[:name]).to be_present
end
it 'validates the presence of the read-only flag' do
expect(file.errors[:read_only]).to be_present
end
context 'as a teacher-defined test' do
before(:each) { file.update(role: 'teacher_defined_test') }
it 'validates the presence of a feedback message' do
expect(file.errors[:feedback_message]).to be_present
end
it 'validates the numericality of a weight' do
file.update(weight: 'heavy')
expect(file.errors[:weight]).to be_present
end
it 'validates the presence of a weight' do
expect(file.errors[:weight]).to be_present
end
end
context 'with another file type' do
before(:each) { file.update(role: 'regular_file') }
it 'validates the absence of a feedback message' do
file.update(feedback_message: 'Your solution is not correct yet.')
expect(file.errors[:feedback_message]).to be_present
end
it 'validates the absence of a weight' do
file.update(weight: 1)
expect(file.errors[:weight]).to be_present
end
end
end

View File

@ -0,0 +1,22 @@
require 'rails_helper'
describe Consumer do
let(:consumer) { Consumer.create }
it 'validates the presence of a name' do
expect(consumer.errors[:name]).to be_present
end
it 'validates the presence of an OAuth key' do
expect(consumer.errors[:oauth_key]).to be_present
end
it 'validates the uniqueness of the OAuth key' do
consumer.update(oauth_key: FactoryGirl.create(:consumer).oauth_key)
expect(consumer.errors[:oauth_key]).to be_present
end
it 'validates the presence of an OAuth secret' do
expect(consumer.errors[:oauth_secret]).to be_present
end
end

13
spec/models/error_spec.rb Normal file
View File

@ -0,0 +1,13 @@
require 'rails_helper'
describe Error do
let(:error) { Error.create }
it 'validates the presence of an execution environment' do
expect(error.errors[:execution_environment_id]).to be_present
end
it 'validates the presence of a message' do
expect(error.errors[:message]).to be_present
end
end

View File

@ -0,0 +1,87 @@
require 'rails_helper'
describe ExecutionEnvironment do
let(:execution_environment) { ExecutionEnvironment.create }
it 'validates that the Docker image works', docker: true do
expect(execution_environment).to receive(:working_docker_image?).and_call_original
expect(execution_environment).to receive(:validate_docker_image?).and_return(true)
execution_environment.update(docker_image: 'invalid')
expect(execution_environment.errors[:docker_image]).to be_present
end
it 'validates the presence of a Docker image name' do
expect(execution_environment.errors[:docker_image]).to be_present
end
it 'validates the presence of a name' do
expect(execution_environment.errors[:name]).to be_present
end
it 'validates the numericality of a permitted run time' do
execution_environment.update(permitted_execution_time: Math::PI)
expect(execution_environment.errors[:permitted_execution_time]).to be_present
end
it 'validates the presence of a permitted run time' do
expect(execution_environment.errors[:permitted_execution_time]).to be_present
end
it 'validates the presence of a run command' do
expect(execution_environment.errors[:run_command]).to be_present
end
it 'validates the presence of a user' do
expect(execution_environment.errors[:user_id]).to be_present
expect(execution_environment.errors[:user_type]).to be_present
end
describe '#validate_docker_image?' do
it 'is false in the test environment' do
expect(execution_environment.send(:validate_docker_image?)).to be false
end
it 'is false without a Docker image' do
allow(Rails).to receive(:env).and_return('production')
expect(execution_environment.send(:validate_docker_image?)).to be false
end
it 'is true otherwise' do
execution_environment.docker_image = DockerClient.image_tags.first
expect(Rails).to receive(:env).and_return('production')
expect(execution_environment.send(:validate_docker_image?)).to be true
end
end
describe '#working_docker_image?', docker: true do
let(:working_docker_image?) { execution_environment.send(:working_docker_image?) }
before(:each) { expect_any_instance_of(DockerClient).to receive(:find_image_by_tag).and_return(Object.new) }
it 'instantiates a Docker client' do
expect(DockerClient).to receive(:new).with(execution_environment: execution_environment).and_call_original
expect_any_instance_of(DockerClient).to receive(:execute_command).and_return({})
working_docker_image?
end
it 'executes the validation command' do
expect_any_instance_of(DockerClient).to receive(:execute_command).with(ExecutionEnvironment::VALIDATION_COMMAND).and_return({})
working_docker_image?
end
context 'when the command produces an error' do
it 'adds an error' do
expect_any_instance_of(DockerClient).to receive(:execute_command).and_return({stderr: 'command not found'})
working_docker_image?
expect(execution_environment.errors[:docker_image]).to be_present
end
end
context 'when the Docker client produces an error' do
it 'adds an error' do
expect_any_instance_of(DockerClient).to receive(:execute_command).and_raise(DockerClient::Error)
working_docker_image?
expect(execution_environment.errors[:docker_image]).to be_present
end
end
end
end

View File

@ -0,0 +1,30 @@
require 'rails_helper'
describe Exercise do
let(:exercise) { Exercise.create.tap { |exercise| exercise.update(public: nil, token: nil) } }
it 'validates the presence of a description' do
expect(exercise.errors[:description]).to be_present
end
it 'validates the presence of an execution environment' do
expect(exercise.errors[:execution_environment_id]).to be_present
end
it 'validates the presence of the public flag' do
expect(exercise.errors[:public]).to be_present
end
it 'validates the presence of a title' do
expect(exercise.errors[:title]).to be_present
end
it 'validates the presence of a token' do
expect(exercise.errors[:token]).to be_present
end
it 'validates the presence of a user' do
expect(exercise.errors[:user_id]).to be_present
expect(exercise.errors[:user_type]).to be_present
end
end

View File

@ -0,0 +1,25 @@
require 'rails_helper'
describe ExternalUser do
let(:user) { ExternalUser.create }
it 'validates the presence of a consumer' do
expect(user.errors[:consumer_id]).to be_present
end
it 'validates the presence of an external ID' do
expect(user.errors[:external_id]).to be_present
end
describe '#admin?' do
it 'is false' do
expect(FactoryGirl.build(:external_user).admin?).to be false
end
end
describe '#teacher?' do
it 'is false' do
expect(FactoryGirl.build(:external_user).teacher?).to be false
end
end
end

View File

@ -0,0 +1,50 @@
require 'rails_helper'
describe FileType do
let(:file_type) { FileType.create.tap { |file_type| file_type.update(binary: nil, executable: nil, renderable: nil) } }
it 'validates the presence of the binary flag' do
expect(file_type.errors[:binary]).to be_present
end
context 'when binary' do
before(:each) { file_type.update(binary: true) }
it 'does not validate the presence of an editor mode' do
expect(file_type.errors[:editor_mode]).not_to be_present
end
it 'does not validate the presence of an indent size' do
expect(file_type.errors[:indent_size]).not_to be_present
end
end
context 'when not binary' do
before(:each) { file_type.update(binary: false) }
it 'validates the presence of an editor mode' do
expect(file_type.errors[:editor_mode]).to be_present
end
it 'validates the presence of an indent size' do
expect(file_type.errors[:indent_size]).to be_present
end
end
it 'validates the presence of the executable flag' do
expect(file_type.errors[:executable]).to be_present
end
it 'validates the presence of a name' do
expect(file_type.errors[:name]).to be_present
end
it 'validates the presence of the renderable flag' do
expect(file_type.errors[:renderable]).to be_present
end
it 'validates the presence of a user' do
expect(file_type.errors[:user_id]).to be_present
expect(file_type.errors[:user_type]).to be_present
end
end

25
spec/models/hint_spec.rb Normal file
View File

@ -0,0 +1,25 @@
require 'rails_helper'
describe Hint do
let(:user) { Hint.create }
it 'validates the presence of an execution environment' do
expect(user.errors[:execution_environment_id]).to be_present
end
it 'validates the presence of a locale' do
expect(user.errors[:locale]).to be_present
end
it 'validates the presence of a message' do
expect(user.errors[:message]).to be_present
end
it 'validates the presence of a name' do
expect(user.errors[:name]).to be_present
end
it 'validates the presence of a regular expression' do
expect(user.errors[:regular_expression]).to be_present
end
end

View File

@ -0,0 +1,65 @@
require 'rails_helper'
describe InternalUser do
let(:password) { SecureRandom.hex }
let(:user) { InternalUser.create }
it 'validates the presence of an email address' do
expect(user.errors[:email]).to be_present
end
it 'validates the uniqueness of the email address' do
user.update(email: FactoryGirl.create(:admin).email)
expect(user.errors[:email]).to be_present
end
context 'when activated' do
let(:user) { FactoryGirl.create(:teacher, activation_state: 'active') }
it 'does not validate the confirmation of the password' do
user.update(password: password, password_confirmation: '')
expect(user.errors[:password_confirmation]).not_to be_present
end
it 'does not validate the presence of a password' do
expect(user.errors[:password]).not_to be_present
end
end
context 'when not activated' do
let(:user) { InternalUser.create(FactoryGirl.attributes_for(:teacher, activation_state: 'pending', password: nil)) }
it 'validates the confirmation of the password' do
user.update(password: password, password_confirmation: '')
expect(user.errors[:password_confirmation]).to be_present
end
it 'validates the presence of a password' do
user.update(name: Forgery::Name.full_name)
expect(user.errors[:password]).to be_present
end
end
it 'validates the domain of the role' do
user.update(role: 'Foo')
expect(user.errors[:role]).to be_present
end
it 'validates the presence of a role' do
expect(user.errors[:role]).to be_present
end
describe '#admin?' do
it 'is only true for admins' do
expect(FactoryGirl.build(:admin).admin?).to be true
expect(FactoryGirl.build(:teacher).admin?).to be false
end
end
describe '#teacher?' do
it 'is only true for teachers' do
expect(FactoryGirl.build(:admin).teacher?).to be false
expect(FactoryGirl.build(:teacher).teacher?).to be true
end
end
end

View File

@ -0,0 +1,34 @@
require 'rails_helper'
describe Submission do
let(:submission) { Submission.create }
it 'validates the presence of a cause' do
expect(submission.errors[:cause]).to be_present
end
it 'validates the presence of an exercise' do
expect(submission.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
end
%w[download render run test].each do |action|
describe "##{action}_url" do
let(:submission) { FactoryGirl.create(:submission) }
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, ''))
end
it 'ends with a placeholder' do
expect(url).to end_with(Submission::FILENAME_URL_PLACEHOLDER)
end
end
end
end