Upgrade Rails to version 5.2.1 and adopt code & specs where necessary

Signed-off-by: Sebastian Serth <Sebastian.Serth@student.hpi.de>
This commit is contained in:
Sebastian Serth
2018-09-13 12:21:53 +02:00
parent 108190c242
commit de52db89f0
128 changed files with 786 additions and 422 deletions

View File

@@ -1,4 +1,4 @@
class AnomalyNotification < ActiveRecord::Base
class AnomalyNotification < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :exercise
belongs_to :exercise_collection

View File

@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@@ -1,4 +1,4 @@
class CodeHarborLink < ActiveRecord::Base
class CodeHarborLink < ApplicationRecord
validates :oauth2token, presence: true
validates :user_id, presence: true

View File

@@ -15,7 +15,7 @@ module CodeOcean
end
end
class File < ActiveRecord::Base
class File < ApplicationRecord
include DefaultValues
DEFAULT_WEIGHT = 1.0
@@ -28,12 +28,11 @@ module CodeOcean
before_validation :set_ancestor_values, if: :incomplete_descendent?
belongs_to :context, polymorphic: true
belongs_to :execution_environment
belongs_to :file
belongs_to :file, class_name: 'CodeOcean::File', optional: true # This is only required for submissions and is validated below
alias_method :ancestor, :file
belongs_to :file_type
has_many :files
has_many :files, class_name: 'CodeOcean::File'
has_many :testruns
has_many :comments
alias_method :descendants, :files
@@ -59,6 +58,7 @@ module CodeOcean
validates :role, inclusion: {in: ROLES}
validates :weight, if: :teacher_defined_test?, numericality: true, presence: true
validates :weight, absence: true, unless: :teacher_defined_test?
validates :file, presence: true if :context.is_a?(Submission)
validates_with FileNameValidator, fields: [:name, :path, :file_type_id]

View File

@@ -1,4 +1,4 @@
class Comment < ActiveRecord::Base
class Comment < ApplicationRecord
# inherit the creation module: encapsulates that this is a polymorphic user, offers some aliases and makes sure that all necessary attributes are set.
include Creation
attr_accessor :username, :date, :updated, :editable

View File

@@ -1,4 +1,4 @@
class Consumer < ActiveRecord::Base
class Consumer < ApplicationRecord
has_many :users
scope :with_users, -> { where('id IN (SELECT consumer_id FROM internal_users)') }

View File

@@ -1,4 +1,4 @@
class Error < ActiveRecord::Base
class Error < ApplicationRecord
belongs_to :execution_environment
scope :for_execution_environment, ->(execution_environment) { where(execution_environment_id: execution_environment.id) }

View File

@@ -1,4 +1,4 @@
class ErrorTemplate < ActiveRecord::Base
class ErrorTemplate < ApplicationRecord
belongs_to :execution_environment
has_and_belongs_to_many :error_template_attributes

View File

@@ -1,4 +1,4 @@
class ErrorTemplateAttribute < ActiveRecord::Base
class ErrorTemplateAttribute < ApplicationRecord
has_and_belongs_to_many :error_template
def to_s

View File

@@ -1,7 +1,7 @@
class Event < ActiveRecord::Base
class Event < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :exercise
belongs_to :file
belongs_to :file, class_name: 'CodeOcean::File'
validates :category, presence: true
validates :data, presence: true

View File

@@ -1,6 +1,6 @@
require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __FILE__)
class ExecutionEnvironment < ActiveRecord::Base
class ExecutionEnvironment < ApplicationRecord
include Creation
include DefaultValues

View File

@@ -1,7 +1,7 @@
require 'nokogiri'
require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __FILE__)
class Exercise < ActiveRecord::Base
class Exercise < ApplicationRecord
include Context
include Creation
include DefaultValues
@@ -23,8 +23,8 @@ class Exercise < ActiveRecord::Base
accepts_nested_attributes_for :exercise_tags
has_many :user_exercise_feedbacks
has_many :external_users, source: :user, source_type: ExternalUser, through: :submissions
has_many :internal_users, source: :user, source_type: InternalUser, through: :submissions
has_many :external_users, source: :user, source_type: 'ExternalUser', through: :submissions
has_many :internal_users, source: :user, source_type: 'InternalUser', through: :submissions
alias_method :users, :external_users
scope :with_submissions, -> { where('id IN (SELECT exercise_id FROM submissions)') }

View File

@@ -1,4 +1,4 @@
class ExerciseCollection < ActiveRecord::Base
class ExerciseCollection < ApplicationRecord
include TimeHelper
has_many :exercise_collection_items, dependent: :delete_all

View File

