Enable Rails/Validation

This commit is contained in:
Douwe Maan 2017-02-21 18:40:04 -06:00
parent 8df3eb6648
commit 5cd9c7c6ea
13 changed files with 19 additions and 33 deletions

View File

@ -941,6 +941,9 @@ Rails/OutputSafety:
Rails/TimeZone:
Enabled: false
Rails/Validation:
Enabled: true
Style/AlignParameters:
Enabled: false

View File

@ -38,23 +38,6 @@ RSpec/SingleArgumentMessageChain:
Exclude:
- 'spec/requests/api/internal_spec.rb'
# Cop supports --auto-correct.
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/Validation:
Exclude:
- 'app/models/ci/build.rb'
- 'app/models/ci/pipeline.rb'
- 'app/models/ci/runner_project.rb'
- 'app/models/ci/trigger.rb'
- 'app/models/commit_status.rb'
- 'app/models/members/group_member.rb'
- 'app/models/members/project_member.rb'
- 'app/models/pages_domain.rb'
- 'app/models/project.rb'
- 'app/models/protected_branch.rb'
- 'app/models/user.rb'
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.

View File

@ -23,7 +23,7 @@ module Ci
serialize :yaml_variables, Gitlab::Serializer::Ci::Variables
validates :coverage, numericality: true, allow_blank: true
validates_presence_of :ref
validates :ref, presence: true
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }

View File

@ -14,9 +14,9 @@ module Ci
has_many :builds, foreign_key: :commit_id
has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id
validates_presence_of :sha, unless: :importing?
validates_presence_of :ref, unless: :importing?
validates_presence_of :status, unless: :importing?
validates :sha, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
validates :status, presence: { unless: :importing? }
validate :valid_commit_sha, unless: :importing?
after_create :keep_around_commits, unless: :importing?

View File

@ -5,6 +5,6 @@ module Ci
belongs_to :runner
belongs_to :project, foreign_key: :gl_project_id
validates_uniqueness_of :runner_id, scope: :gl_project_id
validates :runner_id, uniqueness: { scope: :gl_project_id }
end
end

View File

@ -7,8 +7,8 @@ module Ci
belongs_to :project, foreign_key: :gl_project_id
has_many :trigger_requests, dependent: :destroy
validates_presence_of :token
validates_uniqueness_of :token
validates :token, presence: true
validates :token, uniqueness: true
before_validation :set_default_values

View File

@ -13,7 +13,7 @@ class CommitStatus < ActiveRecord::Base
validates :pipeline, presence: true, unless: :importing?
validates_presence_of :name
validates :name, presence: true
alias_attribute :author, :user

View File

@ -5,7 +5,7 @@ class GroupMember < Member
# Make sure group member points only to group as it source
default_value_for :source_type, SOURCE_TYPE
validates_format_of :source_type, with: /\ANamespace\z/
validates :source_type, format: { with: /\ANamespace\z/ }
default_scope { where(source_type: SOURCE_TYPE) }
def self.access_level_roles

View File

@ -7,7 +7,7 @@ class ProjectMember < Member
# Make sure project member points only to project as it source
default_value_for :source_type, SOURCE_TYPE
validates_format_of :source_type, with: /\AProject\z/
validates :source_type, format: { with: /\AProject\z/ }
validates :access_level, inclusion: { in: Gitlab::Access.values }
default_scope { where(source_type: SOURCE_TYPE) }

View File

@ -2,7 +2,7 @@ class PagesDomain < ActiveRecord::Base
belongs_to :project
validates :domain, hostname: true
validates_uniqueness_of :domain, case_sensitive: false
validates :domain, uniqueness: { case_sensitive: false }
validates :certificate, certificate: true, allow_nil: true, allow_blank: true
validates :key, certificate_key: true, allow_nil: true, allow_blank: true

View File

@ -191,8 +191,8 @@ class Project < ActiveRecord::Base
format: { with: Gitlab::Regex.project_path_regex,
message: Gitlab::Regex.project_path_regex_message }
validates :namespace, presence: true
validates_uniqueness_of :name, scope: :namespace_id
validates_uniqueness_of :path, scope: :namespace_id
validates :name, uniqueness: { scope: :namespace_id }
validates :path, uniqueness: { scope: :namespace_id }
validates :import_url, addressable_url: true, if: :external_import?
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create

View File

@ -8,8 +8,8 @@ class ProtectedBranch < ActiveRecord::Base
has_many :merge_access_levels, dependent: :destroy
has_many :push_access_levels, dependent: :destroy
validates_length_of :merge_access_levels, is: 1, message: "are restricted to a single instance per protected branch."
validates_length_of :push_access_levels, is: 1, message: "are restricted to a single instance per protected branch."
validates :merge_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." }
validates :push_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." }
accepts_nested_attributes_for :push_access_levels
accepts_nested_attributes_for :merge_access_levels

View File

@ -104,7 +104,7 @@ class User < ActiveRecord::Base
#
# Note: devise :validatable above adds validations for :email and :password
validates :name, presence: true
validates_confirmation_of :email
validates :email, confirmation: true
validates :notification_email, presence: true
validates :notification_email, email: true, if: ->(user) { user.notification_email != user.email }
validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true