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,15 @@
require 'seeds_helper'
module CodeOcean
FactoryGirl.define do
factory :file, class: CodeOcean::File do
content ''
association :context, factory: :submission
association :file_type, factory: :dot_rb
hidden false
name { SecureRandom.hex }
read_only false
role 'main_file'
end
end
end

View File

@@ -0,0 +1,12 @@
FactoryGirl.define do
factory :consumer do
name 'openHPI'
oauth_key { SecureRandom.hex }
oauth_secret { SecureRandom.hex }
singleton_consumer
end
trait :singleton_consumer do
initialize_with { Consumer.where(name: name).first_or_create }
end
end

6
spec/factories/error.rb Normal file
View File

@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :error do
association :execution_environment, factory: :ruby
message "exercise.rb:4:in `<main>': undefined local variable or method `foo' for main:Object (NameError)"
end
end

View File

@@ -0,0 +1,114 @@
FactoryGirl.define do
factory :coffee_script, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-coffee:latest'
help
name 'CoffeeScript'
permitted_execution_time 10.seconds
run_command 'coffee'
singleton_execution_environment
end
factory :html, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-html:latest'
help
name 'HTML5'
permitted_execution_time 10.seconds
run_command 'touch'
singleton_execution_environment
test_command 'rspec %{filename} --format documentation'
testing_framework 'RspecAdapter'
end
factory :java, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-java:latest'
help
name 'Java 8'
permitted_execution_time 10.seconds
run_command 'make run'
singleton_execution_environment
test_command 'make test CLASS_NAME="%{class_name}" FILENAME="%{filename}"'
testing_framework 'JunitAdapter'
end
factory :jruby, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-jruby:latest'
help
name 'JRuby 1.7'
permitted_execution_time 10.seconds
run_command 'ruby %{filename}'
singleton_execution_environment
test_command 'rspec %{filename} --format documentation'
testing_framework 'RspecAdapter'
end
factory :node_js, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-node:latest'
help
name 'Node.js'
permitted_execution_time 10.seconds
run_command 'node %{filename}'
singleton_execution_environment
end
factory :python, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-python:latest'
help
name 'Python 2.7'
permitted_execution_time 10.seconds
run_command 'python %{filename}'
singleton_execution_environment
test_command 'python -m unittest --verbose %{module_name}'
testing_framework 'PyUnitAdapter'
end
factory :ruby, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-ruby:latest'
help
name 'Ruby 2.1'
permitted_execution_time 10.seconds
run_command 'ruby %{filename}'
singleton_execution_environment
test_command 'rspec %{filename} --format documentation'
testing_framework 'RspecAdapter'
end
factory :sinatra, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-sinatra:latest'
exposed_ports '4567'
help
name 'Sinatra'
permitted_execution_time 15.minutes
run_command 'ruby %{filename}'
singleton_execution_environment
test_command 'rspec %{filename} --format documentation'
testing_framework 'RspecAdapter'
end
factory :sqlite, class: ExecutionEnvironment do
created_by_teacher
docker_image 'hklement/ubuntu-sqlite:latest'
help
name 'SQLite'
permitted_execution_time 1.minute
run_command 'sqlite3 /database.db -init %{filename} -html'
singleton_execution_environment
test_command 'ruby %{filename}'
testing_framework 'SqlResultSetComparatorAdapter'
end
trait :help do
help { Forgery(:lorem_ipsum).words(Forgery(:basic).number(at_least: 50, at_most: 100)) }
end
trait :singleton_execution_environment do
initialize_with { ExecutionEnvironment.where(name: name).first_or_create }
end
end

174
spec/factories/exercise.rb Normal file
View File

