Update bundle (with newest rubocop version) and fix offenses
This commit is contained in:
52
Gemfile.lock
52
Gemfile.lock
@ -1,9 +1,9 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: https://github.com/evolve75/RubyTree.git
|
remote: https://github.com/evolve75/RubyTree.git
|
||||||
revision: eb045068f73529c66d9d84f0553fdf85fc98bc4f
|
revision: 6081d0959b706dcefb85e85faa329ebb2dabcf9e
|
||||||
specs:
|
specs:
|
||||||
rubytree (1.0.2)
|
rubytree (1.0.2)
|
||||||
json (~> 2.3.1)
|
json (~> 2.6.1)
|
||||||
structured_warnings (~> 0.4.0)
|
structured_warnings (~> 0.4.0)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
@ -151,7 +151,7 @@ GEM
|
|||||||
database_cleaner-core (~> 2.0.0)
|
database_cleaner-core (~> 2.0.0)
|
||||||
database_cleaner-core (2.0.1)
|
database_cleaner-core (2.0.1)
|
||||||
debug_inspector (1.1.0)
|
debug_inspector (1.1.0)
|
||||||
diff-lcs (1.4.4)
|
diff-lcs (1.5.0)
|
||||||
docile (1.4.0)
|
docile (1.4.0)
|
||||||
docker-api (2.2.0)
|
docker-api (2.2.0)
|
||||||
excon (>= 0.47.0)
|
excon (>= 0.47.0)
|
||||||
@ -226,25 +226,25 @@ GEM
|
|||||||
railties (>= 3.2.16)
|
railties (>= 3.2.16)
|
||||||
js-routes (2.2.0)
|
js-routes (2.2.0)
|
||||||
railties (>= 4)
|
railties (>= 4)
|
||||||
json (2.3.1)
|
json (2.6.1)
|
||||||
json_schemer (0.2.18)
|
json_schemer (0.2.18)
|
||||||
ecma-re-validator (~> 0.3)
|
ecma-re-validator (~> 0.3)
|
||||||
hana (~> 1.3)
|
hana (~> 1.3)
|
||||||
regexp_parser (~> 2.0)
|
regexp_parser (~> 2.0)
|
||||||
uri_template (~> 0.7)
|
uri_template (~> 0.7)
|
||||||
jwt (2.3.0)
|
jwt (2.3.0)
|
||||||
kaminari (1.2.1)
|
kaminari (1.2.2)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
kaminari-actionview (= 1.2.1)
|
kaminari-actionview (= 1.2.2)
|
||||||
kaminari-activerecord (= 1.2.1)
|
kaminari-activerecord (= 1.2.2)
|
||||||
kaminari-core (= 1.2.1)
|
kaminari-core (= 1.2.2)
|
||||||
kaminari-actionview (1.2.1)
|
kaminari-actionview (1.2.2)
|
||||||
actionview
|
actionview
|
||||||
kaminari-core (= 1.2.1)
|
kaminari-core (= 1.2.2)
|
||||||
kaminari-activerecord (1.2.1)
|
kaminari-activerecord (1.2.2)
|
||||||
activerecord
|
activerecord
|
||||||
kaminari-core (= 1.2.1)
|
kaminari-core (= 1.2.2)
|
||||||
kaminari-core (1.2.1)
|
kaminari-core (1.2.2)
|
||||||
kramdown (2.3.1)
|
kramdown (2.3.1)
|
||||||
rexml
|
rexml
|
||||||
listen (3.7.0)
|
listen (3.7.0)
|
||||||
@ -266,7 +266,7 @@ GEM
|
|||||||
rake
|
rake
|
||||||
mini_magick (4.11.0)
|
mini_magick (4.11.0)
|
||||||
mini_mime (1.1.2)
|
mini_mime (1.1.2)
|
||||||
mini_portile2 (2.5.3)
|
mini_portile2 (2.6.1)
|
||||||
minitest (5.15.0)
|
minitest (5.15.0)
|
||||||
minitest-autotest (1.1.1)
|
minitest-autotest (1.1.1)
|
||||||
minitest-server (~> 1.0)
|
minitest-server (~> 1.0)
|
||||||
@ -286,8 +286,8 @@ GEM
|
|||||||
netrc (0.11.0)
|
netrc (0.11.0)
|
||||||
newrelic_rpm (8.2.0)
|
newrelic_rpm (8.2.0)
|
||||||
nio4r (2.5.8)
|
nio4r (2.5.8)
|
||||||
nokogiri (1.11.7)
|
nokogiri (1.12.5)
|
||||||
mini_portile2 (~> 2.5.0)
|
mini_portile2 (~> 2.6.1)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nyan-cat-formatter (0.12.0)
|
nyan-cat-formatter (0.12.0)
|
||||||
rspec (>= 2.99, >= 2.14.2, < 4)
|
rspec (>= 2.99, >= 2.14.2, < 4)
|
||||||
@ -301,7 +301,7 @@ GEM
|
|||||||
pagedown-bootstrap-rails (2.1.4)
|
pagedown-bootstrap-rails (2.1.4)
|
||||||
railties (> 3.1)
|
railties (> 3.1)
|
||||||
parallel (1.21.0)
|
parallel (1.21.0)
|
||||||
parser (3.0.3.2)
|
parser (3.1.0.0)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
path_expander (1.1.0)
|
path_expander (1.1.0)
|
||||||
pg (1.2.3)
|
pg (1.2.3)
|
||||||
@ -381,7 +381,7 @@ GEM
|
|||||||
thor (~> 1.0)
|
thor (~> 1.0)
|
||||||
rainbow (3.0.0)
|
rainbow (3.0.0)
|
||||||
rake (13.0.6)
|
rake (13.0.6)
|
||||||
ransack (2.4.2)
|
ransack (2.5.0)
|
||||||
activerecord (>= 5.2.4)
|
activerecord (>= 5.2.4)
|
||||||
activesupport (>= 5.2.4)
|
activesupport (>= 5.2.4)
|
||||||
i18n
|
i18n
|
||||||
@ -422,25 +422,25 @@ GEM
|
|||||||
rspec-mocks (~> 3.10)
|
rspec-mocks (~> 3.10)
|
||||||
rspec-support (~> 3.10)
|
rspec-support (~> 3.10)
|
||||||
rspec-support (3.10.3)
|
rspec-support (3.10.3)
|
||||||
rubocop (1.23.0)
|
rubocop (1.24.1)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 3.0.0.0)
|
parser (>= 3.0.0.0)
|
||||||
rainbow (>= 2.2.2, < 4.0)
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
regexp_parser (>= 1.8, < 3.0)
|
regexp_parser (>= 1.8, < 3.0)
|
||||||
rexml
|
rexml
|
||||||
rubocop-ast (>= 1.12.0, < 2.0)
|
rubocop-ast (>= 1.15.1, < 2.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 1.4.0, < 3.0)
|
unicode-display_width (>= 1.4.0, < 3.0)
|
||||||
rubocop-ast (1.15.0)
|
rubocop-ast (1.15.1)
|
||||||
parser (>= 3.0.1.1)
|
parser (>= 3.0.1.1)
|
||||||
rubocop-performance (1.12.0)
|
rubocop-performance (1.13.1)
|
||||||
rubocop (>= 1.7.0, < 2.0)
|
rubocop (>= 1.7.0, < 2.0)
|
||||||
rubocop-ast (>= 0.4.0)
|
rubocop-ast (>= 0.4.0)
|
||||||
rubocop-rails (2.12.4)
|
rubocop-rails (2.13.0)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
rack (>= 1.1)
|
rack (>= 1.1)
|
||||||
rubocop (>= 1.7.0, < 2.0)
|
rubocop (>= 1.7.0, < 2.0)
|
||||||
rubocop-rspec (2.6.0)
|
rubocop-rspec (2.7.0)
|
||||||
rubocop (~> 1.19)
|
rubocop (~> 1.19)
|
||||||
ruby-progressbar (1.11.0)
|
ruby-progressbar (1.11.0)
|
||||||
ruby-vips (2.1.4)
|
ruby-vips (2.1.4)
|
||||||
@ -544,7 +544,7 @@ GEM
|
|||||||
will_paginate (3.3.1)
|
will_paginate (3.3.1)
|
||||||
xpath (3.2.0)
|
xpath (3.2.0)
|
||||||
nokogiri (~> 1.8)
|
nokogiri (~> 1.8)
|
||||||
zeitwerk (2.5.1)
|
zeitwerk (2.5.3)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
@ -625,4 +625,4 @@ DEPENDENCIES
|
|||||||
whenever
|
whenever
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.2.32
|
2.3.4
|
||||||
|
@ -5,7 +5,7 @@ module RedirectBehavior
|
|||||||
|
|
||||||
def redirect_after_submit
|
def redirect_after_submit
|
||||||
Rails.logger.debug { "Redirecting user with score:s #{@submission.normalized_score}" }
|
Rails.logger.debug { "Redirecting user with score:s #{@submission.normalized_score}" }
|
||||||
if @submission.normalized_score.to_d == 1.0.to_d
|
if @submission.normalized_score.to_d == BigDecimal('1.0')
|
||||||
if redirect_to_community_solution?
|
if redirect_to_community_solution?
|
||||||
redirect_to_community_solution
|
redirect_to_community_solution
|
||||||
return
|
return
|
||||||
|
@ -59,7 +59,7 @@ raise: false
|
|||||||
end
|
end
|
||||||
|
|
||||||
def collect_paths(files)
|
def collect_paths(files)
|
||||||
unique_paths = files.map(&:path).reject(&:blank?).uniq
|
unique_paths = files.map(&:path).compact_blank.uniq
|
||||||
subpaths = unique_paths.map do |path|
|
subpaths = unique_paths.map do |path|
|
||||||
Array.new((path.split('/').length + 1)) do |n|
|
Array.new((path.split('/').length + 1)) do |n|
|
||||||
path.split('/').shift(n).join('/')
|
path.split('/').shift(n).join('/')
|
||||||
|
@ -24,7 +24,7 @@ class ProxyExercisesController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
myparams = proxy_exercise_params
|
myparams = proxy_exercise_params
|
||||||
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].reject(&:empty?))
|
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
|
||||||
@proxy_exercise = ProxyExercise.new(myparams)
|
@proxy_exercise = ProxyExercise.new(myparams)
|
||||||
authorize!
|
authorize!
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class ProxyExercisesController < ApplicationController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
myparams = proxy_exercise_params
|
myparams = proxy_exercise_params
|
||||||
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].reject(&:blank?))
|
myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank)
|
||||||
update_and_respond(object: @proxy_exercise, params: myparams)
|
update_and_respond(object: @proxy_exercise, params: myparams)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ class StudyGroupsController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
myparams = study_group_params
|
myparams = study_group_params
|
||||||
myparams[:external_users] =
|
myparams[:external_users] =
|
||||||
StudyGroupMembership.find(myparams[:study_group_membership_ids].reject(&:empty?)).map(&:user)
|
StudyGroupMembership.find(myparams[:study_group_membership_ids].compact_blank).map(&:user)
|
||||||
myparams.delete(:study_group_membership_ids)
|
myparams.delete(:study_group_membership_ids)
|
||||||
update_and_respond(object: @study_group, params: myparams)
|
update_and_respond(object: @study_group, params: myparams)
|
||||||
end
|
end
|
||||||
|
@ -244,9 +244,7 @@ class SubmissionsController < ApplicationController
|
|||||||
@submission.files.each do |file|
|
@submission.files.each do |file|
|
||||||
content += "#{file.filepath}=#{file.file_id}\n"
|
content += "#{file.filepath}=#{file.file_id}\n"
|
||||||
end
|
end
|
||||||
File.open(path, 'w+') do |f|
|
File.write(path, content)
|
||||||
f.write(content)
|
|
||||||
end
|
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class UserExerciseFeedbacksController < ApplicationController
|
|||||||
authorize!
|
authorize!
|
||||||
if validate_inputs(uef_params)
|
if validate_inputs(uef_params)
|
||||||
path =
|
path =
|
||||||
if rfc && submission && submission.normalized_score.to_d == 1.0.to_d
|
if rfc && submission && submission.normalized_score.to_d == BigDecimal('1.0')
|
||||||
request_for_comment_path(rfc)
|
request_for_comment_path(rfc)
|
||||||
else
|
else
|
||||||
implement_exercise_path(@exercise)
|
implement_exercise_path(@exercise)
|
||||||
@ -82,7 +82,7 @@ class UserExerciseFeedbacksController < ApplicationController
|
|||||||
authorize!
|
authorize!
|
||||||
if @exercise && validate_inputs(uef_params)
|
if @exercise && validate_inputs(uef_params)
|
||||||
path =
|
path =
|
||||||
if rfc && submission && submission.normalized_score.to_d == 1.0.to_d
|
if rfc && submission && submission.normalized_score.to_d == BigDecimal('1.0')
|
||||||
request_for_comment_path(rfc)
|
request_for_comment_path(rfc)
|
||||||
else
|
else
|
||||||
implement_exercise_path(@exercise)
|
implement_exercise_path(@exercise)
|
||||||
|
@ -41,7 +41,6 @@ module CodeOcean
|
|||||||
|
|
||||||
validates :feedback_message, if: :teacher_defined_assessment?, presence: true
|
validates :feedback_message, if: :teacher_defined_assessment?, presence: true
|
||||||
validates :feedback_message, absence: true, unless: :teacher_defined_assessment?
|
validates :feedback_message, absence: true, unless: :teacher_defined_assessment?
|
||||||
validates :file_type_id, presence: true
|
|
||||||
validates :hashed_content, if: :content_present?, presence: true
|
validates :hashed_content, if: :content_present?, presence: true
|
||||||
validates :hidden, boolean_presence: true
|
validates :hidden, boolean_presence: true
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
@ -7,8 +7,5 @@ module Creation
|
|||||||
belongs_to :user, polymorphic: true
|
belongs_to :user, polymorphic: true
|
||||||
alias_method :author, :user
|
alias_method :author, :user
|
||||||
alias_method :creator, :user
|
alias_method :creator, :user
|
||||||
|
|
||||||
validates :user_id, presence: true
|
|
||||||
validates :user_type, presence: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,7 +49,7 @@ class Exercise < ApplicationRecord
|
|||||||
MAX_GROUP_EXERCISE_FEEDBACKS = 20
|
MAX_GROUP_EXERCISE_FEEDBACKS = 20
|
||||||
|
|
||||||
def average_percentage
|
def average_percentage
|
||||||
if average_score && (maximum_score.to_d != 0.0.to_d) && submissions.exists?(cause: 'submit')
|
if average_score && (maximum_score.to_d != BigDecimal('0.0')) && submissions.exists?(cause: 'submit')
|
||||||
(average_score / maximum_score * 100).round(2)
|
(average_score / maximum_score * 100).round(2)
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
@ -580,7 +580,7 @@ cause: %w[submit assess remoteSubmit remoteAssess]}).distinct
|
|||||||
private :valid_submission_deadlines?
|
private :valid_submission_deadlines?
|
||||||
|
|
||||||
def needs_more_feedback?(submission)
|
def needs_more_feedback?(submission)
|
||||||
if submission.normalized_score.to_d == 1.0.to_d
|
if submission.normalized_score.to_d == BigDecimal('1.0')
|
||||||
user_exercise_feedbacks.final.size <= MAX_GROUP_EXERCISE_FEEDBACKS
|
user_exercise_feedbacks.final.size <= MAX_GROUP_EXERCISE_FEEDBACKS
|
||||||
else
|
else
|
||||||
user_exercise_feedbacks.intermediate.size <= MAX_GROUP_EXERCISE_FEEDBACKS
|
user_exercise_feedbacks.intermediate.size <= MAX_GROUP_EXERCISE_FEEDBACKS
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ExternalUser < User
|
class ExternalUser < User
|
||||||
validates :consumer_id, presence: true
|
|
||||||
validates :external_id, presence: true
|
validates :external_id, presence: true
|
||||||
|
|
||||||
def displayname
|
def displayname
|
||||||
|
@ -175,7 +175,7 @@ class ProxyExercise < ApplicationRecord
|
|||||||
return 0.0
|
return 0.0
|
||||||
end
|
end
|
||||||
points_ratio = exercise.maximum_score(user) / max_score
|
points_ratio = exercise.maximum_score(user) / max_score
|
||||||
if points_ratio.to_d == 0.0.to_d
|
if points_ratio.to_d == BigDecimal('0.0')
|
||||||
Rails.logger.debug { "scoring user #{user.id} for exercise #{exercise.id}: points_ratio=#{points_ratio} score: 0" }
|
Rails.logger.debug { "scoring user #{user.id} for exercise #{exercise.id}: points_ratio=#{points_ratio} score: 0" }
|
||||||
return 0.0
|
return 0.0
|
||||||
elsif points_ratio > 1.0
|
elsif points_ratio > 1.0
|
||||||
|
@ -6,7 +6,7 @@ class Runner < ApplicationRecord
|
|||||||
|
|
||||||
before_validation :request_id
|
before_validation :request_id
|
||||||
|
|
||||||
validates :execution_environment, :user, :runner_id, presence: true
|
validates :runner_id, presence: true
|
||||||
|
|
||||||
attr_accessor :strategy
|
attr_accessor :strategy
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ class Submission < ApplicationRecord
|
|||||||
scope :in_study_group_of, ->(user) { where(study_group_id: user.study_groups) unless user.admin? }
|
scope :in_study_group_of, ->(user) { where(study_group_id: user.study_groups) unless user.admin? }
|
||||||
|
|
||||||
validates :cause, inclusion: {in: CAUSES}
|
validates :cause, inclusion: {in: CAUSES}
|
||||||
validates :exercise_id, presence: true
|
|
||||||
|
|
||||||
# after_save :trigger_working_times_action_cable
|
# after_save :trigger_working_times_action_cable
|
||||||
|
|
||||||
@ -293,7 +292,7 @@ class Submission < ApplicationRecord
|
|||||||
end
|
end
|
||||||
# Prevent floating point precision issues by converting to BigDecimal, e.g., for `0.28 * 25`
|
# Prevent floating point precision issues by converting to BigDecimal, e.g., for `0.28 * 25`
|
||||||
update(score: score.to_d)
|
update(score: score.to_d)
|
||||||
if normalized_score.to_d == 1.0.to_d
|
if normalized_score.to_d == BigDecimal('1.0')
|
||||||
Thread.new do
|
Thread.new do
|
||||||
RequestForComment.where(exercise_id: exercise_id, user_id: user_id, user_type: user_type).find_each do |rfc|
|
RequestForComment.where(exercise_id: exercise_id, user_id: user_id, user_type: user_type).find_each do |rfc|
|
||||||
rfc.full_score_reached = true
|
rfc.full_score_reached = true
|
||||||
|
@ -4,8 +4,4 @@ class UserExerciseIntervention < ApplicationRecord
|
|||||||
belongs_to :user, polymorphic: true
|
belongs_to :user, polymorphic: true
|
||||||
belongs_to :intervention
|
belongs_to :intervention
|
||||||
belongs_to :exercise
|
belongs_to :exercise
|
||||||
|
|
||||||
validates :user, presence: true
|
|
||||||
validates :exercise, presence: true
|
|
||||||
validates :intervention, presence: true
|
|
||||||
end
|
end
|
||||||
|
@ -5,10 +5,5 @@ class UserProxyExerciseExercise < ApplicationRecord
|
|||||||
belongs_to :exercise
|
belongs_to :exercise
|
||||||
belongs_to :proxy_exercise
|
belongs_to :proxy_exercise
|
||||||
|
|
||||||
validates :user_id, presence: true
|
|
||||||
validates :user_type, presence: true
|
|
||||||
validates :exercise_id, presence: true
|
|
||||||
validates :proxy_exercise_id, presence: true
|
|
||||||
|
|
||||||
validates :user_id, uniqueness: {scope: %i[proxy_exercise_id user_type]}
|
validates :user_id, uniqueness: {scope: %i[proxy_exercise_id user_type]}
|
||||||
end
|
end
|
||||||
|
@ -40,9 +40,9 @@ module ProformaService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def task_files
|
def task_files
|
||||||
@task_files ||= @task.all_files.reject {|file| file.id == 'ms-placeholder-file' }.map do |task_file|
|
@task_files ||= @task.all_files.reject {|file| file.id == 'ms-placeholder-file' }.to_h do |task_file|
|
||||||
[task_file.id, codeocean_file_from_task_file(task_file)]
|
[task_file.id, codeocean_file_from_task_file(task_file)]
|
||||||
end.to_h
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def codeocean_file_from_task_file(file)
|
def codeocean_file_from_task_file(file)
|
||||||
|
@ -9,7 +9,6 @@ class DropErrors < ActiveRecord::Migration[5.2]
|
|||||||
scope :for_execution_environment, ->(execution_environment) { where(execution_environment_id: execution_environment.id) }
|
scope :for_execution_environment, ->(execution_environment) { where(execution_environment_id: execution_environment.id) }
|
||||||
scope :grouped_by_message, -> { select('MAX(created_at) AS created_at, MAX(id) AS id, message, COUNT(id) AS count').group(:message).order('count DESC') }
|
scope :grouped_by_message, -> { select('MAX(created_at) AS created_at, MAX(id) AS id, message, COUNT(id) AS count').group(:message).order('count DESC') }
|
||||||
|
|
||||||
validates :execution_environment_id, presence: true
|
|
||||||
validates :message, presence: true
|
validates :message, presence: true
|
||||||
|
|
||||||
def self.nested_resource?
|
def self.nested_resource?
|
||||||
|
@ -8,7 +8,7 @@ module ActiveModel
|
|||||||
def validate(record)
|
def validate(record)
|
||||||
[attributes].flatten.each do |attribute|
|
[attributes].flatten.each do |attribute|
|
||||||
value = record.send(:read_attribute_for_validation, attribute)
|
value = record.send(:read_attribute_for_validation, attribute)
|
||||||
record.errors.add(attribute, nil, options) unless BOOLEAN_VALUES.include?(value)
|
record.errors.add(attribute, nil, **options) unless BOOLEAN_VALUES.include?(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ class Assessor
|
|||||||
|
|
||||||
def calculate_score(test_outcome)
|
def calculate_score(test_outcome)
|
||||||
score = 0.0
|
score = 0.0
|
||||||
if test_outcome[:passed].to_d != 0.0.to_d && test_outcome[:count].to_d != 0.0.to_d
|
if test_outcome[:passed].to_d != BigDecimal('0.0') && test_outcome[:count].to_d != BigDecimal('0.0')
|
||||||
score = (test_outcome[:passed].to_f / test_outcome[:count])
|
score = (test_outcome[:passed].to_f / test_outcome[:count])
|
||||||
# prevent negative scores
|
# prevent negative scores
|
||||||
score = [0.0, score].max
|
score = [0.0, score].max
|
||||||
|
@ -9,7 +9,9 @@ module CodeOcean
|
|||||||
def read(options = {})
|
def read(options = {})
|
||||||
path = Rails.root.join('config', "#{@filename}.yml#{options[:erb] ? '.erb' : ''}")
|
path = Rails.root.join('config', "#{@filename}.yml#{options[:erb] ? '.erb' : ''}")
|
||||||
if ::File.exist?(path)
|
if ::File.exist?(path)
|
||||||
content = options[:erb] ? YAML.safe_load(ERB.new(::File.new(path, 'r').read).result, aliases: true, permitted_classes: [Range]) : YAML.load_file(path)
|
yaml_content = ::File.new(path, 'r').read || ''
|
||||||
|
yaml_content = ERB.new(yaml_content).result if options[:erb]
|
||||||
|
content = YAML.safe_load(yaml_content, aliases: true, permitted_classes: [Range, Symbol])
|
||||||
content[Rails.env].with_indifferent_access
|
content[Rails.env].with_indifferent_access
|
||||||
else
|
else
|
||||||
raise Error.new("Configuration file not found: #{path}")
|
raise Error.new("Configuration file not found: #{path}")
|
||||||
|
@ -17,7 +17,7 @@ class CppCatch2Adapter < TestingFrameworkAdapter
|
|||||||
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||||
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||||
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||||
{count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)}
|
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -315,7 +315,7 @@ container_execution_time: nil}
|
|||||||
@tubesock&.send_data JSON.dump({'cmd' => 'timeout'})
|
@tubesock&.send_data JSON.dump({'cmd' => 'timeout'})
|
||||||
if @socket
|
if @socket
|
||||||
begin
|
begin
|
||||||
@socket.send('#timeout')
|
@socket.send('#timeout') # rubocop:disable Performance/StringIdentifierArgument
|
||||||
# sleep one more second to ensure that the message reaches the submissions_controller.
|
# sleep one more second to ensure that the message reaches the submissions_controller.
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@socket.close
|
@socket.close
|
||||||
@ -434,9 +434,9 @@ container_execution_time: nil}
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.mapped_ports(execution_environment)
|
def self.mapped_ports(execution_environment)
|
||||||
execution_environment.exposed_ports.map do |port|
|
execution_environment.exposed_ports.to_h do |port|
|
||||||
["#{port}/tcp", [{'HostPort' => PortPool.available_port.to_s}]]
|
["#{port}/tcp", [{'HostPort' => PortPool.available_port.to_s}]]
|
||||||
end.to_h
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pull(docker_image)
|
def self.pull(docker_image)
|
||||||
|
@ -16,7 +16,7 @@ class Junit5Adapter < TestingFrameworkAdapter
|
|||||||
{count: count, passed: count}
|
{count: count, passed: count}
|
||||||
else
|
else
|
||||||
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||||
{count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)}
|
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ class JunitAdapter < TestingFrameworkAdapter
|
|||||||
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||||
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
|
||||||
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||||
{count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)}
|
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -43,8 +43,8 @@ class PyLintAdapter < TestingFrameworkAdapter
|
|||||||
{
|
{
|
||||||
count: count,
|
count: count,
|
||||||
failed: failed,
|
failed: failed,
|
||||||
error_messages: concatenated_errors.flatten.reject(&:blank?),
|
error_messages: concatenated_errors.flatten.compact_blank,
|
||||||
detailed_linter_results: assertion_error_matches.flatten.reject(&:blank?),
|
detailed_linter_results: assertion_error_matches.flatten.compact_blank,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,6 +32,6 @@ class PyUnitAdapter < TestingFrameworkAdapter
|
|||||||
Sentry.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json)
|
Sentry.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json)
|
||||||
assertion_error_matches = []
|
assertion_error_matches = []
|
||||||
end
|
end
|
||||||
{count: count, failed: failed + errors, error_messages: assertion_error_matches.flatten.reject(&:blank?)}
|
{count: count, failed: failed + errors, error_messages: assertion_error_matches.flatten.compact_blank}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,6 +14,6 @@ class RScriptAdapter < TestingFrameworkAdapter
|
|||||||
passed = captures.second
|
passed = captures.second
|
||||||
failed = count - passed
|
failed = count - passed
|
||||||
assertion_error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
assertion_error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
|
||||||
{count: count, failed: failed, error_messages: assertion_error_matches.flatten.reject(&:blank?)}
|
{count: count, failed: failed, error_messages: assertion_error_matches.flatten.compact_blank}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -97,7 +97,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
|||||||
FileUtils.cp(file.native_file.path, local_file_path)
|
FileUtils.cp(file.native_file.path, local_file_path)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
File.open(local_file_path, 'w') {|f| f.write(file.content) }
|
File.write(local_file_path, file.content)
|
||||||
rescue IOError => e
|
rescue IOError => e
|
||||||
raise Runner::Error::WorkspaceError.new("Could not create file #{file.filepath}: #{e.inspect}")
|
raise Runner::Error::WorkspaceError.new("Could not create file #{file.filepath}: #{e.inspect}")
|
||||||
end
|
end
|
||||||
|
@ -8,11 +8,11 @@ end
|
|||||||
|
|
||||||
describe FileParameters do
|
describe FileParameters do
|
||||||
let(:controller) { Controller.new }
|
let(:controller) { Controller.new }
|
||||||
let(:hello_world) { FactoryBot.create(:hello_world) }
|
let(:hello_world) { create(:hello_world) }
|
||||||
|
|
||||||
describe '#reject_illegal_file_attributes!' do
|
describe '#reject_illegal_file_attributes!' do
|
||||||
def file_accepted?(file)
|
def file_accepted?(file)
|
||||||
files = [[0, FactoryBot.attributes_for(:file, context: hello_world, file_id: file.id)]]
|
files = [[0, attributes_for(:file, context: hello_world, file_id: file.id)]]
|
||||||
filtered_files = controller.send(:reject_illegal_file_attributes, hello_world, files)
|
filtered_files = controller.send(:reject_illegal_file_attributes, hello_world, files)
|
||||||
files.eql?(filtered_files)
|
files.eql?(filtered_files)
|
||||||
end
|
end
|
||||||
@ -24,31 +24,31 @@ describe FileParameters do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'new file' do
|
it 'new file' do
|
||||||
submission = FactoryBot.create(:submission, exercise: hello_world, id: 1337)
|
submission = create(:submission, exercise: hello_world, id: 1337)
|
||||||
new_file = FactoryBot.create(:file, context: submission)
|
new_file = create(:file, context: submission)
|
||||||
expect(file_accepted?(new_file)).to be true
|
expect(file_accepted?(new_file)).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'rejects' do
|
describe 'rejects' do
|
||||||
it 'file of different exercise' do
|
it 'file of different exercise' do
|
||||||
fibonacci = FactoryBot.create(:fibonacci, allow_file_creation: true)
|
fibonacci = create(:fibonacci, allow_file_creation: true)
|
||||||
other_exercises_file = FactoryBot.create(:file, context: fibonacci)
|
other_exercises_file = create(:file, context: fibonacci)
|
||||||
expect(file_accepted?(other_exercises_file)).to be false
|
expect(file_accepted?(other_exercises_file)).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'hidden file' do
|
it 'hidden file' do
|
||||||
hidden_file = FactoryBot.create(:file, context: hello_world, hidden: true)
|
hidden_file = create(:file, context: hello_world, hidden: true)
|
||||||
expect(file_accepted?(hidden_file)).to be false
|
expect(file_accepted?(hidden_file)).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'read only file' do
|
it 'read only file' do
|
||||||
read_only_file = FactoryBot.create(:file, context: hello_world, read_only: true)
|
read_only_file = create(:file, context: hello_world, read_only: true)
|
||||||
expect(file_accepted?(read_only_file)).to be false
|
expect(file_accepted?(read_only_file)).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'non existent file' do
|
it 'non existent file' do
|
||||||
non_existent_file = FactoryBot.build(:file, context: hello_world, id: 42)
|
non_existent_file = build(:file, context: hello_world, id: 42)
|
||||||
expect(file_accepted?(non_existent_file)).to be false
|
expect(file_accepted?(non_existent_file)).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@ describe Lti do
|
|||||||
describe '#build_tool_provider' do
|
describe '#build_tool_provider' do
|
||||||
it 'instantiates a tool provider' do
|
it 'instantiates a tool provider' do
|
||||||
expect(IMS::LTI::ToolProvider).to receive(:new)
|
expect(IMS::LTI::ToolProvider).to receive(:new)
|
||||||
controller.send(:build_tool_provider, consumer: FactoryBot.build(:consumer), parameters: {})
|
controller.send(:build_tool_provider, consumer: build(:consumer), parameters: {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -101,12 +101,12 @@ describe Lti do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#send_score' do
|
describe '#send_score' do
|
||||||
let(:consumer) { FactoryBot.create(:consumer) }
|
let(:consumer) { create(:consumer) }
|
||||||
let(:score) { 0.5 }
|
let(:score) { 0.5 }
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
FactoryBot.create(:lti_parameter, consumers_id: consumer.id, external_users_id: submission.user_id, exercises_id: submission.exercise_id)
|
create(:lti_parameter, consumers_id: consumer.id, external_users_id: submission.user_id, exercises_id: submission.exercise_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with an invalid score' do
|
context 'with an invalid score' do
|
||||||
@ -168,18 +168,18 @@ describe Lti do
|
|||||||
let(:parameters) { ActionController::Parameters.new({}) }
|
let(:parameters) { ActionController::Parameters.new({}) }
|
||||||
|
|
||||||
it 'stores data in the session' do
|
it 'stores data in the session' do
|
||||||
controller.instance_variable_set(:@current_user, FactoryBot.create(:external_user))
|
controller.instance_variable_set(:@current_user, create(:external_user))
|
||||||
controller.instance_variable_set(:@exercise, FactoryBot.create(:fibonacci))
|
controller.instance_variable_set(:@exercise, create(:fibonacci))
|
||||||
expect(controller.session).to receive(:[]=).with(:external_user_id, anything)
|
expect(controller.session).to receive(:[]=).with(:external_user_id, anything)
|
||||||
expect(controller.session).to receive(:[]=).with(:lti_parameters_id, anything)
|
expect(controller.session).to receive(:[]=).with(:lti_parameters_id, anything)
|
||||||
controller.send(:store_lti_session_data, consumer: FactoryBot.build(:consumer), parameters: parameters)
|
controller.send(:store_lti_session_data, consumer: build(:consumer), parameters: parameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates an LtiParameter Object' do
|
it 'creates an LtiParameter Object' do
|
||||||
before_count = LtiParameter.count
|
before_count = LtiParameter.count
|
||||||
controller.instance_variable_set(:@current_user, FactoryBot.create(:external_user))
|
controller.instance_variable_set(:@current_user, create(:external_user))
|
||||||
controller.instance_variable_set(:@exercise, FactoryBot.create(:fibonacci))
|
controller.instance_variable_set(:@exercise, create(:fibonacci))
|
||||||
controller.send(:store_lti_session_data, consumer: FactoryBot.build(:consumer), parameters: parameters)
|
controller.send(:store_lti_session_data, consumer: build(:consumer), parameters: parameters)
|
||||||
expect(LtiParameter.count).to eq(before_count + 1)
|
expect(LtiParameter.count).to eq(before_count + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Admin::DashboardController do
|
describe Admin::DashboardController do
|
||||||
before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:admin)) }
|
before { allow(controller).to receive(:current_user).and_return(build(:admin)) }
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
describe 'with format HTML' do
|
describe 'with format HTML' do
|
||||||
|
@ -5,7 +5,7 @@ require 'rails_helper'
|
|||||||
describe ApplicationController do
|
describe ApplicationController do
|
||||||
describe '#current_user' do
|
describe '#current_user' do
|
||||||
context 'with an external user' do
|
context 'with an external user' do
|
||||||
let(:external_user) { FactoryBot.create(:external_user) }
|
let(:external_user) { create(:external_user) }
|
||||||
|
|
||||||
before { session[:external_user_id] = external_user.id }
|
before { session[:external_user_id] = external_user.id }
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ describe ApplicationController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'without an external user' do
|
context 'without an external user' do
|
||||||
let(:internal_user) { FactoryBot.create(:teacher) }
|
let(:internal_user) { create(:teacher) }
|
||||||
|
|
||||||
before { login_user(internal_user) }
|
before { login_user(internal_user) }
|
||||||
|
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe CodeOcean::FilesController do
|
describe CodeOcean::FilesController do
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
let(:submission) { FactoryBot.create(:submission, user: user) }
|
let(:submission) { create(:submission, user: user) }
|
||||||
|
|
||||||
context 'with a valid file' do
|
context 'with a valid file' do
|
||||||
let(:perform_request) { proc { post :create, params: {code_ocean_file: FactoryBot.build(:file, context: submission).attributes, format: :json} } }
|
let(:perform_request) { proc { post :create, params: {code_ocean_file: build(:file, context: submission).attributes, format: :json} } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
submission.exercise.update(allow_file_creation: true)
|
submission.exercise.update(allow_file_creation: true)
|
||||||
@ -41,7 +41,7 @@ describe CodeOcean::FilesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
let(:perform_request) { proc { delete :destroy, params: {id: exercise.files.first.id} } }
|
let(:perform_request) { proc { delete :destroy, params: {id: exercise.files.first.id} } }
|
||||||
|
|
||||||
before { perform_request.call }
|
before { perform_request.call }
|
||||||
@ -49,7 +49,7 @@ describe CodeOcean::FilesController do
|
|||||||
expect_assigns(file: CodeOcean::File)
|
expect_assigns(file: CodeOcean::File)
|
||||||
|
|
||||||
it 'destroys the file' do
|
it 'destroys the file' do
|
||||||
FactoryBot.create(:fibonacci)
|
create(:fibonacci)
|
||||||
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
|
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe CodeharborLinksController do
|
describe CodeharborLinksController do
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
||||||
let(:codeharbor_config) { {codeharbor: {enabled: true, url: 'http://test.url'}} }
|
let(:codeharbor_config) { {codeharbor: {enabled: true, url: 'http://test.url'}} }
|
||||||
@ -23,7 +23,7 @@ describe CodeharborLinksController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #edit' do
|
describe 'GET #edit' do
|
||||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
|
|
||||||
before { get :edit, params: {id: codeharbor_link.id} }
|
before { get :edit, params: {id: codeharbor_link.id} }
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ describe CodeharborLinksController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
let(:put_request) { patch :update, params: {id: codeharbor_link.id, codeharbor_link: params} }
|
let(:put_request) { patch :update, params: {id: codeharbor_link.id, codeharbor_link: params} }
|
||||||
let(:params) { {push_url: 'http://foo.bar/push', check_uuid_url: 'http://foo.bar/check', api_key: 'api_key'} }
|
let(:params) { {push_url: 'http://foo.bar/push', check_uuid_url: 'http://foo.bar/check', api_key: 'api_key'} }
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ describe CodeharborLinksController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
let(:destroy_request) { delete :destroy, params: {id: codeharbor_link.id} }
|
let(:destroy_request) { delete :destroy, params: {id: codeharbor_link.id} }
|
||||||
|
|
||||||
it 'deletes codeharbor_link' do
|
it 'deletes codeharbor_link' do
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ConsumersController do
|
describe ConsumersController do
|
||||||
let(:consumer) { FactoryBot.create(:consumer) }
|
let(:consumer) { create(:consumer) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context 'with a valid consumer' do
|
context 'with a valid consumer' do
|
||||||
let(:perform_request) { proc { post :create, params: {consumer: FactoryBot.attributes_for(:consumer)} } }
|
let(:perform_request) { proc { post :create, params: {consumer: attributes_for(:consumer)} } }
|
||||||
|
|
||||||
before { perform_request.call }
|
before { perform_request.call }
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ describe ConsumersController do
|
|||||||
expect_assigns(consumer: Consumer)
|
expect_assigns(consumer: Consumer)
|
||||||
|
|
||||||
it 'destroys the consumer' do
|
it 'destroys the consumer' do
|
||||||
consumer = FactoryBot.create(:consumer)
|
consumer = create(:consumer)
|
||||||
expect { delete :destroy, params: {id: consumer.id} }.to change(Consumer, :count).by(-1)
|
expect { delete :destroy, params: {id: consumer.id} }.to change(Consumer, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ describe ConsumersController do
|
|||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
before do
|
before do
|
||||||
FactoryBot.create_pair(:consumer)
|
create_pair(:consumer)
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ describe ConsumersController do
|
|||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
context 'with a valid consumer' do
|
context 'with a valid consumer' do
|
||||||
before { put :update, params: {consumer: FactoryBot.attributes_for(:consumer), id: consumer.id} }
|
before { put :update, params: {consumer: attributes_for(:consumer), id: consumer.id} }
|
||||||
|
|
||||||
expect_assigns(consumer: Consumer)
|
expect_assigns(consumer: Consumer)
|
||||||
expect_redirect(:consumer)
|
expect_redirect(:consumer)
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ErrorTemplateAttributesController do
|
describe ErrorTemplateAttributesController do
|
||||||
let!(:error_template_attribute) { FactoryBot.create(:error_template_attribute) }
|
let!(:error_template_attribute) { create(:error_template_attribute) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ describe ErrorTemplateAttributesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'updates error_template_attribute' do
|
it 'updates error_template_attribute' do
|
||||||
patch :update, params: {id: error_template_attribute, error_template_attribute: FactoryBot.attributes_for(:error_template_attribute)}
|
patch :update, params: {id: error_template_attribute, error_template_attribute: attributes_for(:error_template_attribute)}
|
||||||
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
|
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ErrorTemplatesController do
|
describe ErrorTemplatesController do
|
||||||
let!(:error_template) { FactoryBot.create(:error_template) }
|
let!(:error_template) { create(:error_template) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ describe ErrorTemplatesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'updates error_template' do
|
it 'updates error_template' do
|
||||||
patch :update, params: {id: error_template, error_template: FactoryBot.attributes_for(:error_template)}
|
patch :update, params: {id: error_template, error_template: attributes_for(:error_template)}
|
||||||
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
|
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe EventsController do
|
describe EventsController do
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ExecutionEnvironmentsController do
|
describe ExecutionEnvironmentsController do
|
||||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
let(:execution_environment) { create(:ruby) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(controller).to receive(:current_user).and_return(user)
|
allow(controller).to receive(:current_user).and_return(user)
|
||||||
@ -13,7 +13,7 @@ describe ExecutionEnvironmentsController do
|
|||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context 'with a valid execution environment' do
|
context 'with a valid execution environment' do
|
||||||
let(:perform_request) { proc { post :create, params: {execution_environment: FactoryBot.build(:ruby, pool_size: 1).attributes} } }
|
let(:perform_request) { proc { post :create, params: {execution_environment: build(:ruby, pool_size: 1).attributes} } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(Rails.env).to receive(:test?).and_return(false, true)
|
allow(Rails.env).to receive(:test?).and_return(false, true)
|
||||||
@ -64,7 +64,7 @@ describe ExecutionEnvironmentsController do
|
|||||||
expect_assigns(execution_environment: :execution_environment)
|
expect_assigns(execution_environment: :execution_environment)
|
||||||
|
|
||||||
it 'destroys the execution environment' do
|
it 'destroys the execution environment' do
|
||||||
execution_environment = FactoryBot.create(:ruby)
|
execution_environment = create(:ruby)
|
||||||
expect { delete :destroy, params: {id: execution_environment.id} }.to change(ExecutionEnvironment, :count).by(-1)
|
expect { delete :destroy, params: {id: execution_environment.id} }.to change(ExecutionEnvironment, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ describe ExecutionEnvironmentsController do
|
|||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
before do
|
before do
|
||||||
FactoryBot.create_pair(:ruby)
|
create_pair(:ruby)
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ describe ExecutionEnvironmentsController do
|
|||||||
runner = instance_double 'runner'
|
runner = instance_double 'runner'
|
||||||
allow(Runner).to receive(:for).and_return(runner)
|
allow(Runner).to receive(:for).and_return(runner)
|
||||||
allow(runner).to receive(:execute_command).and_return({})
|
allow(runner).to receive(:execute_command).and_return({})
|
||||||
put :update, params: {execution_environment: FactoryBot.attributes_for(:ruby, pool_size: 1), id: execution_environment.id}
|
put :update, params: {execution_environment: attributes_for(:ruby, pool_size: 1), id: execution_environment.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
expect_assigns(docker_images: Array)
|
expect_assigns(docker_images: Array)
|
||||||
@ -216,8 +216,8 @@ describe ExecutionEnvironmentsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#sync_all_to_runner_management' do
|
describe '#sync_all_to_runner_management' do
|
||||||
let(:execution_environments) { %i[ruby java python].map {|environment| FactoryBot.create(environment) } }
|
let(:execution_environments) { %i[ruby java python].map {|environment| create(environment) } }
|
||||||
let(:outdated_execution_environments) { %i[node_js html].map {|environment| FactoryBot.build_stubbed(environment) } }
|
let(:outdated_execution_environments) { %i[node_js html].map {|environment| build_stubbed(environment) } }
|
||||||
|
|
||||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
||||||
let(:runner_management_config) { {runner_management: {enabled: true, strategy: :poseidon}} }
|
let(:runner_management_config) { {runner_management: {enabled: true, strategy: :poseidon}} }
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ExercisesController do
|
describe ExercisesController do
|
||||||
let(:exercise) { FactoryBot.create(:dummy) }
|
let(:exercise) { create(:dummy) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ describe ExercisesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
|
let(:exercise_attributes) { build(:dummy).attributes }
|
||||||
|
|
||||||
context 'with a valid exercise' do
|
context 'with a valid exercise' do
|
||||||
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes} } }
|
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes} } }
|
||||||
@ -76,7 +76,7 @@ describe ExercisesController do
|
|||||||
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes.merge(files_attributes: files_attributes)} } }
|
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes.merge(files_attributes: files_attributes)} } }
|
||||||
|
|
||||||
context 'when specifying the file content within the form' do
|
context 'when specifying the file content within the form' do
|
||||||
let(:files_attributes) { {'0' => FactoryBot.build(:file).attributes} }
|
let(:files_attributes) { {'0' => build(:file).attributes} }
|
||||||
|
|
||||||
it 'creates the file' do
|
it 'creates the file' do
|
||||||
expect { perform_request.call }.to change(CodeOcean::File, :count)
|
expect { perform_request.call }.to change(CodeOcean::File, :count)
|
||||||
@ -84,11 +84,11 @@ describe ExercisesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when uploading a file' do
|
context 'when uploading a file' do
|
||||||
let(:files_attributes) { {'0' => FactoryBot.build(:file, file_type: file_type).attributes.merge(content: uploaded_file)} }
|
let(:files_attributes) { {'0' => build(:file, file_type: file_type).attributes.merge(content: uploaded_file)} }
|
||||||
|
|
||||||
context 'when uploading a binary file' do
|
context 'when uploading a binary file' do
|
||||||
let(:file_path) { Rails.root.join('db/seeds/audio_video/devstories.mp4') }
|
let(:file_path) { Rails.root.join('db/seeds/audio_video/devstories.mp4') }
|
||||||
let(:file_type) { FactoryBot.create(:dot_mp4) }
|
let(:file_type) { create(:dot_mp4) }
|
||||||
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'video/mp4', true) }
|
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'video/mp4', true) }
|
||||||
|
|
||||||
it 'creates the file' do
|
it 'creates the file' do
|
||||||
@ -103,7 +103,7 @@ describe ExercisesController do
|
|||||||
|
|
||||||
context 'when uploading a non-binary file' do
|
context 'when uploading a non-binary file' do
|
||||||
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
|
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
|
||||||
let(:file_type) { FactoryBot.create(:dot_rb) }
|
let(:file_type) { create(:dot_rb) }
|
||||||
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'text/x-ruby', false) }
|
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'text/x-ruby', false) }
|
||||||
|
|
||||||
it 'creates the file' do
|
it 'creates the file' do
|
||||||
@ -133,7 +133,7 @@ describe ExercisesController do
|
|||||||
expect_assigns(exercise: :exercise)
|
expect_assigns(exercise: :exercise)
|
||||||
|
|
||||||
it 'destroys the exercise' do
|
it 'destroys the exercise' do
|
||||||
exercise = FactoryBot.create(:dummy)
|
exercise = create(:dummy)
|
||||||
expect { delete :destroy, params: {id: exercise.id} }.to change(Exercise, :count).by(-1)
|
expect { delete :destroy, params: {id: exercise.id} }.to change(Exercise, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -152,14 +152,14 @@ describe ExercisesController do
|
|||||||
let(:perform_request) { proc { get :implement, params: {id: exercise.id} } }
|
let(:perform_request) { proc { get :implement, params: {id: exercise.id} } }
|
||||||
|
|
||||||
context 'with an exercise with visible files' do
|
context 'with an exercise with visible files' do
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
|
|
||||||
before { perform_request.call }
|
before { perform_request.call }
|
||||||
|
|
||||||
expect_assigns(exercise: :exercise)
|
expect_assigns(exercise: :exercise)
|
||||||
|
|
||||||
context 'with an existing submission' do
|
context 'with an existing submission' do
|
||||||
let!(:submission) { FactoryBot.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
|
let!(:submission) { create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
|
||||||
|
|
||||||
it "populates the editors with the submission's files' content" do
|
it "populates the editors with the submission's files' content" do
|
||||||
perform_request.call
|
perform_request.call
|
||||||
@ -190,7 +190,7 @@ describe ExercisesController do
|
|||||||
let(:scope) { Pundit.policy_scope!(user, Exercise) }
|
let(:scope) { Pundit.policy_scope!(user, Exercise) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
FactoryBot.create_pair(:dummy)
|
create_pair(:dummy)
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ describe ExercisesController do
|
|||||||
describe 'POST #submit' do
|
describe 'POST #submit' do
|
||||||
let(:output) { {} }
|
let(:output) { {} }
|
||||||
let(:perform_request) { post :submit, format: :json, params: {id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id}} }
|
let(:perform_request) { post :submit, format: :json, params: {id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id}} }
|
||||||
let(:user) { FactoryBot.create(:external_user) }
|
let(:user) { create(:external_user) }
|
||||||
let(:scoring_response) do
|
let(:scoring_response) do
|
||||||
[{
|
[{
|
||||||
status: :ok,
|
status: :ok,
|
||||||
@ -260,8 +260,8 @@ describe ExercisesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
FactoryBot.create(:lti_parameter, external_user: user, exercise: exercise)
|
create(:lti_parameter, external_user: user, exercise: exercise)
|
||||||
submission = FactoryBot.build(:submission, exercise: exercise, user: user)
|
submission = build(:submission, exercise: exercise, user: user)
|
||||||
allow(submission).to receive(:normalized_score).and_return(1)
|
allow(submission).to receive(:normalized_score).and_return(1)
|
||||||
allow(submission).to receive(:calculate_score).and_return(scoring_response)
|
allow(submission).to receive(:calculate_score).and_return(scoring_response)
|
||||||
allow(Submission).to receive(:create).and_return(submission)
|
allow(Submission).to receive(:create).and_return(submission)
|
||||||
@ -328,7 +328,7 @@ describe ExercisesController do
|
|||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
context 'with a valid exercise' do
|
context 'with a valid exercise' do
|
||||||
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
|
let(:exercise_attributes) { build(:dummy).attributes }
|
||||||
|
|
||||||
before { put :update, params: {exercise: exercise_attributes, id: exercise.id} }
|
before { put :update, params: {exercise: exercise_attributes, id: exercise.id} }
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ describe ExercisesController do
|
|||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:post_request) { post :export_external_check, params: {id: exercise.id} }
|
let(:post_request) { post :export_external_check, params: {id: exercise.id} }
|
||||||
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
let(:external_check_hash) { {message: message, exercise_found: true, update_right: update_right, error: error} }
|
let(:external_check_hash) { {message: message, exercise_found: true, update_right: update_right, error: error} }
|
||||||
let(:message) { 'message' }
|
let(:message) { 'message' }
|
||||||
let(:update_right) { true }
|
let(:update_right) { true }
|
||||||
@ -405,7 +405,7 @@ describe ExercisesController do
|
|||||||
describe '#export_external_confirm' do
|
describe '#export_external_confirm' do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
let(:post_request) { post :export_external_confirm, params: {id: exercise.id, codeharbor_link: codeharbor_link.id} }
|
let(:post_request) { post :export_external_confirm, params: {id: exercise.id, codeharbor_link: codeharbor_link.id} }
|
||||||
let(:error) { nil }
|
let(:error) { nil }
|
||||||
let(:zip) { 'zip' }
|
let(:zip) { 'zip' }
|
||||||
@ -440,8 +440,8 @@ describe ExercisesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#import_uuid_check' do
|
describe '#import_uuid_check' do
|
||||||
let(:exercise) { FactoryBot.create(:dummy, uuid: SecureRandom.uuid) }
|
let(:exercise) { create(:dummy, uuid: SecureRandom.uuid) }
|
||||||
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
let(:uuid) { exercise.reload.uuid }
|
let(:uuid) { exercise.reload.uuid }
|
||||||
let(:post_request) { post :import_uuid_check, params: {uuid: uuid} }
|
let(:post_request) { post :import_uuid_check, params: {uuid: uuid} }
|
||||||
let(:headers) { {'Authorization' => "Bearer #{codeharbor_link.api_key}"} }
|
let(:headers) { {'Authorization' => "Bearer #{codeharbor_link.api_key}"} }
|
||||||
@ -466,7 +466,7 @@ describe ExercisesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when the user cannot update the exercise' do
|
context 'when the user cannot update the exercise' do
|
||||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, api_key: 'anotherkey') }
|
let(:codeharbor_link) { create(:codeharbor_link, api_key: 'anotherkey') }
|
||||||
|
|
||||||
it 'renders correct response' do
|
it 'renders correct response' do
|
||||||
post_request
|
post_request
|
||||||
@ -490,8 +490,8 @@ describe ExercisesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #import_exercise' do
|
describe 'POST #import_exercise' do
|
||||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
let(:codeharbor_link) { create(:codeharbor_link, user: user) }
|
||||||
let!(:imported_exercise) { FactoryBot.create(:fibonacci) }
|
let!(:imported_exercise) { create(:fibonacci) }
|
||||||
let(:post_request) { post :import_exercise, body: zip_file_content }
|
let(:post_request) { post :import_exercise, body: zip_file_content }
|
||||||
let(:zip_file_content) { 'zipped task xml' }
|
let(:zip_file_content) { 'zipped task xml' }
|
||||||
let(:headers) { {'Authorization' => "Bearer #{codeharbor_link.api_key}"} }
|
let(:headers) { {'Authorization' => "Bearer #{codeharbor_link.api_key}"} }
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ExternalUsersController do
|
describe ExternalUsersController do
|
||||||
let(:user) { FactoryBot.build(:admin) }
|
let(:user) { build(:admin) }
|
||||||
let!(:users) { FactoryBot.create_pair(:external_user) }
|
let!(:users) { create_pair(:external_user) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe FileTypesController do
|
describe FileTypesController do
|
||||||
let(:file_type) { FactoryBot.create(:dot_rb) }
|
let(:file_type) { create(:dot_rb) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context 'with a valid file type' do
|
context 'with a valid file type' do
|
||||||
let(:perform_request) { proc { post :create, params: {file_type: FactoryBot.attributes_for(:dot_rb)} } }
|
let(:perform_request) { proc { post :create, params: {file_type: attributes_for(:dot_rb)} } }
|
||||||
|
|
||||||
before { perform_request.call }
|
before { perform_request.call }
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ describe FileTypesController do
|
|||||||
expect_assigns(file_type: FileType)
|
expect_assigns(file_type: FileType)
|
||||||
|
|
||||||
it 'destroys the file type' do
|
it 'destroys the file type' do
|
||||||
file_type = FactoryBot.create(:dot_rb)
|
file_type = create(:dot_rb)
|
||||||
expect { delete :destroy, params: {id: file_type.id} }.to change(FileType, :count).by(-1)
|
expect { delete :destroy, params: {id: file_type.id} }.to change(FileType, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ describe FileTypesController do
|
|||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
before do
|
before do
|
||||||
FactoryBot.create_pair(:dot_rb)
|
create_pair(:dot_rb)
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ describe FileTypesController do
|
|||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
context 'with a valid file type' do
|
context 'with a valid file type' do
|
||||||
before { put :update, params: {file_type: FactoryBot.attributes_for(:dot_rb), id: file_type.id} }
|
before { put :update, params: {file_type: attributes_for(:dot_rb), id: file_type.id} }
|
||||||
|
|
||||||
expect_assigns(editor_modes: Array)
|
expect_assigns(editor_modes: Array)
|
||||||
expect_assigns(file_type: FileType)
|
expect_assigns(file_type: FileType)
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe InternalUsersController do
|
describe InternalUsersController do
|
||||||
let(:user) { FactoryBot.build(:admin) }
|
let(:user) { build(:admin) }
|
||||||
let!(:users) { FactoryBot.create_pair(:teacher) }
|
let!(:users) { create_pair(:teacher) }
|
||||||
|
|
||||||
describe 'GET #activate' do
|
describe 'GET #activate' do
|
||||||
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
|
let(:user) { InternalUser.create(attributes_for(:teacher)) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
user.send(:setup_activation)
|
user.send(:setup_activation)
|
||||||
@ -39,7 +39,7 @@ describe InternalUsersController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #activate' do
|
describe 'PUT #activate' do
|
||||||
let(:user) { InternalUser.create(FactoryBot.build(:teacher).attributes) }
|
let(:user) { InternalUser.create(build(:teacher).attributes) }
|
||||||
let(:password) { SecureRandom.hex }
|
let(:password) { SecureRandom.hex }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@ -108,7 +108,7 @@ describe InternalUsersController do
|
|||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
context 'with a valid internal user' do
|
context 'with a valid internal user' do
|
||||||
let(:perform_request) { proc { post :create, params: {internal_user: FactoryBot.build(:teacher).attributes} } }
|
let(:perform_request) { proc { post :create, params: {internal_user: build(:teacher).attributes} } }
|
||||||
|
|
||||||
before { perform_request.call }
|
before { perform_request.call }
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ describe InternalUsersController do
|
|||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
context 'with a valid internal user' do
|
context 'with a valid internal user' do
|
||||||
before { put :update, params: {internal_user: FactoryBot.attributes_for(:teacher), id: users.first.id} }
|
before { put :update, params: {internal_user: attributes_for(:teacher), id: users.first.id} }
|
||||||
|
|
||||||
expect_assigns(user: InternalUser)
|
expect_assigns(user: InternalUser)
|
||||||
expect_redirect { user }
|
expect_redirect { user }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RequestForCommentsController do
|
describe RequestForCommentsController do
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -16,13 +16,13 @@ describe RequestForCommentsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'shows only rfc`s belonging to selected study group' do
|
it 'shows only rfc`s belonging to selected study group' do
|
||||||
my_study_group = FactoryBot.create(:study_group)
|
my_study_group = create(:study_group)
|
||||||
rfc_within_my_study_group = FactoryBot.create(:rfc, user: user)
|
rfc_within_my_study_group = create(:rfc, user: user)
|
||||||
user.update(study_groups: [my_study_group])
|
user.update(study_groups: [my_study_group])
|
||||||
rfc_within_my_study_group.submission.update(study_group: my_study_group)
|
rfc_within_my_study_group.submission.update(study_group: my_study_group)
|
||||||
|
|
||||||
another_study_group = FactoryBot.create(:study_group)
|
another_study_group = create(:study_group)
|
||||||
rfc_other_study_group = FactoryBot.create(:rfc)
|
rfc_other_study_group = create(:rfc)
|
||||||
rfc_other_study_group.user.update(study_groups: [another_study_group])
|
rfc_other_study_group.user.update(study_groups: [another_study_group])
|
||||||
rfc_other_study_group.submission.update(study_group: another_study_group)
|
rfc_other_study_group.submission.update(study_group: another_study_group)
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ describe RequestForCommentsController do
|
|||||||
|
|
||||||
describe 'GET #rfcs_for_exercise' do
|
describe 'GET #rfcs_for_exercise' do
|
||||||
before do
|
before do
|
||||||
exercise = FactoryBot.create(:even_odd)
|
exercise = create(:even_odd)
|
||||||
get :rfcs_for_exercise, params: {exercise_id: exercise.id}
|
get :rfcs_for_exercise, params: {exercise_id: exercise.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe SessionsController do
|
describe SessionsController do
|
||||||
let(:consumer) { FactoryBot.create(:consumer) }
|
let(:consumer) { create(:consumer) }
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
let(:password) { FactoryBot.attributes_for(:teacher)[:password] }
|
let(:password) { attributes_for(:teacher)[:password] }
|
||||||
let(:user) { InternalUser.create(user_attributes.merge(password: password)) }
|
let(:user) { InternalUser.create(user_attributes.merge(password: password)) }
|
||||||
let(:user_attributes) { FactoryBot.build(:teacher).attributes }
|
let(:user_attributes) { build(:teacher).attributes }
|
||||||
|
|
||||||
context 'with valid credentials' do
|
context 'with valid credentials' do
|
||||||
before do
|
before do
|
||||||
@ -29,8 +29,8 @@ describe SessionsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create_through_lti' do
|
describe 'POST #create_through_lti' do
|
||||||
let(:exercise) { FactoryBot.create(:dummy) }
|
let(:exercise) { create(:dummy) }
|
||||||
let(:exercise2) { FactoryBot.create(:dummy) }
|
let(:exercise2) { create(:dummy) }
|
||||||
let(:nonce) { SecureRandom.hex }
|
let(:nonce) { SecureRandom.hex }
|
||||||
|
|
||||||
context 'without OAuth parameters' do
|
context 'without OAuth parameters' do
|
||||||
@ -74,7 +74,7 @@ describe SessionsController do
|
|||||||
context 'with valid launch parameters' do
|
context 'with valid launch parameters' do
|
||||||
let(:locale) { :de }
|
let(:locale) { :de }
|
||||||
let(:perform_request) { post :create_through_lti, params: {custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id} }
|
let(:perform_request) { post :create_through_lti, params: {custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id} }
|
||||||
let(:user) { FactoryBot.create(:external_user, consumer_id: consumer.id) }
|
let(:user) { create(:external_user, consumer_id: consumer.id) }
|
||||||
|
|
||||||
before { allow_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
|
before { allow_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
|
||||||
|
|
||||||
@ -139,14 +139,14 @@ describe SessionsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to recommended exercise if requested token of proxy exercise' do
|
it 'redirects to recommended exercise if requested token of proxy exercise' do
|
||||||
FactoryBot.create(:proxy_exercise, exercises: [exercise])
|
create(:proxy_exercise, exercises: [exercise])
|
||||||
post :create_through_lti, params: {custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id}
|
post :create_through_lti, params: {custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id}
|
||||||
expect(controller).to redirect_to(implement_exercise_path(exercise.id))
|
expect(controller).to redirect_to(implement_exercise_path(exercise.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'recommends only exercises who are 1 degree more complicated than what user has seen' do
|
it 'recommends only exercises who are 1 degree more complicated than what user has seen' do
|
||||||
# dummy user has no exercises finished, therefore his highest difficulty is 0
|
# dummy user has no exercises finished, therefore his highest difficulty is 0
|
||||||
FactoryBot.create(:proxy_exercise, exercises: [exercise, exercise2])
|
create(:proxy_exercise, exercises: [exercise, exercise2])
|
||||||
exercise.expected_difficulty = 3
|
exercise.expected_difficulty = 3
|
||||||
exercise.save
|
exercise.save
|
||||||
exercise2.expected_difficulty = 1
|
exercise2.expected_difficulty = 1
|
||||||
@ -202,7 +202,7 @@ describe SessionsController do
|
|||||||
|
|
||||||
describe 'GET #destroy_through_lti' do
|
describe 'GET #destroy_through_lti' do
|
||||||
let(:perform_request) { proc { get :destroy_through_lti, params: {consumer_id: consumer.id, submission_id: submission.id} } }
|
let(:perform_request) { proc { get :destroy_through_lti, params: {consumer_id: consumer.id, submission_id: submission.id} } }
|
||||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) }
|
let(:submission) { create(:submission, exercise: create(:dummy)) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
# Todo replace session with lti_parameter
|
# Todo replace session with lti_parameter
|
||||||
@ -238,7 +238,7 @@ describe SessionsController do
|
|||||||
before do
|
before do
|
||||||
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
||||||
|
|
||||||
allow(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher))
|
allow(controller).to receive(:current_user).and_return(build(:teacher))
|
||||||
get :new
|
get :new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe StatisticsController do
|
describe StatisticsController do
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe SubmissionsController do
|
describe SubmissionsController do
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ describe SubmissionsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a valid submission' do
|
context 'with a valid submission' do
|
||||||
let(:exercise) { FactoryBot.create(:hello_world) }
|
let(:exercise) { create(:hello_world) }
|
||||||
let(:perform_request) { proc { post :create, format: :json, params: {submission: FactoryBot.attributes_for(:submission, exercise_id: exercise.id)} } }
|
let(:perform_request) { proc { post :create, format: :json, params: {submission: attributes_for(:submission, exercise_id: exercise.id)} } }
|
||||||
|
|
||||||
before { perform_request.call }
|
before { perform_request.call }
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ describe SubmissionsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a valid binary filename' do
|
context 'with a valid binary filename' do
|
||||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:sql_select)) }
|
let(:submission) { create(:submission, exercise: create(:sql_select)) }
|
||||||
|
|
||||||
before { get :download_file, params: {filename: file.name_with_extension, id: submission.id} }
|
before { get :download_file, params: {filename: file.name_with_extension, id: submission.id} }
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ describe SubmissionsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a valid filename' do
|
context 'with a valid filename' do
|
||||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
|
let(:submission) { create(:submission, exercise: create(:audio_video)) }
|
||||||
|
|
||||||
before { get :download_file, params: {filename: file.name_with_extension, id: submission.id} }
|
before { get :download_file, params: {filename: file.name_with_extension, id: submission.id} }
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ describe SubmissionsController do
|
|||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
before do
|
before do
|
||||||
FactoryBot.create_pair(:submission)
|
create_pair(:submission)
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ describe SubmissionsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a valid filename' do
|
context 'with a valid filename' do
|
||||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
|
let(:submission) { create(:submission, exercise: create(:audio_video)) }
|
||||||
|
|
||||||
before { get :render_file, params: {filename: file.name_with_extension, id: submission.id} }
|
before { get :render_file, params: {filename: file.name_with_extension, id: submission.id} }
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'Authentication' do
|
describe 'Authentication' do
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
let(:password) { FactoryBot.attributes_for(:admin)[:password] }
|
let(:password) { attributes_for(:admin)[:password] }
|
||||||
|
|
||||||
context 'when signed out' do
|
context 'when signed out' do
|
||||||
before { visit(root_path) }
|
before { visit(root_path) }
|
||||||
|
@ -6,7 +6,7 @@ describe 'Authorization' do
|
|||||||
before { allow(Runner.strategy_class).to receive(:available_images).and_return([]) }
|
before { allow(Runner.strategy_class).to receive(:available_images).and_return([]) }
|
||||||
|
|
||||||
context 'when being an admin' do
|
context 'when being an admin' do
|
||||||
let(:user) { FactoryBot.create(:admin) }
|
let(:user) { create(:admin) }
|
||||||
|
|
||||||
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ describe 'Authorization' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with being an external user' do
|
context 'with being an external user' do
|
||||||
let(:user) { FactoryBot.create(:external_user) }
|
let(:user) { create(:external_user) }
|
||||||
|
|
||||||
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ describe 'Authorization' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with being a teacher' do
|
context 'with being a teacher' do
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'Editor', js: true do
|
describe 'Editor', js: true do
|
||||||
let(:exercise) { FactoryBot.create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
let(:exercise) { create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
||||||
let(:scoring_response) do
|
let(:scoring_response) do
|
||||||
[{
|
[{
|
||||||
status: :ok,
|
status: :ok,
|
||||||
@ -22,12 +22,12 @@ describe 'Editor', js: true do
|
|||||||
weight: 2.0,
|
weight: 2.0,
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
visit(sign_in_path)
|
visit(sign_in_path)
|
||||||
fill_in('email', with: user.email)
|
fill_in('email', with: user.email)
|
||||||
fill_in('password', with: FactoryBot.attributes_for(:teacher)[:password])
|
fill_in('password', with: attributes_for(:teacher)[:password])
|
||||||
click_button(I18n.t('sessions.new.link'))
|
click_button(I18n.t('sessions.new.link'))
|
||||||
allow_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(true)
|
allow_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(true)
|
||||||
visit(implement_exercise_path(exercise))
|
visit(implement_exercise_path(exercise))
|
||||||
@ -94,7 +94,7 @@ describe 'Editor', js: true do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'contains a button for submitting the exercise' do
|
it 'contains a button for submitting the exercise' do
|
||||||
submission = FactoryBot.build(:submission, user: user, exercise: exercise)
|
submission = build(:submission, user: user, exercise: exercise)
|
||||||
allow(submission).to receive(:calculate_score).and_return(scoring_response)
|
allow(submission).to receive(:calculate_score).and_return(scoring_response)
|
||||||
allow(Submission).to receive(:find).and_return(submission)
|
allow(Submission).to receive(:find).and_return(submission)
|
||||||
click_button(I18n.t('exercises.editor.score'))
|
click_button(I18n.t('exercises.editor.score'))
|
||||||
|
@ -26,7 +26,7 @@ describe Prometheus::Controller do
|
|||||||
|
|
||||||
describe 'instance count' do
|
describe 'instance count' do
|
||||||
it 'initializes the metrics with the current database entries' do
|
it 'initializes the metrics with the current database entries' do
|
||||||
FactoryBot.create_list(:proxy_exercise, 3)
|
create_list(:proxy_exercise, 3)
|
||||||
described_class.register_metrics
|
described_class.register_metrics
|
||||||
stub_metrics
|
stub_metrics
|
||||||
described_class.initialize_instance_count
|
described_class.initialize_instance_count
|
||||||
@ -35,25 +35,25 @@ describe Prometheus::Controller do
|
|||||||
|
|
||||||
it 'gets notified when an object is created' do
|
it 'gets notified when an object is created' do
|
||||||
allow(described_class).to receive(:create_notification)
|
allow(described_class).to receive(:create_notification)
|
||||||
proxy_exercise = FactoryBot.create(:proxy_exercise)
|
proxy_exercise = create(:proxy_exercise)
|
||||||
expect(described_class).to have_received(:create_notification).with(proxy_exercise).once
|
expect(described_class).to have_received(:create_notification).with(proxy_exercise).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'gets notified when an object is destroyed' do
|
it 'gets notified when an object is destroyed' do
|
||||||
allow(described_class).to receive(:destroy_notification)
|
allow(described_class).to receive(:destroy_notification)
|
||||||
proxy_exercise = FactoryBot.create(:proxy_exercise).destroy
|
proxy_exercise = create(:proxy_exercise).destroy
|
||||||
expect(described_class).to have_received(:destroy_notification).with(proxy_exercise).once
|
expect(described_class).to have_received(:destroy_notification).with(proxy_exercise).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'increments gauge when creating a new instance' do
|
it 'increments gauge when creating a new instance' do
|
||||||
FactoryBot.create(:proxy_exercise)
|
create(:proxy_exercise)
|
||||||
expect(described_class.instance_variable_get(:@instance_count)).to(
|
expect(described_class.instance_variable_get(:@instance_count)).to(
|
||||||
have_received(:increment).with(class: ProxyExercise.name).once
|
have_received(:increment).with(class: ProxyExercise.name).once
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'decrements gauge when deleting an object' do
|
it 'decrements gauge when deleting an object' do
|
||||||
FactoryBot.create(:proxy_exercise).destroy
|
create(:proxy_exercise).destroy
|
||||||
expect(described_class.instance_variable_get(:@instance_count)).to(
|
expect(described_class.instance_variable_get(:@instance_count)).to(
|
||||||
have_received(:decrement).with(class: ProxyExercise.name).once
|
have_received(:decrement).with(class: ProxyExercise.name).once
|
||||||
)
|
)
|
||||||
@ -63,7 +63,7 @@ describe Prometheus::Controller do
|
|||||||
describe 'rfc count' do
|
describe 'rfc count' do
|
||||||
context 'when initializing an rfc' do
|
context 'when initializing an rfc' do
|
||||||
it 'updates rfc count when creating an ongoing rfc' do
|
it 'updates rfc count when creating an ongoing rfc' do
|
||||||
FactoryBot.create(:rfc)
|
create(:rfc)
|
||||||
expect(described_class.instance_variable_get(:@rfc_count)).to(
|
expect(described_class.instance_variable_get(:@rfc_count)).to(
|
||||||
have_received(:increment).with(state: RequestForComment::ONGOING).once
|
have_received(:increment).with(state: RequestForComment::ONGOING).once
|
||||||
)
|
)
|
||||||
@ -71,7 +71,7 @@ describe Prometheus::Controller do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when changing the state of an rfc' do
|
context 'when changing the state of an rfc' do
|
||||||
let(:rfc) { FactoryBot.create(:rfc) }
|
let(:rfc) { create(:rfc) }
|
||||||
|
|
||||||
it 'updates rfc count when soft-solving an rfc' do
|
it 'updates rfc count when soft-solving an rfc' do
|
||||||
rfc.full_score_reached = true
|
rfc.full_score_reached = true
|
||||||
@ -90,12 +90,12 @@ describe Prometheus::Controller do
|
|||||||
|
|
||||||
context 'when commenting an rfc' do
|
context 'when commenting an rfc' do
|
||||||
it 'updates comment metric when commenting an rfc' do
|
it 'updates comment metric when commenting an rfc' do
|
||||||
FactoryBot.create(:rfc_with_comment)
|
create(:rfc_with_comment)
|
||||||
expect(described_class.instance_variable_get(:@rfc_commented_count)).to have_received(:increment).once
|
expect(described_class.instance_variable_get(:@rfc_commented_count)).to have_received(:increment).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not update comment metric when commenting an rfc that already has a comment' do
|
it 'does not update comment metric when commenting an rfc that already has a comment' do
|
||||||
rfc = FactoryBot.create(:rfc_with_comment)
|
rfc = create(:rfc_with_comment)
|
||||||
expect(described_class.instance_variable_get(:@rfc_commented_count)).to have_received(:increment).once
|
expect(described_class.instance_variable_get(:@rfc_commented_count)).to have_received(:increment).once
|
||||||
|
|
||||||
Comment.create(file: rfc.file, user: rfc.user, text: "comment a for rfc #{rfc.question}")
|
Comment.create(file: rfc.file, user: rfc.user, text: "comment a for rfc #{rfc.question}")
|
||||||
|
@ -3,21 +3,21 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'Request_for_Comments' do
|
describe 'Request_for_Comments' do
|
||||||
let(:exercise) { FactoryBot.create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
let(:exercise) { create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
visit(sign_in_path)
|
visit(sign_in_path)
|
||||||
fill_in('email', with: user.email)
|
fill_in('email', with: user.email)
|
||||||
fill_in('password', with: FactoryBot.attributes_for(:teacher)[:password])
|
fill_in('password', with: attributes_for(:teacher)[:password])
|
||||||
click_button(I18n.t('sessions.new.link'))
|
click_button(I18n.t('sessions.new.link'))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not contain rfcs for unpublished exercises' do
|
it 'does not contain rfcs for unpublished exercises' do
|
||||||
unpublished_rfc = FactoryBot.create(:rfc)
|
unpublished_rfc = create(:rfc)
|
||||||
unpublished_rfc.exercise.update(title: 'Unpublished Exercise')
|
unpublished_rfc.exercise.update(title: 'Unpublished Exercise')
|
||||||
unpublished_rfc.exercise.update(unpublished: true)
|
unpublished_rfc.exercise.update(unpublished: true)
|
||||||
rfc = FactoryBot.create(:rfc)
|
rfc = create(:rfc)
|
||||||
rfc.exercise.update(title: 'Normal Exercise')
|
rfc.exercise.update(title: 'Normal Exercise')
|
||||||
rfc.exercise.update(unpublished: false)
|
rfc.exercise.update(unpublished: false)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ describe Admin::DashboardHelper do
|
|||||||
|
|
||||||
describe '#docker_data' do
|
describe '#docker_data' do
|
||||||
before do
|
before do
|
||||||
FactoryBot.create(:ruby)
|
create(:ruby)
|
||||||
dcp = instance_double 'docker_container_pool'
|
dcp = instance_double 'docker_container_pool'
|
||||||
allow(Runner).to receive(:strategy_class).and_return dcp
|
allow(Runner).to receive(:strategy_class).and_return dcp
|
||||||
allow(dcp).to receive(:pool_size).and_return({})
|
allow(dcp).to receive(:pool_size).and_return({})
|
||||||
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||||||
|
|
||||||
describe ExerciseHelper do
|
describe ExerciseHelper do
|
||||||
describe '#embedding_parameters' do
|
describe '#embedding_parameters' do
|
||||||
let(:exercise) { FactoryBot.build(:dummy) }
|
let(:exercise) { build(:dummy) }
|
||||||
|
|
||||||
it 'contains the locale' do
|
it 'contains the locale' do
|
||||||
expect(embedding_parameters(exercise)).to start_with("locale=#{I18n.locale}")
|
expect(embedding_parameters(exercise)).to start_with("locale=#{I18n.locale}")
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Assessor do
|
describe Assessor do
|
||||||
let(:assessor) { described_class.new(execution_environment: FactoryBot.build(:ruby)) }
|
let(:assessor) { described_class.new(execution_environment: build(:ruby)) }
|
||||||
|
|
||||||
describe '#assess' do
|
describe '#assess' do
|
||||||
let(:assess) { assessor.assess(stdout: stdout) }
|
let(:assess) { assessor.assess(stdout: stdout) }
|
||||||
@ -55,7 +55,7 @@ describe Assessor do
|
|||||||
|
|
||||||
context 'with an execution environment without a testing framework adapter' do
|
context 'with an execution environment without a testing framework adapter' do
|
||||||
it 'raises an error' do
|
it 'raises an error' do
|
||||||
expect { described_class.new(execution_environment: FactoryBot.build(:ruby, testing_framework: nil)) }.to raise_error(Assessor::Error)
|
expect { described_class.new(execution_environment: build(:ruby, testing_framework: nil)) }.to raise_error(Assessor::Error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,14 +7,14 @@ WORKSPACE_PATH = Rails.root.join('tmp', 'files', Rails.env, 'code_ocean_test')
|
|||||||
|
|
||||||
describe DockerClient do
|
describe DockerClient do
|
||||||
let(:command) { 'whoami' }
|
let(:command) { 'whoami' }
|
||||||
let(:docker_client) { described_class.new(execution_environment: FactoryBot.build(:java), user: FactoryBot.build(:admin)) }
|
let(:docker_client) { described_class.new(execution_environment: build(:java), user: build(:admin)) }
|
||||||
let(:execution_environment) { FactoryBot.build(:java) }
|
let(:execution_environment) { build(:java) }
|
||||||
let(:image) { double }
|
let(:image) { double }
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
let(:workspace_path) { WORKSPACE_PATH }
|
let(:workspace_path) { WORKSPACE_PATH }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
docker_image = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex, 'RepoTags' => [FactoryBot.attributes_for(:java)[:docker_image]])
|
docker_image = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex, 'RepoTags' => [attributes_for(:java)[:docker_image]])
|
||||||
allow(described_class).to receive(:find_image_by_tag).and_return(docker_image)
|
allow(described_class).to receive(:find_image_by_tag).and_return(docker_image)
|
||||||
described_class.initialize_environment
|
described_class.initialize_environment
|
||||||
allow(described_class).to receive(:container_creation_options).and_wrap_original do |original_method, *args, &block|
|
allow(described_class).to receive(:container_creation_options).and_wrap_original do |original_method, *args, &block|
|
||||||
@ -177,7 +177,7 @@ describe DockerClient do
|
|||||||
|
|
||||||
describe '#create_workspace_file' do
|
describe '#create_workspace_file' do
|
||||||
let(:container) { Docker::Container.send(:new, Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex) }
|
let(:container) { Docker::Container.send(:new, Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex) }
|
||||||
let(:file) { FactoryBot.build(:file, content: 'puts 42') }
|
let(:file) { build(:file, content: 'puts 42') }
|
||||||
let(:file_path) { File.join(workspace_path, file.name_with_extension) }
|
let(:file_path) { File.join(workspace_path, file.name_with_extension) }
|
||||||
|
|
||||||
after { File.delete(file_path) }
|
after { File.delete(file_path) }
|
||||||
|
@ -10,7 +10,7 @@ describe FileTree do
|
|||||||
|
|
||||||
context 'with a media file' do
|
context 'with a media file' do
|
||||||
context 'with an audio file' do
|
context 'with an audio file' do
|
||||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp3)) }
|
let(:file) { build(:file, file_type: build(:dot_mp3)) }
|
||||||
|
|
||||||
it 'is an audio file icon' do
|
it 'is an audio file icon' do
|
||||||
expect(file_icon).to include('fa-file-audio-o')
|
expect(file_icon).to include('fa-file-audio-o')
|
||||||
@ -18,7 +18,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with an image file' do
|
context 'with an image file' do
|
||||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_jpg)) }
|
let(:file) { build(:file, file_type: build(:dot_jpg)) }
|
||||||
|
|
||||||
it 'is an image file icon' do
|
it 'is an image file icon' do
|
||||||
expect(file_icon).to include('fa-file-image-o')
|
expect(file_icon).to include('fa-file-image-o')
|
||||||
@ -26,7 +26,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a video file' do
|
context 'with a video file' do
|
||||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp4)) }
|
let(:file) { build(:file, file_type: build(:dot_mp4)) }
|
||||||
|
|
||||||
it 'is a video file icon' do
|
it 'is a video file icon' do
|
||||||
expect(file_icon).to include('fa-file-video-o')
|
expect(file_icon).to include('fa-file-video-o')
|
||||||
@ -36,7 +36,7 @@ describe FileTree do
|
|||||||
|
|
||||||
context 'with other files' do
|
context 'with other files' do
|
||||||
context 'with a read-only file' do
|
context 'with a read-only file' do
|
||||||
let(:file) { FactoryBot.build(:file, read_only: true) }
|
let(:file) { build(:file, read_only: true) }
|
||||||
|
|
||||||
it 'is a lock icon' do
|
it 'is a lock icon' do
|
||||||
expect(file_icon).to include('fa-lock')
|
expect(file_icon).to include('fa-lock')
|
||||||
@ -44,7 +44,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with an executable file' do
|
context 'with an executable file' do
|
||||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_py)) }
|
let(:file) { build(:file, file_type: build(:dot_py)) }
|
||||||
|
|
||||||
it 'is a code file icon' do
|
it 'is a code file icon' do
|
||||||
expect(file_icon).to include('fa-file-code-o')
|
expect(file_icon).to include('fa-file-code-o')
|
||||||
@ -52,7 +52,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a renderable file' do
|
context 'with a renderable file' do
|
||||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_svg)) }
|
let(:file) { build(:file, file_type: build(:dot_svg)) }
|
||||||
|
|
||||||
it 'is a text file icon' do
|
it 'is a text file icon' do
|
||||||
expect(file_icon).to include('fa-file-text-o')
|
expect(file_icon).to include('fa-file-text-o')
|
||||||
@ -60,7 +60,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with all other files' do
|
context 'with all other files' do
|
||||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_md)) }
|
let(:file) { build(:file, file_type: build(:dot_md)) }
|
||||||
|
|
||||||
it 'is a generic file icon' do
|
it 'is a generic file icon' do
|
||||||
expect(file_icon).to include('fa-file-o')
|
expect(file_icon).to include('fa-file-o')
|
||||||
@ -77,7 +77,7 @@ describe FileTree do
|
|||||||
|
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
let(:file_tree) { described_class.new(files) }
|
let(:file_tree) { described_class.new(files) }
|
||||||
let(:files) { FactoryBot.build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||||
|
|
||||||
it 'creates a root node' do
|
it 'creates a root node' do
|
||||||
# Instead of checking #initialize on the parent, we validate #set_as_root!
|
# Instead of checking #initialize on the parent, we validate #set_as_root!
|
||||||
@ -95,7 +95,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#map_to_js_tree' do
|
describe '#map_to_js_tree' do
|
||||||
let(:file) { FactoryBot.build(:file) }
|
let(:file) { build(:file) }
|
||||||
let(:js_tree) { file_tree.send(:map_to_js_tree, node) }
|
let(:js_tree) { file_tree.send(:map_to_js_tree, node) }
|
||||||
let!(:leaf) { root.add(Tree::TreeNode.new('', file)) }
|
let!(:leaf) { root.add(Tree::TreeNode.new('', file)) }
|
||||||
let(:root) { Tree::TreeNode.new('', file) }
|
let(:root) { Tree::TreeNode.new('', file) }
|
||||||
@ -186,7 +186,7 @@ describe FileTree do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with files' do
|
context 'with files' do
|
||||||
let(:files) { FactoryBot.build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||||
let(:file_tree) { described_class.new(files) }
|
let(:file_tree) { described_class.new(files) }
|
||||||
let(:js_tree) { file_tree.to_js_tree }
|
let(:js_tree) { file_tree.to_js_tree }
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ require 'rails_helper'
|
|||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
||||||
describe Runner::Strategy::DockerContainerPool do
|
describe Runner::Strategy::DockerContainerPool do
|
||||||
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
|
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||||
let(:execution_environment) { FactoryBot.create :ruby }
|
let(:execution_environment) { create :ruby }
|
||||||
let(:container_pool) { described_class.new(runner_id, execution_environment) }
|
let(:container_pool) { described_class.new(runner_id, execution_environment) }
|
||||||
let(:docker_container_pool_url) { 'http://localhost:1234' }
|
let(:docker_container_pool_url) { 'http://localhost:1234' }
|
||||||
let(:config) { {url: docker_container_pool_url, unused_runner_expiration_time: 180} }
|
let(:config) { {url: docker_container_pool_url, unused_runner_expiration_time: 180} }
|
||||||
@ -112,22 +112,20 @@ describe Runner::Strategy::DockerContainerPool do
|
|||||||
|
|
||||||
context 'when receiving a normal file' do
|
context 'when receiving a normal file' do
|
||||||
let(:file_content) { 'print("Hello World!")' }
|
let(:file_content) { 'print("Hello World!")' }
|
||||||
let(:files) { [FactoryBot.build(:file, content: file_content)] }
|
let(:files) { [build(:file, content: file_content)] }
|
||||||
|
|
||||||
it 'writes the file to disk' do
|
it 'writes the file to disk' do
|
||||||
file = instance_double(File)
|
expect(File).to receive(:write).with(local_path.join(files.first.filepath), file_content)
|
||||||
allow(File).to receive(:open).and_yield(file)
|
|
||||||
expect(file).to receive(:write).with(file_content)
|
|
||||||
container_pool.copy_files(files)
|
container_pool.copy_files(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates the file inside the workspace' do
|
it 'creates the file inside the workspace' do
|
||||||
expect(File).to receive(:open).with(local_path.join(files.first.filepath), 'w')
|
expect(File).to receive(:write).with(local_path.join(files.first.filepath), files.first.content)
|
||||||
container_pool.copy_files(files)
|
container_pool.copy_files(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error in case of an IOError' do
|
it 'raises an error in case of an IOError' do
|
||||||
allow(File).to receive(:open).and_raise(IOError)
|
allow(File).to receive(:write).and_raise(IOError)
|
||||||
expect { container_pool.copy_files(files) }.to raise_error(Runner::Error::WorkspaceError, /#{files.first.filepath}/)
|
expect { container_pool.copy_files(files) }.to raise_error(Runner::Error::WorkspaceError, /#{files.first.filepath}/)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -137,10 +135,10 @@ describe Runner::Strategy::DockerContainerPool do
|
|||||||
|
|
||||||
context 'when the file is inside a directory' do
|
context 'when the file is inside a directory' do
|
||||||
let(:directory) { 'temp/dir' }
|
let(:directory) { 'temp/dir' }
|
||||||
let(:files) { [FactoryBot.build(:file, path: directory)] }
|
let(:files) { [build(:file, path: directory)] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(File).to receive(:open)
|
allow(File).to receive(:write)
|
||||||
allow(FileUtils).to receive(:mkdir_p).with(local_path)
|
allow(FileUtils).to receive(:mkdir_p).with(local_path)
|
||||||
allow(FileUtils).to receive(:mkdir_p).with(local_path.join(directory))
|
allow(FileUtils).to receive(:mkdir_p).with(local_path.join(directory))
|
||||||
end
|
end
|
||||||
@ -159,7 +157,7 @@ describe Runner::Strategy::DockerContainerPool do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when receiving a binary file' do
|
context 'when receiving a binary file' do
|
||||||
let(:files) { [FactoryBot.build(:file, :image)] }
|
let(:files) { [build(:file, :image)] }
|
||||||
|
|
||||||
it 'copies the file inside the workspace' do
|
it 'copies the file inside the workspace' do
|
||||||
expect(FileUtils).to receive(:cp).with(files.first.native_file.path, local_path.join(files.first.filepath))
|
expect(FileUtils).to receive(:cp).with(files.first.native_file.path, local_path.join(files.first.filepath))
|
||||||
@ -168,11 +166,11 @@ describe Runner::Strategy::DockerContainerPool do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when receiving multiple files' do
|
context 'when receiving multiple files' do
|
||||||
let(:files) { FactoryBot.build_list(:file, 3) }
|
let(:files) { build_list(:file, 3) }
|
||||||
|
|
||||||
it 'creates all files' do
|
it 'creates all files' do
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
expect(File).to receive(:open).with(local_path.join(file.filepath), 'w')
|
expect(File).to receive(:write).with(local_path.join(file.filepath), file.content)
|
||||||
end
|
end
|
||||||
container_pool.copy_files(files)
|
container_pool.copy_files(files)
|
||||||
end
|
end
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Runner::Strategy::Poseidon do
|
describe Runner::Strategy::Poseidon do
|
||||||
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
|
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||||
let(:execution_environment) { FactoryBot.create :ruby }
|
let(:execution_environment) { create :ruby }
|
||||||
let(:poseidon) { described_class.new(runner_id, execution_environment) }
|
let(:poseidon) { described_class.new(runner_id, execution_environment) }
|
||||||
let(:error_message) { 'test error message' }
|
let(:error_message) { 'test error message' }
|
||||||
let(:response_body) { nil }
|
let(:response_body) { nil }
|
||||||
@ -128,7 +128,7 @@ describe Runner::Strategy::Poseidon do
|
|||||||
|
|
||||||
describe '::sync_environment' do
|
describe '::sync_environment' do
|
||||||
let(:action) { -> { described_class.sync_environment(execution_environment) } }
|
let(:action) { -> { described_class.sync_environment(execution_environment) } }
|
||||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
let(:execution_environment) { create(:ruby) }
|
||||||
|
|
||||||
it 'makes the correct request to Poseidon' do
|
it 'makes the correct request to Poseidon' do
|
||||||
faraday_connection = instance_double 'Faraday::Connection'
|
faraday_connection = instance_double 'Faraday::Connection'
|
||||||
@ -321,7 +321,7 @@ describe Runner::Strategy::Poseidon do
|
|||||||
|
|
||||||
describe '#copy_files' do
|
describe '#copy_files' do
|
||||||
let(:file_content) { 'print("Hello World!")' }
|
let(:file_content) { 'print("Hello World!")' }
|
||||||
let(:file) { FactoryBot.build(:file, content: file_content) }
|
let(:file) { build(:file, content: file_content) }
|
||||||
let(:action) { -> { poseidon.copy_files([file]) } }
|
let(:action) { -> { poseidon.copy_files([file]) } }
|
||||||
let(:encoded_file_content) { Base64.strict_encode64(file.content) }
|
let(:encoded_file_content) { Base64.strict_encode64(file.content) }
|
||||||
let!(:copy_files_stub) do
|
let!(:copy_files_stub) do
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe UserMailer do
|
describe UserMailer do
|
||||||
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
|
let(:user) { InternalUser.create(attributes_for(:teacher)) }
|
||||||
|
|
||||||
describe '#activation_needed_email' do
|
describe '#activation_needed_email' do
|
||||||
let(:mail) { described_class.activation_needed_email(user) }
|
let(:mail) { described_class.activation_needed_email(user) }
|
||||||
|
@ -6,7 +6,7 @@ describe CodeOcean::File do
|
|||||||
let(:file) { described_class.create.tap {|file| file.update(content: nil, hidden: nil, read_only: nil) } }
|
let(:file) { described_class.create.tap {|file| file.update(content: nil, hidden: nil, read_only: nil) } }
|
||||||
|
|
||||||
it 'validates the presence of a file type' do
|
it 'validates the presence of a file type' do
|
||||||
expect(file.errors[:file_type_id]).to be_present
|
expect(file.errors[:file_type]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of the hidden flag' do
|
it 'validates the presence of the hidden flag' do
|
||||||
|
@ -11,7 +11,7 @@ describe CodeharborLink do
|
|||||||
describe '#to_s' do
|
describe '#to_s' do
|
||||||
subject { codeharbor_link.to_s }
|
subject { codeharbor_link.to_s }
|
||||||
|
|
||||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link) }
|
let(:codeharbor_link) { create(:codeharbor_link) }
|
||||||
|
|
||||||
it { is_expected.to eql codeharbor_link.id.to_s }
|
it { is_expected.to eql codeharbor_link.id.to_s }
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ describe Consumer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the uniqueness of the OAuth key' do
|
it 'validates the uniqueness of the OAuth key' do
|
||||||
consumer.update(oauth_key: FactoryBot.create(:consumer).oauth_key)
|
consumer.update(oauth_key: create(:consumer).oauth_key)
|
||||||
expect(consumer.errors[:oauth_key]).to be_present
|
expect(consumer.errors[:oauth_key]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ describe ExecutionEnvironment do
|
|||||||
it 'validates that the Docker image works' do
|
it 'validates that the Docker image works' do
|
||||||
allow(execution_environment).to receive(:validate_docker_image?).and_return(true)
|
allow(execution_environment).to receive(:validate_docker_image?).and_return(true)
|
||||||
allow(execution_environment).to receive(:working_docker_image?).and_return(true)
|
allow(execution_environment).to receive(:working_docker_image?).and_return(true)
|
||||||
execution_environment.update(FactoryBot.build(:ruby).attributes)
|
execution_environment.update(build(:ruby).attributes)
|
||||||
expect(execution_environment).to have_received(:working_docker_image?)
|
expect(execution_environment).to have_received(:working_docker_image?)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -81,8 +81,7 @@ describe ExecutionEnvironment do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of a user' do
|
it 'validates the presence of a user' do
|
||||||
expect(execution_environment.errors[:user_id]).to be_present
|
expect(execution_environment.errors[:user]).to be_present
|
||||||
expect(execution_environment.errors[:user_type]).to be_present
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the format of the exposed ports' do
|
it 'validates the format of the exposed ports' do
|
||||||
@ -95,7 +94,7 @@ describe ExecutionEnvironment do
|
|||||||
|
|
||||||
describe '#valid_test_setup?' do
|
describe '#valid_test_setup?' do
|
||||||
context 'with a test command and a testing framework' do
|
context 'with a test command and a testing framework' do
|
||||||
before { execution_environment.update(test_command: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
|
before { execution_environment.update(test_command: attributes_for(:ruby)[:test_command], testing_framework: attributes_for(:ruby)[:testing_framework]) }
|
||||||
|
|
||||||
it 'is valid' do
|
it 'is valid' do
|
||||||
expect(execution_environment.errors[:test_command]).to be_blank
|
expect(execution_environment.errors[:test_command]).to be_blank
|
||||||
@ -103,7 +102,7 @@ describe ExecutionEnvironment do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a test command but no testing framework' do
|
context 'with a test command but no testing framework' do
|
||||||
before { execution_environment.update(test_command: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: nil) }
|
before { execution_environment.update(test_command: attributes_for(:ruby)[:test_command], testing_framework: nil) }
|
||||||
|
|
||||||
it 'is invalid' do
|
it 'is invalid' do
|
||||||
expect(execution_environment.errors[:test_command]).to be_present
|
expect(execution_environment.errors[:test_command]).to be_present
|
||||||
@ -111,7 +110,7 @@ describe ExecutionEnvironment do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with no test command but a testing framework' do
|
context 'with no test command but a testing framework' do
|
||||||
before { execution_environment.update(test_command: nil, testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
|
before { execution_environment.update(test_command: nil, testing_framework: attributes_for(:ruby)[:testing_framework]) }
|
||||||
|
|
||||||
it 'is invalid' do
|
it 'is invalid' do
|
||||||
expect(execution_environment.errors[:test_command]).to be_present
|
expect(execution_environment.errors[:test_command]).to be_present
|
||||||
@ -144,7 +143,7 @@ describe ExecutionEnvironment do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'is true otherwise' do
|
it 'is true otherwise' do
|
||||||
execution_environment.docker_image = FactoryBot.attributes_for(:ruby)[:docker_image]
|
execution_environment.docker_image = attributes_for(:ruby)[:docker_image]
|
||||||
execution_environment.pool_size = 1
|
execution_environment.pool_size = 1
|
||||||
allow(Rails.env).to receive(:test?).and_return(false)
|
allow(Rails.env).to receive(:test?).and_return(false)
|
||||||
expect(execution_environment.send(:validate_docker_image?)).to be true
|
expect(execution_environment.send(:validate_docker_image?)).to be true
|
||||||
@ -152,7 +151,7 @@ describe ExecutionEnvironment do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#working_docker_image?' do
|
describe '#working_docker_image?' do
|
||||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
let(:execution_environment) { create(:ruby) }
|
||||||
let(:working_docker_image?) { execution_environment.send(:working_docker_image?) }
|
let(:working_docker_image?) { execution_environment.send(:working_docker_image?) }
|
||||||
let(:runner) { instance_double 'runner' }
|
let(:runner) { instance_double 'runner' }
|
||||||
|
|
||||||
|
@ -4,15 +4,15 @@ require 'rails_helper'
|
|||||||
|
|
||||||
describe Exercise do
|
describe Exercise do
|
||||||
let(:exercise) { described_class.create.tap {|exercise| exercise.update(public: nil, token: nil) } }
|
let(:exercise) { described_class.create.tap {|exercise| exercise.update(public: nil, token: nil) } }
|
||||||
let(:users) { FactoryBot.create_list(:external_user, 10) }
|
let(:users) { create_list(:external_user, 10) }
|
||||||
|
|
||||||
def create_submissions
|
def create_submissions
|
||||||
FactoryBot.create_list(:submission, 10, cause: 'submit', exercise: exercise, score: Forgery(:basic).number, user: users.sample)
|
create_list(:submission, 10, cause: 'submit', exercise: exercise, score: Forgery(:basic).number, user: users.sample)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the number of main files' do
|
it 'validates the number of main files' do
|
||||||
exercise = FactoryBot.create(:dummy)
|
exercise = create(:dummy)
|
||||||
exercise.files += FactoryBot.create_pair(:file)
|
exercise.files += create_pair(:file)
|
||||||
expect(exercise).to receive(:valid_main_file?).and_call_original
|
expect(exercise).to receive(:valid_main_file?).and_call_original
|
||||||
exercise.save
|
exercise.save
|
||||||
expect(exercise.errors[:files]).to be_present
|
expect(exercise.errors[:files]).to be_present
|
||||||
@ -37,36 +37,35 @@ describe Exercise do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of a user' do
|
it 'validates the presence of a user' do
|
||||||
expect(exercise.errors[:user_id]).to be_present
|
expect(exercise.errors[:user]).to be_present
|
||||||
expect(exercise.errors[:user_type]).to be_present
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise is unpublished' do
|
context 'when exercise is unpublished' do
|
||||||
subject { FactoryBot.build(:dummy, unpublished: true) }
|
subject { build(:dummy, unpublished: true) }
|
||||||
|
|
||||||
it { is_expected.not_to validate_presence_of(:execution_environment) }
|
it { is_expected.not_to validate_presence_of(:execution_environment) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise is not unpublished' do
|
context 'when exercise is not unpublished' do
|
||||||
subject { FactoryBot.build(:dummy, unpublished: false) }
|
subject { build(:dummy, unpublished: false) }
|
||||||
|
|
||||||
it { is_expected.to validate_presence_of(:execution_environment) }
|
it { is_expected.to validate_presence_of(:execution_environment) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with uuid' do
|
context 'with uuid' do
|
||||||
subject { FactoryBot.build(:dummy, uuid: SecureRandom.uuid) }
|
subject { build(:dummy, uuid: SecureRandom.uuid) }
|
||||||
|
|
||||||
it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
|
it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without uuid' do
|
context 'without uuid' do
|
||||||
subject { FactoryBot.build(:dummy, uuid: nil) }
|
subject { build(:dummy, uuid: nil) }
|
||||||
|
|
||||||
it { is_expected.not_to validate_uniqueness_of(:uuid) }
|
it { is_expected.not_to validate_uniqueness_of(:uuid) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#average_percentage' do
|
describe '#average_percentage' do
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
|
|
||||||
context 'without submissions' do
|
context 'without submissions' do
|
||||||
it 'returns nil' do
|
it 'returns nil' do
|
||||||
@ -85,7 +84,7 @@ describe Exercise do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#average_score' do
|
describe '#average_score' do
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
|
|
||||||
context 'without submissions' do
|
context 'without submissions' do
|
||||||
it 'returns nil' do
|
it 'returns nil' do
|
||||||
@ -104,7 +103,7 @@ describe Exercise do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#duplicate' do
|
describe '#duplicate' do
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
|
|
||||||
after { exercise.duplicate }
|
after { exercise.duplicate }
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ describe ExternalUser do
|
|||||||
let(:user) { described_class.create }
|
let(:user) { described_class.create }
|
||||||
|
|
||||||
it 'validates the presence of a consumer' do
|
it 'validates the presence of a consumer' do
|
||||||
expect(user.errors[:consumer_id]).to be_present
|
expect(user.errors[:consumer]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of an external ID' do
|
it 'validates the presence of an external ID' do
|
||||||
@ -15,7 +15,7 @@ describe ExternalUser do
|
|||||||
|
|
||||||
describe '#admin?' do
|
describe '#admin?' do
|
||||||
it 'is false' do
|
it 'is false' do
|
||||||
expect(FactoryBot.build(:external_user).admin?).to be false
|
expect(build(:external_user).admin?).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ describe ExternalUser do
|
|||||||
|
|
||||||
describe '#teacher?' do
|
describe '#teacher?' do
|
||||||
it 'is false' do
|
it 'is false' do
|
||||||
expect(FactoryBot.build(:external_user).teacher?).to be false
|
expect(build(:external_user).teacher?).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -52,7 +52,6 @@ describe FileType do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of a user' do
|
it 'validates the presence of a user' do
|
||||||
expect(file_type.errors[:user_id]).to be_present
|
expect(file_type.errors[:user]).to be_present
|
||||||
expect(file_type.errors[:user_type]).to be_present
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,12 +11,12 @@ describe InternalUser do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the uniqueness of the email address' do
|
it 'validates the uniqueness of the email address' do
|
||||||
user.update(email: FactoryBot.create(:admin).email)
|
user.update(email: create(:admin).email)
|
||||||
expect(user.errors[:email]).to be_present
|
expect(user.errors[:email]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not activated' do
|
context 'when not activated' do
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
user.send(:setup_activation)
|
user.send(:setup_activation)
|
||||||
@ -35,7 +35,7 @@ describe InternalUser do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a pending password reset' do
|
context 'with a pending password reset' do
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
|
|
||||||
before { user.deliver_reset_password_instructions! }
|
before { user.deliver_reset_password_instructions! }
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ describe InternalUser do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when complete' do
|
context 'when complete' do
|
||||||
let(:user) { FactoryBot.create(:teacher, activation_state: 'active') }
|
let(:user) { create(:teacher, activation_state: 'active') }
|
||||||
|
|
||||||
it 'does not validate the confirmation of the password' do
|
it 'does not validate the confirmation of the password' do
|
||||||
user.update(password: password, password_confirmation: '')
|
user.update(password: password, password_confirmation: '')
|
||||||
@ -74,8 +74,8 @@ describe InternalUser do
|
|||||||
|
|
||||||
describe '#admin?' do
|
describe '#admin?' do
|
||||||
it 'is only true for admins' do
|
it 'is only true for admins' do
|
||||||
expect(FactoryBot.build(:admin).admin?).to be true
|
expect(build(:admin).admin?).to be true
|
||||||
expect(FactoryBot.build(:teacher).admin?).to be false
|
expect(build(:teacher).admin?).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ describe InternalUser do
|
|||||||
|
|
||||||
describe '#teacher?' do
|
describe '#teacher?' do
|
||||||
it 'is only true for teachers' do
|
it 'is only true for teachers' do
|
||||||
expect(FactoryBot.build(:admin).teacher?).to be false
|
expect(build(:admin).teacher?).to be false
|
||||||
expect(FactoryBot.build(:teacher).teacher?).to be true
|
expect(build(:teacher).teacher?).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe RequestForComment do
|
describe RequestForComment do
|
||||||
let!(:rfc) { FactoryBot.create(:rfc) }
|
let!(:rfc) { create(:rfc) }
|
||||||
|
|
||||||
describe 'scope with_comments' do
|
describe 'scope with_comments' do
|
||||||
let!(:rfc2) { FactoryBot.create(:rfc_with_comment) }
|
let!(:rfc2) { create(:rfc_with_comment) }
|
||||||
|
|
||||||
it 'includes all RfCs with comments' do
|
it 'includes all RfCs with comments' do
|
||||||
expect(described_class.with_comments).to include(rfc2)
|
expect(described_class.with_comments).to include(rfc2)
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Runner do
|
describe Runner do
|
||||||
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
|
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||||
let(:strategy_class) { described_class.strategy_class }
|
let(:strategy_class) { described_class.strategy_class }
|
||||||
let(:strategy) { instance_double(strategy_class) }
|
let(:strategy) { instance_double(strategy_class) }
|
||||||
|
|
||||||
describe 'attribute validation' do
|
describe 'attribute validation' do
|
||||||
let(:runner) { FactoryBot.create :runner }
|
let(:runner) { create :runner }
|
||||||
|
|
||||||
it 'validates the presence of the runner id' do
|
it 'validates the presence of the runner id' do
|
||||||
described_class.skip_callback(:validation, :before, :request_id)
|
described_class.skip_callback(:validation, :before, :request_id)
|
||||||
@ -162,8 +162,8 @@ describe Runner do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'creation' do
|
describe 'creation' do
|
||||||
let(:user) { FactoryBot.create :external_user }
|
let(:user) { create :external_user }
|
||||||
let(:execution_environment) { FactoryBot.create :ruby }
|
let(:execution_environment) { create :ruby }
|
||||||
let(:create_action) { -> { described_class.create(user: user, execution_environment: execution_environment) } }
|
let(:create_action) { -> { described_class.create(user: user, execution_environment: execution_environment) } }
|
||||||
|
|
||||||
it 'requests a runner id from the runner management' do
|
it 'requests a runner id from the runner management' do
|
||||||
@ -187,12 +187,12 @@ describe Runner do
|
|||||||
it 'does not call the runner management again while a runner id is set' do
|
it 'does not call the runner management again while a runner id is set' do
|
||||||
expect(strategy_class).to receive(:request_from_management).and_return(runner_id).once
|
expect(strategy_class).to receive(:request_from_management).and_return(runner_id).once
|
||||||
runner = create_action.call
|
runner = create_action.call
|
||||||
runner.update(user: FactoryBot.create(:external_user))
|
runner.update(user: create(:external_user))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#request_new_id' do
|
describe '#request_new_id' do
|
||||||
let(:runner) { FactoryBot.create :runner }
|
let(:runner) { create :runner }
|
||||||
|
|
||||||
context 'when the environment is available in the runner management' do
|
context 'when the environment is available in the runner management' do
|
||||||
it 'requests the runner management' do
|
it 'requests the runner management' do
|
||||||
@ -240,8 +240,8 @@ describe Runner do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '::for' do
|
describe '::for' do
|
||||||
let(:user) { FactoryBot.create :external_user }
|
let(:user) { create :external_user }
|
||||||
let(:exercise) { FactoryBot.create :fibonacci }
|
let(:exercise) { create :fibonacci }
|
||||||
|
|
||||||
context 'when the runner could not be saved' do
|
context 'when the runner could not be saved' do
|
||||||
before { allow(strategy_class).to receive(:request_from_management).and_return(nil) }
|
before { allow(strategy_class).to receive(:request_from_management).and_return(nil) }
|
||||||
@ -252,7 +252,7 @@ describe Runner do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when a runner already exists' do
|
context 'when a runner already exists' do
|
||||||
let!(:existing_runner) { FactoryBot.create(:runner, user: user, execution_environment: exercise.execution_environment) }
|
let!(:existing_runner) { create(:runner, user: user, execution_environment: exercise.execution_environment) }
|
||||||
|
|
||||||
it 'returns the existing runner' do
|
it 'returns the existing runner' do
|
||||||
new_runner = described_class.for(user, exercise.execution_environment)
|
new_runner = described_class.for(user, exercise.execution_environment)
|
||||||
|
@ -3,23 +3,22 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Submission do
|
describe Submission do
|
||||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) }
|
let(:submission) { create(:submission, exercise: create(:dummy)) }
|
||||||
|
|
||||||
it 'validates the presence of a cause' do
|
it 'validates the presence of a cause' do
|
||||||
expect(described_class.create.errors[:cause]).to be_present
|
expect(described_class.create.errors[:cause]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of an exercise' do
|
it 'validates the presence of an exercise' do
|
||||||
expect(described_class.create.errors[:exercise_id]).to be_present
|
expect(described_class.create.errors[:exercise]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates the presence of a user' do
|
it 'validates the presence of a user' do
|
||||||
expect(described_class.create.errors[:user_id]).to be_present
|
expect(described_class.create.errors[:user]).to be_present
|
||||||
expect(described_class.create.errors[:user_type]).to be_present
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#main_file' do
|
describe '#main_file' do
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
|
|
||||||
it "returns the submission's main file" do
|
it "returns the submission's main file" do
|
||||||
expect(submission.main_file).to be_a(CodeOcean::File)
|
expect(submission.main_file).to be_a(CodeOcean::File)
|
||||||
@ -29,7 +28,7 @@ describe Submission do
|
|||||||
|
|
||||||
describe '#normalized_score' do
|
describe '#normalized_score' do
|
||||||
context 'with a score' do
|
context 'with a score' do
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
|
|
||||||
before { submission.score = submission.exercise.maximum_score / 2 }
|
before { submission.score = submission.exercise.maximum_score / 2 }
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ describe Submission do
|
|||||||
|
|
||||||
describe '#percentage' do
|
describe '#percentage' do
|
||||||
context 'with a score' do
|
context 'with a score' do
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
|
|
||||||
before { submission.score = submission.exercise.maximum_score / 2 }
|
before { submission.score = submission.exercise.maximum_score / 2 }
|
||||||
|
|
||||||
@ -69,11 +68,11 @@ describe Submission do
|
|||||||
|
|
||||||
describe '#siblings' do
|
describe '#siblings' do
|
||||||
let(:siblings) { described_class.find_by(user: user).siblings }
|
let(:siblings) { described_class.find_by(user: user).siblings }
|
||||||
let(:user) { FactoryBot.create(:external_user) }
|
let(:user) { create(:external_user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
10.times.each_with_index do |_, index|
|
10.times.each_with_index do |_, index|
|
||||||
FactoryBot.create(:submission, exercise: submission.exercise, user: (index.even? ? user : FactoryBot.create(:external_user)))
|
create(:submission, exercise: submission.exercise, user: (index.even? ? user : create(:external_user)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -92,9 +91,9 @@ describe Submission do
|
|||||||
|
|
||||||
describe '#redirect_to_feedback?' do
|
describe '#redirect_to_feedback?' do
|
||||||
context 'with no exercise feedback' do
|
context 'with no exercise feedback' do
|
||||||
let(:exercise) { FactoryBot.create(:dummy) }
|
let(:exercise) { create(:dummy) }
|
||||||
let(:user) { FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
let(:user) { build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
||||||
let(:submission) { FactoryBot.build(:submission, exercise: exercise, user: user) }
|
let(:submission) { build(:submission, exercise: exercise, user: user) }
|
||||||
|
|
||||||
it 'sends 10% of users to feedback page' do
|
it 'sends 10% of users to feedback page' do
|
||||||
expect(submission.send(:redirect_to_feedback?)).to be_truthy
|
expect(submission.send(:redirect_to_feedback?)).to be_truthy
|
||||||
@ -102,16 +101,16 @@ describe Submission do
|
|||||||
|
|
||||||
it 'does not redirect other users' do
|
it 'does not redirect other users' do
|
||||||
9.times do |i|
|
9.times do |i|
|
||||||
submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
submission = build(:submission, exercise: exercise, user: build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
||||||
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with little exercise feedback' do
|
context 'with little exercise feedback' do
|
||||||
let(:exercise) { FactoryBot.create(:dummy_with_user_feedbacks) }
|
let(:exercise) { create(:dummy_with_user_feedbacks) }
|
||||||
let(:user) { FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
let(:user) { build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
||||||
let(:submission) { FactoryBot.build(:submission, exercise: exercise, user: user) }
|
let(:submission) { build(:submission, exercise: exercise, user: user) }
|
||||||
|
|
||||||
it 'sends 10% of users to feedback page' do
|
it 'sends 10% of users to feedback page' do
|
||||||
expect(submission.send(:redirect_to_feedback?)).to be_truthy
|
expect(submission.send(:redirect_to_feedback?)).to be_truthy
|
||||||
@ -119,15 +118,15 @@ describe Submission do
|
|||||||
|
|
||||||
it 'does not redirect other users' do
|
it 'does not redirect other users' do
|
||||||
9.times do |i|
|
9.times do |i|
|
||||||
submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
submission = build(:submission, exercise: exercise, user: build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
||||||
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with enough exercise feedback' do
|
context 'with enough exercise feedback' do
|
||||||
let(:exercise) { FactoryBot.create(:dummy_with_user_feedbacks, user_feedbacks_count: 42) }
|
let(:exercise) { create(:dummy_with_user_feedbacks, user_feedbacks_count: 42) }
|
||||||
let(:user) { FactoryBot.create(:external_user) }
|
let(:user) { create(:external_user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(described_class).to receive(:redirect_to_feedback?).and_return(false)
|
allow_any_instance_of(described_class).to receive(:redirect_to_feedback?).and_return(false)
|
||||||
@ -135,7 +134,7 @@ describe Submission do
|
|||||||
|
|
||||||
it 'sends nobody to feedback page' do
|
it 'sends nobody to feedback page' do
|
||||||
30.times do |_i|
|
30.times do |_i|
|
||||||
submission = FactoryBot.create(:submission, exercise: exercise, user: FactoryBot.create(:external_user))
|
submission = create(:submission, exercise: exercise, user: create(:external_user))
|
||||||
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -143,7 +142,7 @@ describe Submission do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#calculate_score' do
|
describe '#calculate_score' do
|
||||||
let(:runner) { FactoryBot.create :runner }
|
let(:runner) { create :runner }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(Runner).to receive(:for).and_return(runner)
|
allow(Runner).to receive(:for).and_return(runner)
|
||||||
|
@ -7,15 +7,15 @@ describe Admin::DashboardPolicy do
|
|||||||
|
|
||||||
permissions :show? do
|
permissions :show? do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), :dashboard)
|
expect(policy).to permit(build(:admin), :dashboard)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to teachers' do
|
it 'does not grant access to teachers' do
|
||||||
expect(policy).not_to permit(FactoryBot.build(:teacher), :dashboard)
|
expect(policy).not_to permit(build(:teacher), :dashboard)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to external users' do
|
it 'does not grant access to external users' do
|
||||||
expect(policy).not_to permit(FactoryBot.build(:external_user), :dashboard)
|
expect(policy).not_to permit(build(:external_user), :dashboard)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,15 +5,15 @@ require 'rails_helper'
|
|||||||
describe CodeOcean::FilePolicy do
|
describe CodeOcean::FilePolicy do
|
||||||
subject(:policy) { described_class }
|
subject(:policy) { described_class }
|
||||||
|
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
let(:submission) { FactoryBot.create(:submission) }
|
let(:submission) { create(:submission) }
|
||||||
|
|
||||||
permissions :create? do
|
permissions :create? do
|
||||||
context 'when being part of an exercise' do
|
context 'when being part of an exercise' do
|
||||||
let(:file) { exercise.files.first }
|
let(:file) { exercise.files.first }
|
||||||
|
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), file)
|
expect(policy).to permit(build(:admin), file)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
@ -22,7 +22,7 @@ describe CodeOcean::FilePolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
expect(policy).not_to permit(build(factory_name), file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -52,7 +52,7 @@ describe CodeOcean::FilePolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[admin external_user teacher].each do |factory_name|
|
%i[admin external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
expect(policy).not_to permit(build(factory_name), file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -63,7 +63,7 @@ describe CodeOcean::FilePolicy do
|
|||||||
let(:file) { exercise.files.first }
|
let(:file) { exercise.files.first }
|
||||||
|
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), file)
|
expect(policy).to permit(build(:admin), file)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
@ -72,7 +72,7 @@ describe CodeOcean::FilePolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
expect(policy).not_to permit(build(factory_name), file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -82,7 +82,7 @@ describe CodeOcean::FilePolicy do
|
|||||||
|
|
||||||
it 'does not grant access to anyone' do
|
it 'does not grant access to anyone' do
|
||||||
%i[admin external_user teacher].each do |factory_name|
|
%i[admin external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
expect(policy).not_to permit(build(factory_name), file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ require 'rails_helper'
|
|||||||
describe CodeharborLinkPolicy do
|
describe CodeharborLinkPolicy do
|
||||||
subject(:policy) { described_class }
|
subject(:policy) { described_class }
|
||||||
|
|
||||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link) }
|
let(:codeharbor_link) { create(:codeharbor_link) }
|
||||||
|
|
||||||
context 'when CodeHarbor link is enabled' do
|
context 'when CodeHarbor link is enabled' do
|
||||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
||||||
@ -20,7 +20,7 @@ describe CodeharborLinkPolicy do
|
|||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'does not grant access any user' do
|
it 'does not grant access any user' do
|
||||||
%i[external_user teacher admin].each do |factory_name|
|
%i[external_user teacher admin].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.create(factory_name), codeharbor_link)
|
expect(policy).not_to permit(create(factory_name), codeharbor_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -30,12 +30,12 @@ describe CodeharborLinkPolicy do
|
|||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to teachers' do
|
it 'grants access to teachers' do
|
||||||
%i[teacher admin].each do |factory_name|
|
%i[teacher admin].each do |factory_name|
|
||||||
expect(policy).to permit(FactoryBot.create(factory_name), codeharbor_link)
|
expect(policy).to permit(create(factory_name), codeharbor_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
expect(policy).not_to permit(FactoryBot.create(:external_user), codeharbor_link)
|
expect(policy).not_to permit(create(:external_user), codeharbor_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -48,7 +48,7 @@ describe CodeharborLinkPolicy do
|
|||||||
|
|
||||||
it 'does not grant access to arbitrary users' do
|
it 'does not grant access to arbitrary users' do
|
||||||
%i[external_user admin teacher].each do |factory_name|
|
%i[external_user admin teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.create(factory_name), codeharbor_link)
|
expect(policy).not_to permit(create(factory_name), codeharbor_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -57,7 +57,7 @@ describe CodeharborLinkPolicy do
|
|||||||
permissions(:enabled?) do
|
permissions(:enabled?) do
|
||||||
it 'reflects the config option' do
|
it 'reflects the config option' do
|
||||||
%i[external_user admin teacher].each do |factory_name|
|
%i[external_user admin teacher].each do |factory_name|
|
||||||
expect(policy).to permit(FactoryBot.create(factory_name), codeharbor_link)
|
expect(policy).to permit(create(factory_name), codeharbor_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -75,7 +75,7 @@ describe CodeharborLinkPolicy do
|
|||||||
permissions(:enabled?) do
|
permissions(:enabled?) do
|
||||||
it 'reflects the config option' do
|
it 'reflects the config option' do
|
||||||
%i[external_user admin teacher].each do |factory_name|
|
%i[external_user admin teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.create(factory_name), codeharbor_link)
|
expect(policy).not_to permit(create(factory_name), codeharbor_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,9 +8,9 @@ describe ConsumerPolicy do
|
|||||||
%i[create? destroy? edit? index? new? show? update?].each do |action|
|
%i[create? destroy? edit? index? new? show? update?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins only' do
|
it 'grants access to admins only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), Consumer.new)
|
expect(policy).to permit(build(:admin), Consumer.new)
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), Consumer.new)
|
expect(policy).not_to permit(build(factory_name), Consumer.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,20 +5,20 @@ require 'rails_helper'
|
|||||||
describe ExecutionEnvironmentPolicy do
|
describe ExecutionEnvironmentPolicy do
|
||||||
subject(:policy) { described_class }
|
subject(:policy) { described_class }
|
||||||
|
|
||||||
let(:execution_environment) { FactoryBot.build(:ruby) }
|
let(:execution_environment) { build(:ruby) }
|
||||||
|
|
||||||
[:index?].each do |action|
|
[:index?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), execution_environment)
|
expect(policy).to permit(build(:admin), execution_environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to teachers' do
|
it 'grants access to teachers' do
|
||||||
expect(policy).to permit(FactoryBot.build(:teacher), execution_environment)
|
expect(policy).to permit(build(:teacher), execution_environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to external users' do
|
it 'does not grant access to external users' do
|
||||||
expect(policy).not_to permit(FactoryBot.build(:external_user), execution_environment)
|
expect(policy).not_to permit(build(:external_user), execution_environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -26,7 +26,7 @@ describe ExecutionEnvironmentPolicy do
|
|||||||
%i[execute_command? shell? statistics? show?].each do |action|
|
%i[execute_command? shell? statistics? show?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), execution_environment)
|
expect(policy).to permit(build(:admin), execution_environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
@ -35,7 +35,7 @@ describe ExecutionEnvironmentPolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), execution_environment)
|
expect(policy).not_to permit(build(factory_name), execution_environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ describe ExecutionEnvironmentPolicy do
|
|||||||
%i[destroy? edit? update? new? create?].each do |action|
|
%i[destroy? edit? update? new? create?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), execution_environment)
|
expect(policy).to permit(build(:admin), execution_environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to authors' do
|
it 'does not grant access to authors' do
|
||||||
@ -53,7 +53,7 @@ describe ExecutionEnvironmentPolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), execution_environment)
|
expect(policy).not_to permit(build(factory_name), execution_environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -61,7 +61,7 @@ describe ExecutionEnvironmentPolicy do
|
|||||||
|
|
||||||
permissions(:sync_all_to_runner_management?) do
|
permissions(:sync_all_to_runner_management?) do
|
||||||
it 'grants access to the admin' do
|
it 'grants access to the admin' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin))
|
expect(policy).to permit(build(:admin))
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'it does not grant access' do |user|
|
shared_examples 'it does not grant access' do |user|
|
||||||
@ -71,7 +71,7 @@ describe ExecutionEnvironmentPolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
%i[teacher external_user].each do |user|
|
%i[teacher external_user].each do |user|
|
||||||
include_examples 'it does not grant access', FactoryBot.build(user)
|
include_examples 'it does not grant access', FactoryBot.build(user) # rubocop:disable RSpec/FactoryBot/SyntaxMethods
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,13 +5,13 @@ require 'rails_helper'
|
|||||||
describe ExercisePolicy do
|
describe ExercisePolicy do
|
||||||
subject(:policy) { described_class }
|
subject(:policy) { described_class }
|
||||||
|
|
||||||
let(:exercise) { FactoryBot.build(:dummy, public: true) }
|
let(:exercise) { build(:dummy, public: true) }
|
||||||
|
|
||||||
permissions :batch_update? do
|
permissions :batch_update? do
|
||||||
it 'grants access to admins only' do
|
it 'grants access to admins only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), exercise)
|
expect(policy).to permit(build(:admin), exercise)
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), exercise)
|
expect(policy).not_to permit(build(factory_name), exercise)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -19,15 +19,15 @@ describe ExercisePolicy do
|
|||||||
%i[create? index? new? statistics? feedback? rfcs_for_exercise?].each do |action|
|
%i[create? index? new? statistics? feedback? rfcs_for_exercise?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), exercise)
|
expect(policy).to permit(build(:admin), exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to teachers' do
|
it 'grants access to teachers' do
|
||||||
expect(policy).to permit(FactoryBot.build(:teacher), exercise)
|
expect(policy).to permit(build(:teacher), exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to external users' do
|
it 'does not grant access to external users' do
|
||||||
expect(policy).not_to permit(FactoryBot.build(:external_user), exercise)
|
expect(policy).not_to permit(build(:external_user), exercise)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -35,7 +35,7 @@ describe ExercisePolicy do
|
|||||||
%i[clone? destroy? edit? update?].each do |action|
|
%i[clone? destroy? edit? update?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), exercise)
|
expect(policy).to permit(build(:admin), exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
@ -44,7 +44,7 @@ describe ExercisePolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), exercise)
|
expect(policy).not_to permit(build(factory_name), exercise)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -60,7 +60,7 @@ describe ExercisePolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when user has codeharbor_link' do
|
context 'when user has codeharbor_link' do
|
||||||
before { user.codeharbor_link = FactoryBot.build(:codeharbor_link) }
|
before { user.codeharbor_link = build(:codeharbor_link) }
|
||||||
|
|
||||||
it 'grants access' do
|
it 'grants access' do
|
||||||
expect(policy).to permit(user, exercise)
|
expect(policy).to permit(user, exercise)
|
||||||
@ -69,14 +69,14 @@ describe ExercisePolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is admin' do
|
context 'when user is admin' do
|
||||||
let(:user) { FactoryBot.build(:admin) }
|
let(:user) { build(:admin) }
|
||||||
|
|
||||||
it 'does not grant access' do
|
it 'does not grant access' do
|
||||||
expect(policy).not_to permit(user, exercise)
|
expect(policy).not_to permit(user, exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user has codeharbor_link' do
|
context 'when user has codeharbor_link' do
|
||||||
before { user.codeharbor_link = FactoryBot.build(:codeharbor_link) }
|
before { user.codeharbor_link = build(:codeharbor_link) }
|
||||||
|
|
||||||
it 'grants access' do
|
it 'grants access' do
|
||||||
expect(policy).to permit(user, exercise)
|
expect(policy).to permit(user, exercise)
|
||||||
@ -86,14 +86,14 @@ describe ExercisePolicy do
|
|||||||
|
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
context "when user is #{factory_name}" do
|
context "when user is #{factory_name}" do
|
||||||
let(:user) { FactoryBot.build(factory_name) }
|
let(:user) { build(factory_name) }
|
||||||
|
|
||||||
it 'does not grant access' do
|
it 'does not grant access' do
|
||||||
expect(policy).not_to permit(user, exercise)
|
expect(policy).not_to permit(user, exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user has codeharbor_link' do
|
context 'when user has codeharbor_link' do
|
||||||
before { user.codeharbor_link = FactoryBot.build(:codeharbor_link) }
|
before { user.codeharbor_link = build(:codeharbor_link) }
|
||||||
|
|
||||||
it 'does not grant access' do
|
it 'does not grant access' do
|
||||||
expect(policy).not_to permit(user, exercise)
|
expect(policy).not_to permit(user, exercise)
|
||||||
@ -107,7 +107,7 @@ describe ExercisePolicy do
|
|||||||
[:show?].each do |action|
|
[:show?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'not grants access to external users' do
|
it 'not grants access to external users' do
|
||||||
expect(policy).not_to permit(FactoryBot.build(:external_user), exercise)
|
expect(policy).not_to permit(build(:external_user), exercise)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -116,7 +116,7 @@ describe ExercisePolicy do
|
|||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to anyone' do
|
it 'grants access to anyone' do
|
||||||
%i[admin external_user teacher].each do |factory_name|
|
%i[admin external_user teacher].each do |factory_name|
|
||||||
expect(policy).to permit(FactoryBot.build(factory_name), Exercise.new)
|
expect(policy).to permit(build(factory_name), Exercise.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -124,14 +124,14 @@ describe ExercisePolicy do
|
|||||||
|
|
||||||
describe ExercisePolicy::Scope do
|
describe ExercisePolicy::Scope do
|
||||||
describe '#resolve' do
|
describe '#resolve' do
|
||||||
let(:admin) { FactoryBot.create(:admin) }
|
let(:admin) { create(:admin) }
|
||||||
let(:external_user) { FactoryBot.create(:external_user) }
|
let(:external_user) { create(:external_user) }
|
||||||
let(:teacher) { FactoryBot.create(:teacher) }
|
let(:teacher) { create(:teacher) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
[admin, teacher].each do |user|
|
[admin, teacher].each do |user|
|
||||||
[true, false].each do |public|
|
[true, false].each do |public|
|
||||||
FactoryBot.create(:dummy, public: public, user_id: user.id, user_type: InternalUser.name)
|
create(:dummy, public: public, user_id: user.id, user_type: InternalUser.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,9 +8,9 @@ describe ExternalUserPolicy do
|
|||||||
%i[create? destroy? edit? new? show? update?].each do |action|
|
%i[create? destroy? edit? new? show? update?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins only' do
|
it 'grants access to admins only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), ExternalUser.new)
|
expect(policy).to permit(build(:admin), ExternalUser.new)
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), ExternalUser.new)
|
expect(policy).not_to permit(build(factory_name), ExternalUser.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -19,10 +19,10 @@ describe ExternalUserPolicy do
|
|||||||
[:index?].each do |action|
|
[:index?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins and teachers only' do
|
it 'grants access to admins and teachers only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), ExternalUser.new)
|
expect(policy).to permit(build(:admin), ExternalUser.new)
|
||||||
expect(policy).to permit(FactoryBot.build(:teacher), ExternalUser.new)
|
expect(policy).to permit(build(:teacher), ExternalUser.new)
|
||||||
[:external_user].each do |factory_name|
|
[:external_user].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), ExternalUser.new)
|
expect(policy).not_to permit(build(factory_name), ExternalUser.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,12 +5,12 @@ require 'rails_helper'
|
|||||||
describe FileTypePolicy do
|
describe FileTypePolicy do
|
||||||
subject(:policy) { described_class }
|
subject(:policy) { described_class }
|
||||||
|
|
||||||
let(:file_type) { FactoryBot.build(:dot_rb) }
|
let(:file_type) { build(:dot_rb) }
|
||||||
|
|
||||||
%i[destroy? edit? update? new? create? index? show?].each do |action|
|
%i[destroy? edit? update? new? create? index? show?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), file_type)
|
expect(policy).to permit(build(:admin), file_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
@ -19,7 +19,7 @@ describe FileTypePolicy do
|
|||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file_type)
|
expect(policy).not_to permit(build(factory_name), file_type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,9 +8,9 @@ describe InternalUserPolicy do
|
|||||||
%i[create? edit? index? new? show? update?].each do |action|
|
%i[create? edit? index? new? show? update?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins only' do
|
it 'grants access to admins only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), InternalUser.new)
|
expect(policy).to permit(build(:admin), InternalUser.new)
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), InternalUser.new)
|
expect(policy).not_to permit(build(factory_name), InternalUser.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -20,16 +20,16 @@ describe InternalUserPolicy do
|
|||||||
context 'with an admin user' do
|
context 'with an admin user' do
|
||||||
it 'grants access to no one' do
|
it 'grants access to no one' do
|
||||||
%i[admin external_user teacher].each do |factory_name|
|
%i[admin external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), FactoryBot.build(:admin))
|
expect(policy).not_to permit(build(factory_name), build(:admin))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a non-admin user' do
|
context 'with a non-admin user' do
|
||||||
it 'grants access to admins only' do
|
it 'grants access to admins only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), InternalUser.new)
|
expect(policy).to permit(build(:admin), InternalUser.new)
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), FactoryBot.build(:teacher))
|
expect(policy).not_to permit(build(factory_name), build(:teacher))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ describe SubmissionPolicy do
|
|||||||
permissions :create? do
|
permissions :create? do
|
||||||
it 'grants access to anyone' do
|
it 'grants access to anyone' do
|
||||||
%i[admin external_user teacher].each do |factory_name|
|
%i[admin external_user teacher].each do |factory_name|
|
||||||
expect(policy).to permit(FactoryBot.build(factory_name), Submission.new)
|
expect(policy).to permit(build(factory_name), Submission.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -16,21 +16,21 @@ describe SubmissionPolicy do
|
|||||||
%i[download_file? render_file? run? score? show? statistics? stop? test?].each do |action|
|
%i[download_file? render_file? run? score? show? statistics? stop? test?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), Submission.new)
|
expect(policy).to permit(build(:admin), Submission.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
user = FactoryBot.create(:external_user)
|
user = create(:external_user)
|
||||||
expect(policy).to permit(user, FactoryBot.build(:submission, exercise: Exercise.new, user_id: user.id, user_type: user.class.name))
|
expect(policy).to permit(user, build(:submission, exercise: Exercise.new, user_id: user.id, user_type: user.class.name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
permissions :index? do
|
permissions :index? do
|
||||||
it 'grants access to admins only' do
|
it 'grants access to admins only' do
|
||||||
expect(policy).to permit(FactoryBot.build(:admin), Submission.new)
|
expect(policy).to permit(build(:admin), Submission.new)
|
||||||
%i[external_user teacher].each do |factory_name|
|
%i[external_user teacher].each do |factory_name|
|
||||||
expect(policy).not_to permit(FactoryBot.build(factory_name), Submission.new)
|
expect(policy).not_to permit(build(factory_name), Submission.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ describe ExerciseService::CheckExternal do
|
|||||||
subject(:export_service) { described_class.new(uuid: uuid, codeharbor_link: codeharbor_link) }
|
subject(:export_service) { described_class.new(uuid: uuid, codeharbor_link: codeharbor_link) }
|
||||||
|
|
||||||
let(:uuid) { SecureRandom.uuid }
|
let(:uuid) { SecureRandom.uuid }
|
||||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||||
|
|
||||||
it 'assigns uuid' do
|
it 'assigns uuid' do
|
||||||
expect(export_service.instance_variable_get(:@uuid)).to be uuid
|
expect(export_service.instance_variable_get(:@uuid)).to be uuid
|
||||||
@ -22,7 +22,7 @@ describe ExerciseService::CheckExternal do
|
|||||||
subject(:check_external_service) { described_class.call(uuid: uuid, codeharbor_link: codeharbor_link) }
|
subject(:check_external_service) { described_class.call(uuid: uuid, codeharbor_link: codeharbor_link) }
|
||||||
|
|
||||||
let(:uuid) { SecureRandom.uuid }
|
let(:uuid) { SecureRandom.uuid }
|
||||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||||
let(:response) { {}.to_json }
|
let(:response) { {}.to_json }
|
||||||
|
|
||||||
before { stub_request(:post, codeharbor_link.check_uuid_url).to_return(body: response) }
|
before { stub_request(:post, codeharbor_link.check_uuid_url).to_return(body: response) }
|
||||||
|
@ -6,8 +6,8 @@ RSpec.describe ExerciseService::PushExternal do
|
|||||||
describe '.new' do
|
describe '.new' do
|
||||||
subject(:push_external) { described_class.new(zip: zip, codeharbor_link: codeharbor_link) }
|
subject(:push_external) { described_class.new(zip: zip, codeharbor_link: codeharbor_link) }
|
||||||
|
|
||||||
let(:zip) { ProformaService::ExportTask.call(exercise: FactoryBot.build(:dummy)) }
|
let(:zip) { ProformaService::ExportTask.call(exercise: build(:dummy)) }
|
||||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||||
|
|
||||||
it 'assigns zip' do
|
it 'assigns zip' do
|
||||||
expect(push_external.instance_variable_get(:@zip)).to be zip
|
expect(push_external.instance_variable_get(:@zip)).to be zip
|
||||||
@ -21,8 +21,8 @@ RSpec.describe ExerciseService::PushExternal do
|
|||||||
describe '#execute' do
|
describe '#execute' do
|
||||||
subject(:push_external) { described_class.call(zip: zip, codeharbor_link: codeharbor_link) }
|
subject(:push_external) { described_class.call(zip: zip, codeharbor_link: codeharbor_link) }
|
||||||
|
|
||||||
let(:zip) { ProformaService::ExportTask.call(exercise: FactoryBot.build(:dummy)) }
|
let(:zip) { ProformaService::ExportTask.call(exercise: build(:dummy)) }
|
||||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||||
let(:status) { 200 }
|
let(:status) { 200 }
|
||||||
let(:response) { '' }
|
let(:response) { '' }
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
describe '.new' do
|
describe '.new' do
|
||||||
subject(:convert_to_task) { described_class.new(exercise: exercise) }
|
subject(:convert_to_task) { described_class.new(exercise: exercise) }
|
||||||
|
|
||||||
let(:exercise) { FactoryBot.build(:dummy) }
|
let(:exercise) { build(:dummy) }
|
||||||
|
|
||||||
it 'assigns exercise' do
|
it 'assigns exercise' do
|
||||||
expect(convert_to_task.instance_variable_get(:@exercise)).to be exercise
|
expect(convert_to_task.instance_variable_get(:@exercise)).to be exercise
|
||||||
@ -18,7 +18,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
|
|
||||||
let(:convert_to_task) { described_class.new(exercise: exercise) }
|
let(:convert_to_task) { described_class.new(exercise: exercise) }
|
||||||
let(:exercise) do
|
let(:exercise) do
|
||||||
FactoryBot.create(:dummy,
|
create(:dummy,
|
||||||
instructions: 'instruction',
|
instructions: 'instruction',
|
||||||
uuid: SecureRandom.uuid,
|
uuid: SecureRandom.uuid,
|
||||||
files: files + tests)
|
files: files + tests)
|
||||||
@ -46,7 +46,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
|
|
||||||
context 'when exercise has a mainfile' do
|
context 'when exercise has a mainfile' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { FactoryBot.build(:file) }
|
let(:file) { build(:file) }
|
||||||
|
|
||||||
it 'creates a task-file with the correct attributes' do
|
it 'creates a task-file with the correct attributes' do
|
||||||
expect(task.files.first).to have_attributes(
|
expect(task.files.first).to have_attributes(
|
||||||
@ -64,7 +64,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
|
|
||||||
context 'when exercise has a regular file' do
|
context 'when exercise has a regular file' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { FactoryBot.build(:file, role: 'regular_file', hidden: hidden, read_only: read_only) }
|
let(:file) { build(:file, role: 'regular_file', hidden: hidden, read_only: read_only) }
|
||||||
let(:hidden) { true }
|
let(:hidden) { true }
|
||||||
let(:read_only) { true }
|
let(:read_only) { true }
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when file has an attachment' do
|
context 'when file has an attachment' do
|
||||||
let(:file) { FactoryBot.build(:file, :image, role: 'regular_file') }
|
let(:file) { build(:file, :image, role: 'regular_file') }
|
||||||
|
|
||||||
it 'creates a task-file with the correct attributes' do
|
it 'creates a task-file with the correct attributes' do
|
||||||
expect(task.files.first).to have_attributes(
|
expect(task.files.first).to have_attributes(
|
||||||
@ -112,7 +112,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
|
|
||||||
context 'when exercise has a file with role reference implementation' do
|
context 'when exercise has a file with role reference implementation' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { FactoryBot.build(:file, role: 'reference_implementation') }
|
let(:file) { build(:file, role: 'reference_implementation') }
|
||||||
|
|
||||||
it 'creates a task with one model-solution' do
|
it 'creates a task with one model-solution' do
|
||||||
expect(task.model_solutions).to have(1).item
|
expect(task.model_solutions).to have(1).item
|
||||||
@ -140,7 +140,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise has multiple files with role reference implementation' do
|
context 'when exercise has multiple files with role reference implementation' do
|
||||||
let(:files) { FactoryBot.build_list(:file, 2, role: 'reference_implementation') }
|
let(:files) { build_list(:file, 2, role: 'reference_implementation') }
|
||||||
|
|
||||||
it 'creates a task with two model-solutions' do
|
it 'creates a task with two model-solutions' do
|
||||||
expect(task.model_solutions).to have(2).items
|
expect(task.model_solutions).to have(2).items
|
||||||
@ -149,7 +149,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
|
|
||||||
context 'when exercise has a test' do
|
context 'when exercise has a test' do
|
||||||
let(:tests) { [test_file] }
|
let(:tests) { [test_file] }
|
||||||
let(:test_file) { FactoryBot.build(:test_file) }
|
let(:test_file) { build(:test_file) }
|
||||||
# let(:file) { FactoryBot.build(:codeharbor_test_file) }
|
# let(:file) { FactoryBot.build(:codeharbor_test_file) }
|
||||||
|
|
||||||
it 'creates a task with one test' do
|
it 'creates a task with one test' do
|
||||||
@ -178,7 +178,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise_file is not hidden' do
|
context 'when exercise_file is not hidden' do
|
||||||
let(:test_file) { FactoryBot.create(:test_file, hidden: false) }
|
let(:test_file) { create(:test_file, hidden: false) }
|
||||||
|
|
||||||
it 'creates the test file with the correct attribute' do
|
it 'creates the test file with the correct attribute' do
|
||||||
expect(task.tests.first.files.first).to have_attributes(visible: 'yes')
|
expect(task.tests.first.files.first).to have_attributes(visible: 'yes')
|
||||||
@ -187,7 +187,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise has multiple tests' do
|
context 'when exercise has multiple tests' do
|
||||||
let(:tests) { FactoryBot.build_list(:test_file, 2) }
|
let(:tests) { build_list(:test_file, 2) }
|
||||||
|
|
||||||
it 'creates a task with two tests' do
|
it 'creates a task with two tests' do
|
||||||
expect(task.tests).to have(2).items
|
expect(task.tests).to have(2).items
|
||||||
|
@ -9,8 +9,8 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
subject(:convert_to_exercise_service) { described_class.new(task: task, user: user, exercise: exercise) }
|
subject(:convert_to_exercise_service) { described_class.new(task: task, user: user, exercise: exercise) }
|
||||||
|
|
||||||
let(:task) { Proforma::Task.new }
|
let(:task) { Proforma::Task.new }
|
||||||
let(:user) { FactoryBot.build(:teacher) }
|
let(:user) { build(:teacher) }
|
||||||
let(:exercise) { FactoryBot.build(:dummy) }
|
let(:exercise) { build(:dummy) }
|
||||||
|
|
||||||
it 'assigns task' do
|
it 'assigns task' do
|
||||||
expect(convert_to_exercise_service.instance_variable_get(:@task)).to be task
|
expect(convert_to_exercise_service.instance_variable_get(:@task)).to be task
|
||||||
@ -28,7 +28,7 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
describe '#execute' do
|
describe '#execute' do
|
||||||
subject(:convert_to_exercise_service) { described_class.call(task: task, user: user, exercise: exercise) }
|
subject(:convert_to_exercise_service) { described_class.call(task: task, user: user, exercise: exercise) }
|
||||||
|
|
||||||
before { FactoryBot.create(:dot_txt) }
|
before { create(:dot_txt) }
|
||||||
|
|
||||||
let(:task) do
|
let(:task) do
|
||||||
Proforma::Task.new(
|
Proforma::Task.new(
|
||||||
@ -44,7 +44,7 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
tests: tests
|
tests: tests
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
let(:files) { [] }
|
let(:files) { [] }
|
||||||
let(:tests) { [] }
|
let(:tests) { [] }
|
||||||
let(:model_solutions) { [] }
|
let(:model_solutions) { [] }
|
||||||
@ -301,7 +301,7 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
|
|
||||||
context 'when exercise is set' do
|
context 'when exercise is set' do
|
||||||
let(:exercise) do
|
let(:exercise) do
|
||||||
FactoryBot.create(
|
create(
|
||||||
:files,
|
:files,
|
||||||
title: 'exercise-title',
|
title: 'exercise-title',
|
||||||
description: 'exercise-description',
|
description: 'exercise-description',
|
||||||
|
@ -6,7 +6,7 @@ describe ProformaService::ExportTask do
|
|||||||
describe '.new' do
|
describe '.new' do
|
||||||
subject(:export_task) { described_class.new(exercise: exercise) }
|
subject(:export_task) { described_class.new(exercise: exercise) }
|
||||||
|
|
||||||
let(:exercise) { FactoryBot.build(:dummy) }
|
let(:exercise) { build(:dummy) }
|
||||||
|
|
||||||
it 'assigns exercise' do
|
it 'assigns exercise' do
|
||||||
expect(export_task.instance_variable_get(:@exercise)).to be exercise
|
expect(export_task.instance_variable_get(:@exercise)).to be exercise
|
||||||
@ -25,7 +25,7 @@ describe ProformaService::ExportTask do
|
|||||||
subject(:export_task) { described_class.call(exercise: exercise) }
|
subject(:export_task) { described_class.call(exercise: exercise) }
|
||||||
|
|
||||||
let(:task) { Proforma::Task.new }
|
let(:task) { Proforma::Task.new }
|
||||||
let(:exercise) { FactoryBot.build(:dummy) }
|
let(:exercise) { build(:dummy) }
|
||||||
let(:exporter) { instance_double('Proforma::Exporter', perform: 'zip') }
|
let(:exporter) { instance_double('Proforma::Exporter', perform: 'zip') }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -7,7 +7,7 @@ describe ProformaService::Import do
|
|||||||
subject(:import_service) { described_class.new(zip: zip, user: user) }
|
subject(:import_service) { described_class.new(zip: zip, user: user) }
|
||||||
|
|
||||||
let(:zip) { Tempfile.new('proforma_test_zip_file') }
|
let(:zip) { Tempfile.new('proforma_test_zip_file') }
|
||||||
let(:user) { FactoryBot.build(:teacher) }
|
let(:user) { build(:teacher) }
|
||||||
|
|
||||||
it 'assigns zip' do
|
it 'assigns zip' do
|
||||||
expect(import_service.instance_variable_get(:@zip)).to be zip
|
expect(import_service.instance_variable_get(:@zip)).to be zip
|
||||||
@ -21,11 +21,11 @@ describe ProformaService::Import do
|
|||||||
describe '#execute' do
|
describe '#execute' do
|
||||||
subject(:import_service) { described_class.call(zip: zip_file, user: import_user) }
|
subject(:import_service) { described_class.call(zip: zip_file, user: import_user) }
|
||||||
|
|
||||||
let(:user) { FactoryBot.create(:teacher) }
|
let(:user) { create(:teacher) }
|
||||||
let(:import_user) { user }
|
let(:import_user) { user }
|
||||||
let(:zip_file) { Tempfile.new('proforma_test_zip_file', encoding: 'ascii-8bit') }
|
let(:zip_file) { Tempfile.new('proforma_test_zip_file', encoding: 'ascii-8bit') }
|
||||||
let(:exercise) do
|
let(:exercise) do
|
||||||
FactoryBot.create(:dummy,
|
create(:dummy,
|
||||||
instructions: 'instruction',
|
instructions: 'instruction',
|
||||||
execution_environment: execution_environment,
|
execution_environment: execution_environment,
|
||||||
files: files + tests,
|
files: files + tests,
|
||||||
@ -34,7 +34,7 @@ describe ProformaService::Import do
|
|||||||
end
|
end
|
||||||
|
|
||||||
let(:uuid) { nil }
|
let(:uuid) { nil }
|
||||||
let(:execution_environment) { FactoryBot.build(:java) }
|
let(:execution_environment) { build(:java) }
|
||||||
let(:files) { [] }
|
let(:files) { [] }
|
||||||
let(:tests) { [] }
|
let(:tests) { [] }
|
||||||
let(:exporter) { ProformaService::ExportTask.call(exercise: exercise.reload).string }
|
let(:exporter) { ProformaService::ExportTask.call(exercise: exercise.reload).string }
|
||||||
@ -78,12 +78,12 @@ describe ProformaService::Import do
|
|||||||
|
|
||||||
context 'when exercise has a mainfile' do
|
context 'when exercise has a mainfile' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { FactoryBot.build(:file) }
|
let(:file) { build(:file) }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
|
|
||||||
context 'when the mainfile is very large' do
|
context 'when the mainfile is very large' do
|
||||||
let(:file) { FactoryBot.build(:file, content: 'test' * (10**5)) }
|
let(:file) { build(:file, content: 'test' * (10**5)) }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
end
|
end
|
||||||
@ -91,12 +91,12 @@ describe ProformaService::Import do
|
|||||||
|
|
||||||
context 'when exercise has a regular file' do
|
context 'when exercise has a regular file' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { FactoryBot.build(:file, role: 'regular_file') }
|
let(:file) { build(:file, role: 'regular_file') }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
|
|
||||||
context 'when file has an attachment' do
|
context 'when file has an attachment' do
|
||||||
let(:file) { FactoryBot.build(:file, :image, role: 'regular_file') }
|
let(:file) { build(:file, :image, role: 'regular_file') }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
end
|
end
|
||||||
@ -104,26 +104,26 @@ describe ProformaService::Import do
|
|||||||
|
|
||||||
context 'when exercise has a file with role reference implementation' do
|
context 'when exercise has a file with role reference implementation' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { FactoryBot.build(:file, role: 'reference_implementation', read_only: true) }
|
let(:file) { build(:file, role: 'reference_implementation', read_only: true) }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise has multiple files with role reference implementation' do
|
context 'when exercise has multiple files with role reference implementation' do
|
||||||
let(:files) { FactoryBot.build_list(:file, 2, role: 'reference_implementation', read_only: true) }
|
let(:files) { build_list(:file, 2, role: 'reference_implementation', read_only: true) }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise has a test' do
|
context 'when exercise has a test' do
|
||||||
let(:tests) { [test] }
|
let(:tests) { [test] }
|
||||||
let(:test) { FactoryBot.build(:test_file) }
|
let(:test) { build(:test_file) }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when exercise has multiple tests' do
|
context 'when exercise has multiple tests' do
|
||||||
let(:tests) { FactoryBot.build_list(:test_file, 2) }
|
let(:tests) { build_list(:test_file, 2) }
|
||||||
|
|
||||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||||
end
|
end
|
||||||
@ -153,7 +153,7 @@ describe ProformaService::Import do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when another user imports the exercise' do
|
context 'when another user imports the exercise' do
|
||||||
let(:import_user) { FactoryBot.create(:teacher) }
|
let(:import_user) { create(:teacher) }
|
||||||
|
|
||||||
it 'raises a proforma error' do
|
it 'raises a proforma error' do
|
||||||
expect { imported_exercise.save! }.to raise_error Proforma::ExerciseNotOwned
|
expect { imported_exercise.save! }.to raise_error Proforma::ExerciseNotOwned
|
||||||
|
@ -4,3 +4,7 @@ require 'factory_bot'
|
|||||||
|
|
||||||
# Use "old" FactoryBot default to allow auto-creating associations for #build
|
# Use "old" FactoryBot default to allow auto-creating associations for #build
|
||||||
FactoryBot.use_parent_strategy = false
|
FactoryBot.use_parent_strategy = false
|
||||||
|
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.include FactoryBot::Syntax::Methods
|
||||||
|
end
|
||||||
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||||||
|
|
||||||
describe FileUploader do
|
describe FileUploader do
|
||||||
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
|
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
|
||||||
let(:uploader) { described_class.new(FactoryBot.create(:file)) }
|
let(:uploader) { described_class.new(create(:file)) }
|
||||||
|
|
||||||
before { uploader.store!(File.open(file_path, 'r')) }
|
before { uploader.store!(File.open(file_path, 'r')) }
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'execution_environments/shell.html.slim' do
|
describe 'execution_environments/shell.html.slim' do
|
||||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
let(:execution_environment) { create(:ruby) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
assign(:execution_environment, execution_environment)
|
assign(:execution_environment, execution_environment)
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'exercises/implement.html.slim' do
|
describe 'exercises/implement.html.slim' do
|
||||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
let(:exercise) { create(:fibonacci) }
|
||||||
let(:files) { exercise.files.visible }
|
let(:files) { exercise.files.visible }
|
||||||
let(:non_binary_files) { files.reject {|file| file.file_type.binary? } }
|
let(:non_binary_files) { files.reject {|file| file.file_type.binary? } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
assign(:current_user, FactoryBot.create(:admin))
|
assign(:current_user, create(:admin))
|
||||||
assign(:exercise, exercise)
|
assign(:exercise, exercise)
|
||||||
assign(:files, files)
|
assign(:files, files)
|
||||||
assign(:paths, [])
|
assign(:paths, [])
|
||||||
|
Reference in New Issue
Block a user