@@ -1,4 +1,4 @@
class ExerciseCollectionItem < ActiveRecord::Base
class ExerciseCollectionItem < ApplicationRecord
belongs_to :exercise_collection
belongs_to :exercise
end

View File

@@ -1,4 +1,4 @@
class ExerciseTag < ActiveRecord::Base
class ExerciseTag < ApplicationRecord
belongs_to :tag
belongs_to :exercise

View File

@@ -1,4 +1,4 @@
class ExternalUser < ActiveRecord::Base
class ExternalUser < ApplicationRecord
include User
validates :consumer_id, presence: true

View File

@@ -1,4 +1,4 @@
class FileTemplate < ActiveRecord::Base
class FileTemplate < ApplicationRecord
belongs_to :file_type

View File

@@ -1,6 +1,6 @@
require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __FILE__)
class FileType < ActiveRecord::Base
class FileType < ApplicationRecord
include Creation
include DefaultValues
@@ -11,7 +11,7 @@ class FileType < ActiveRecord::Base
after_initialize :set_default_values
has_many :execution_environments
has_many :files
has_many :files, class_name: 'CodeOcean::File'
has_many :file_templates
validates :binary, boolean_presence: true

View File

@@ -1,4 +1,4 @@
class Hint < ActiveRecord::Base
class Hint < ApplicationRecord
belongs_to :execution_environment
validates :execution_environment_id, presence: true

View File

@@ -1,4 +1,4 @@
class InternalUser < ActiveRecord::Base
class InternalUser < ApplicationRecord
include User
authenticates_with_sorcery!

View File

@@ -1,7 +1,7 @@
class Intervention < ActiveRecord::Base
class Intervention < ApplicationRecord
has_many :user_exercise_interventions
has_many :users, through: :user_exercise_interventions, source_type: "ExternalUser"
has_many :users, through: :user_exercise_interventions, source_type: 'ExternalUser'
def to_s
name

View File

@@ -1,4 +1,4 @@
class LtiParameter < ActiveRecord::Base
class LtiParameter < ApplicationRecord
belongs_to :consumer, foreign_key: "consumers_id"
belongs_to :exercise, foreign_key: "exercises_id"
belongs_to :external_user, foreign_key: "external_users_id"

View File

@@ -1,4 +1,4 @@
class ProxyExercise < ActiveRecord::Base
class ProxyExercise < ApplicationRecord
after_initialize :generate_token
after_initialize :set_reason

View File

@@ -1,5 +1,5 @@
# todo: reference to lti_param_model
class RemoteEvaluationMapping < ActiveRecord::Base
class RemoteEvaluationMapping < ApplicationRecord
before_create :generate_token, unless: :validation_token?
belongs_to :exercise
belongs_to :user

View File

@@ -1,4 +1,4 @@
class RequestForComment < ActiveRecord::Base
class RequestForComment < ApplicationRecord
include Creation
belongs_to :submission
belongs_to :exercise

View File

@@ -1,4 +1,4 @@
class Search < ActiveRecord::Base
class Search < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :exercise
end

View File

@@ -1,7 +1,6 @@
class StructuredError < ActiveRecord::Base
class StructuredError < ApplicationRecord
belongs_to :error_template
belongs_to :submission
belongs_to :file, class_name: 'CodeOcean::File'
has_many :structured_error_attributes

View File

@@ -1,4 +1,4 @@
class StructuredErrorAttribute < ActiveRecord::Base
class StructuredErrorAttribute < ApplicationRecord
belongs_to :structured_error
belongs_to :error_template_attribute

View File

@@ -1,4 +1,4 @@
class Submission < ActiveRecord::Base
class Submission < ApplicationRecord
include Context
include Creation

View File

@@ -1,4 +1,4 @@
class Subscription < ActiveRecord::Base
class Subscription < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :request_for_comment
end

View File

@@ -1,4 +1,4 @@
class Tag < ActiveRecord::Base
class Tag < ApplicationRecord
has_many :exercise_tags
has_many :exercises, through: :exercise_tags

View File

@@ -1,4 +1,4 @@
class Testrun < ActiveRecord::Base
class Testrun < ApplicationRecord
belongs_to :file, class_name: 'CodeOcean::File'
belongs_to :submission
end

View File

@@ -1,4 +1,4 @@
class UserExerciseFeedback < ActiveRecord::Base
class UserExerciseFeedback < ApplicationRecord
include Creation
belongs_to :exercise

View File

@@ -1,4 +1,4 @@
class UserExerciseIntervention < ActiveRecord::Base
class UserExerciseIntervention < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :intervention

View File

@@ -1,4 +1,4 @@
class UserProxyExerciseExercise < ActiveRecord::Base
class UserProxyExerciseExercise < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :exercise