@@ -0,0 +1,174 @@
require 'seeds_helper'
def create_seed_file(exercise, path, file_attributes = {})
file_extension = File.extname(path)
file_type = FactoryGirl.create(file_attributes[:file_type] || :"dot_#{file_extension.gsub('.', '')}")
name = File.basename(path).gsub(file_extension, '')
file_attributes.merge!(file_type: file_type, name: name, path: path.split('/')[1..-2].join('/'), role: file_attributes[:role] || 'regular_file')
if file_type.binary?
file_attributes.merge!(native_file: File.open(SeedsHelper.seed_file_path(path), 'r'))
else
file_attributes.merge!(content: SeedsHelper.read_seed_file(path))
end
file = exercise.add_file!(file_attributes)
end
FactoryGirl.define do
factory :audio_video, class: Exercise do
created_by_teacher
description "Try HTML's audio and video capabilities."
association :execution_environment, factory: :html
instructions "Build a simple website including an HTML <audio> and <video> element. Link the following media files: chai.ogg, devstories.mp4."
title 'Audio & Video'
after(:create) do |exercise|
create_seed_file(exercise, 'audio_video/index.html', role: 'main_file')
create_seed_file(exercise, 'audio_video/index.js')
create_seed_file(exercise, 'audio_video/index.html_spec.rb', feedback_message: 'Your solution is not correct yet.', hidden: true, role: 'teacher_defined_test')
create_seed_file(exercise, 'audio_video/chai.ogg', read_only: true)
create_seed_file(exercise, 'audio_video/devstories.mp4', read_only: true)
create_seed_file(exercise, 'audio_video/devstories.webm', read_only: true)
create_seed_file(exercise, 'audio_video/poster.png', read_only: true)
end
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.'
association :execution_environment, factory: :python
instructions
title 'Even/Odd'
after(:create) do |exercise|
create_seed_file(exercise, 'even_odd/exercise.py', role: 'main_file')
create_seed_file(exercise, 'even_odd/exercise_tests.py', feedback_message: 'Your solution is not correct yet.', hidden: true, role: 'teacher_defined_test')
create_seed_file(exercise, 'even_odd/reference.py', hidden: true, role: 'reference_implementation')
end
end
factory :fibonacci, class: Exercise do
created_by_teacher
description 'Implement a recursive function that calculates a requested Fibonacci number.'
association :execution_environment, factory: :ruby
instructions
title 'Fibonacci Sequence'
after(:create) do |exercise|
create_seed_file(exercise, 'fibonacci/exercise.rb', role: 'main_file')
create_seed_file(exercise, 'fibonacci/exercise_spec_1.rb', feedback_message: "The 'fibonacci' method is not defined correctly. Please take care that the method is called 'fibonacci', takes a single (integer) argument and returns an integer.", hidden: true, role: 'teacher_defined_test', weight: 1.5)
create_seed_file(exercise, 'fibonacci/exercise_spec_2.rb', feedback_message: 'Your method does not work recursively. Please make sure that the method works in a divide-and-conquer fashion by calling itself for partial results.', hidden: true, role: 'teacher_defined_test', weight: 2)
create_seed_file(exercise, 'fibonacci/exercise_spec_3.rb', feedback_message: 'Your method does not return the correct results for all tested input values. ', hidden: true, role: 'teacher_defined_test', weight: 3)
create_seed_file(exercise, 'fibonacci/reference.rb', hidden: true, role: 'reference_implementation')
end
end
factory :files, class: Exercise do
created_by_teacher
description 'Learn how to work with files.'
association :execution_environment, factory: :ruby
instructions
title 'Working with Files'
after(:create) do |exercise|
create_seed_file(exercise, 'files/data.txt', read_only: true)
create_seed_file(exercise, 'files/exercise.rb', role: 'main_file')
create_seed_file(exercise, 'files/exercise_spec.rb', feedback_message: 'Your solution is not correct yet.', hidden: true, role: 'teacher_defined_test')
end
end
factory :geolocation, class: Exercise do
created_by_teacher
description "Use the HTML5 Geolocation API to get the user's geographical position."
association :execution_environment, factory: :html
instructions
title 'Geolocation'
after(:create) do |exercise|
create_seed_file(exercise, 'geolocation/index.html', role: 'main_file')
create_seed_file(exercise, 'geolocation/index.js')
end
end
factory :hello_world, class: Exercise do
created_by_teacher
description "Write a simple 'Hello World' application."
association :execution_environment, factory: :ruby
instructions
title 'Hello World'
after(:create) do |exercise|
create_seed_file(exercise, 'hello_world/exercise.rb', role: 'main_file')
create_seed_file(exercise, 'hello_world/exercise_spec.rb', feedback_message: 'Your solution is not correct yet.', hidden: true, role: 'teacher_defined_test')
end
end
factory :math, class: Exercise do
created_by_teacher
description 'Implement a recursive math library.'
association :execution_environment, factory: :java
instructions
title 'Math'
after(:create) do |exercise|
create_seed_file(exercise, 'math/Makefile', file_type: :makefile, hidden: true, role: 'regular_file')
create_seed_file(exercise, 'math/org/example/RecursiveMath.java', role: 'main_file')
create_seed_file(exercise, 'math/org/example/RecursiveMathTest1.java', feedback_message: "The 'power' method is not defined correctly. Please take care that the method is called 'power', takes two arguments and returns a double.", hidden: true, role: 'teacher_defined_test')
create_seed_file(exercise, 'math/org/example/RecursiveMathTest2.java', feedback_message: 'Your solution yields wrong results.', hidden: true, role: 'teacher_defined_test')
end
end
factory :primes, class: Exercise do
created_by_teacher
description 'Write a function that prints the first n prime numbers.'
association :execution_environment, factory: :node_js
instructions
title 'Primes'
after(:create) do |exercise|
create_seed_file(exercise, 'primes/exercise.js', role: 'main_file')
end
end
factory :sql_select, class: Exercise do
created_by_teacher
description 'Learn to use the SELECT statement.'
association :execution_environment, factory: :sqlite
instructions "Write a query which selects the full rows for all people with the last name 'Doe'."
title 'SELECT'
after(:create) do |exercise|
create_seed_file(exercise, 'sql_select/exercise.sql', role: 'main_file')
create_seed_file(exercise, 'sql_select/comparator.rb', feedback_message: 'Your solution is not correct yet.', hidden: true, role: 'teacher_defined_test')
create_seed_file(exercise, 'sql_select/reference.sql', hidden: true, role: 'reference_implementation')
end
end
factory :tdd, class: Exercise do
created_by_teacher
description 'Learn to appreciate test-driven development.'
association :execution_environment, factory: :ruby
instructions SeedsHelper.read_seed_file('tdd/instructions.md')
title 'Test-driven Development'
after(:create) do |exercise|
create_seed_file(exercise, 'tdd/exercise.rb', role: 'main_file')
create_seed_file(exercise, 'tdd/exercise_spec.rb', role: 'user_defined_test')
end
end
factory :web_app, class: Exercise do
created_by_teacher
description 'Build a simple Web application with Sinatra.'
association :execution_environment, factory: :sinatra
instructions
title 'A Simple Web Application'
after(:create) do |exercise|
create_seed_file(exercise, 'web_app/app.rb', role: 'main_file')
end
end
trait :instructions do
instructions { Forgery(:lorem_ipsum).words(Forgery(:basic).number(at_least: 50, at_most: 100)) }
end
end

View File

@@ -0,0 +1,9 @@
FactoryGirl.define do
factory :external_user do
association :consumer
generated_email
external_id { SecureRandom.uuid }
generated_user_name
singleton_external_user
end
end

193
spec/factories/file_type.rb Normal file
View File

@@ -0,0 +1,193 @@
FactoryGirl.define do
factory :dot_coffee, class: FileType do
created_by_admin
editor_mode 'ace/mode/coffee'
executable
file_extension '.coffee'
indent_size 2
name 'CoffeeScript'
singleton_file_type
end
factory :dot_gif, class: FileType do
binary
created_by_admin
file_extension '.gif'
name 'GIF'
renderable
singleton_file_type
end
factory :dot_html, class: FileType do
created_by_admin
editor_mode 'ace/mode/html'
file_extension '.html'
indent_size 4
name 'HTML'
renderable
singleton_file_type
end
factory :dot_java, class: FileType do
created_by_admin
editor_mode 'ace/mode/java'
executable
file_extension '.java'
indent_size 4
name 'Java'
singleton_file_type
end
factory :dot_jpg, class: FileType do
binary
created_by_admin
file_extension '.jpg'
name 'JPEG'
renderable
singleton_file_type
end
factory :dot_js, class: FileType do
created_by_admin
editor_mode 'ace/mode/javascript'
executable
file_extension '.js'
indent_size 4
name 'JavaScript'
singleton_file_type
end
factory :dot_json, class: FileType do
created_by_admin
editor_mode 'ace/mode/javascript'
file_extension '.json'
indent_size 4
name 'JSON'
renderable
singleton_file_type
end
factory :dot_mp3, class: FileType do
binary
created_by_admin
file_extension '.mp3'
name 'MP3'
renderable
singleton_file_type
end
factory :dot_mp4, class: FileType do
binary
created_by_admin
file_extension '.mp4'
name 'MPEG-4'
renderable
singleton_file_type
end
factory :dot_ogg, class: FileType do
binary
created_by_admin
file_extension '.ogg'
name 'Ogg Vorbis'
renderable
singleton_file_type
end
factory :dot_png, class: FileType do
binary
created_by_admin
file_extension '.png'
name 'PNG'
renderable
singleton_file_type
end
factory :dot_py, class: FileType do
created_by_admin
editor_mode 'ace/mode/python'
executable
file_extension '.py'
indent_size 4
name 'Python'
singleton_file_type
end
factory :dot_rb, class: FileType do
created_by_admin
editor_mode 'ace/mode/ruby'
executable
file_extension '.rb'
indent_size 2
name 'Ruby'
singleton_file_type
end
factory :dot_svg, class: FileType do
created_by_admin
editor_mode 'ace/mode/svg'
file_extension '.svg'
indent_size 4
name 'SVG'
renderable
singleton_file_type
end
factory :dot_sql, class: FileType do
created_by_admin
editor_mode 'ace/mode/sql'
executable
file_extension '.sql'
indent_size 4
name 'SQL'
singleton_file_type
end
factory :dot_txt, class: FileType do
created_by_admin
editor_mode 'ace/mode/plain_text'
file_extension '.txt'
indent_size 4
name 'Plain Text'
renderable
singleton_file_type
end
factory :dot_webm, class: FileType do
binary
created_by_admin
file_extension '.webm'
name 'WebM'
renderable
singleton_file_type
end
factory :dot_xml, class: FileType do
created_by_admin
editor_mode 'ace/mode/xml'
file_extension '.xml'
indent_size 4
name 'XML'
renderable
singleton_file_type
end
factory :makefile, class: FileType do
created_by_admin
editor_mode 'ace/mode/makefile'
executable
indent_size 2
name 'Makefile'
singleton_file_type
end
%w[binary executable renderable].each do |attribute|
trait(attribute) do
self.send(attribute, true)
end
end
trait :singleton_file_type do
initialize_with { FileType.where(attributes).first_or_create }
end
end

101
spec/factories/hint.rb Normal file
View File

@@ -0,0 +1,101 @@
FactoryGirl.define do
factory :node_js_invalid_assignment, class: Hint do
association :execution_environment, factory: :node_js
english
message 'There was an error with an assignment. Maybe you have to use the equality operator here.'
name 'Invalid assignment'
regular_expression 'Invalid left-hand side in assignment'
end
factory :node_js_reference_error, class: Hint do
association :execution_environment, factory: :node_js
english
message "'$1' is not defined."
name 'ReferenceError'
regular_expression 'ReferenceError: (\w+) is not defined'
end
factory :node_js_syntax_error, class: Hint do
association :execution_environment, factory: :node_js
english
message 'You seem to have made a typo.'
name 'SyntaxError'
regular_expression 'SyntaxError: Unexpected token (\w+)'
end
factory :ruby_load_error, class: Hint do
association :execution_environment, factory: :ruby
english
message "The file '$1' cannot be found."
name 'LoadError'
regular_expression 'cannot load such file -- (\w+) (LoadError)'
end
factory :ruby_name_error_constant, class: Hint do
association :execution_environment, factory: :ruby
english
message "The constant '$1' is not defined."
name 'NameError (uninitialized constant)'
regular_expression 'uninitialized constant (\w+) \(NameError\)'
end
factory :ruby_name_error_variable, class: Hint do
association :execution_environment, factory: :ruby
english
message "Your object '$2' of class '$3' does not know what '$1' is. Maybe you made a typo or still have to define '$1'."
name 'NameError (undefined local variable or method)'
regular_expression 'undefined local variable or method `(\w+)\' for (\w+):(\w+) \(NameError\)'
end
factory :ruby_no_method_error, class: Hint do
association :execution_environment, factory: :ruby
english
message "Your object '$2' of class '$3' does not understand the method '$1'. Maybe you made a typo or still have to implement that method."
name 'NoMethodError'
regular_expression 'undefined method `([\w\!\?=\[\]]+)\' for (\w+):(\w+) \(NoMethodError\)'
end
factory :ruby_syntax_error, class: Hint do
association :execution_environment, factory: :ruby
english
message 'You seem to have made a typo.'
name 'SyntaxError'
regular_expression 'syntax error'
end
factory :ruby_system_stack_error, class: Hint do
association :execution_environment, factory: :ruby
english
message 'You seem to have built an infinite loop or recursion.'
name 'SystemStackError'
regular_expression 'stack level too deep \(SystemStackError\)'
end
factory :sqlite_no_such_column, class: Hint do
association :execution_environment, factory: :sqlite
english
message "The column '$1' does not exist."
name 'No Such Column'
regular_expression 'no such column: (\w+)'
end
factory :sqlite_no_such_table, class: Hint do
association :execution_environment, factory: :sqlite
english
message "The table '$1' does not exist."
name 'No Such Table'
regular_expression 'no such table: (\w+)'
end
factory :sqlite_syntax_error, class: Hint do
association :execution_environment, factory: :sqlite
english
message "You seem to have made a typo near '$1'."
name 'SyntaxError'
regular_expression 'near "(\w+)": syntax error'
end
trait :english do
locale 'en'
end
end

View File

@@ -0,0 +1,24 @@
FactoryGirl.define do
factory :admin, class: InternalUser do
activated_user
email 'admin@example.org'
generated_user_name
password 'admin'
role 'admin'
singleton_internal_user
end
factory :teacher, class: InternalUser do
activated_user
association :consumer
generated_email
generated_user_name
password 'teacher'
role 'teacher'
singleton_internal_user
end
trait :activated_user do
after(:create, &:activate!)
end
end

View File

@@ -0,0 +1,21 @@
FactoryGirl.define do
%w[admin external_user teacher].each do |factory_name|
trait :"created_by_#{factory_name}" do
association :user, factory: factory_name
end
end
trait :generated_email do
email { "#{name.underscore.gsub(' ', '.')}@example.org" }
end
trait :generated_user_name do
name { Forgery::Name.full_name }
end
[ExternalUser, InternalUser].each do |klass|
trait :"singleton_#{klass.name.underscore}" do
initialize_with { klass.where(email: email).first_or_create }
end
end
end

View File

@@ -0,0 +1,13 @@
FactoryGirl.define do
factory :submission do
cause 'save'
created_by_external_user
association :exercise, factory: :fibonacci
after(:create) do |submission|
submission.exercise.files.editable.visible.each do |file|
submission.add_file(content: file.content, file_id: file.id)
end
end
end
end