summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-12-02 13:54:57 +0100
committerRémy Coutable <remy@rymai.me>2016-12-06 10:23:17 +0100
commit4e249d5baea99a52915025fc2827d01ab2d77c18 (patch)
tree98a0eaa592fdb17657e10a6cd9fe941b17c0253d /app
parent90c0f610e29976608dbfeeb63bc4763982c5dbc3 (diff)
downloadgitlab-ce-4e249d5baea99a52915025fc2827d01ab2d77c18.tar.gz
Use :maximum instead of :within for length validators with a 0..N range25209-improve-length-validators
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/variable.rb4
-rw-r--r--app/models/concerns/issuable.rb2
-rw-r--r--app/models/environment.rb2
-rw-r--r--app/models/key.rb16
-rw-r--r--app/models/namespace.rb14
-rw-r--r--app/models/project.rb4
-rw-r--r--app/models/snippet.rb8
7 files changed, 31 insertions, 19 deletions
diff --git a/app/models/ci/variable.rb b/app/models/ci/variable.rb
index 94d9e2b3208..2c8698d8b5d 100644
--- a/app/models/ci/variable.rb
+++ b/app/models/ci/variable.rb
@@ -4,10 +4,10 @@ module Ci
belongs_to :project, foreign_key: :gl_project_id
- validates_uniqueness_of :key, scope: :gl_project_id
validates :key,
presence: true,
- length: { within: 0..255 },
+ uniqueness: { scope: :gl_project_id },
+ length: { maximum: 255 },
format: { with: /\A[a-zA-Z0-9_]+\z/,
message: "can contain only letters, digits and '_'." }
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 69d8afc45da..0ea7b1b1098 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -41,7 +41,7 @@ module Issuable
has_one :metrics
validates :author, presence: true
- validates :title, presence: true, length: { within: 0..255 }
+ validates :title, presence: true, length: { maximum: 255 }
scope :authored, ->(user) { where(author_id: user) }
scope :assigned_to, ->(u) { where(assignee_id: u.id)}
diff --git a/app/models/environment.rb b/app/models/environment.rb
index a7f4156fc2e..96700143ddd 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -9,7 +9,7 @@ class Environment < ActiveRecord::Base
validates :name,
presence: true,
uniqueness: { scope: :project_id },
- length: { within: 0..255 },
+ length: { maximum: 255 },
format: { with: Gitlab::Regex.environment_name_regex,
message: Gitlab::Regex.environment_name_regex_message }
diff --git a/app/models/key.rb b/app/models/key.rb
index ff8dda2dc89..a5d25409730 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -8,10 +8,18 @@ class Key < ActiveRecord::Base
before_validation :generate_fingerprint
- validates :title, presence: true, length: { within: 0..255 }
- validates :key, presence: true, length: { within: 0..5000 }, format: { with: /\A(ssh|ecdsa)-.*\Z/ }
- validates :key, format: { without: /\n|\r/, message: 'should be a single line' }
- validates :fingerprint, uniqueness: true, presence: { message: 'cannot be generated' }
+ validates :title,
+ presence: true,
+ length: { maximum: 255 }
+ validates :key,
+ presence: true,
+ length: { maximum: 5000 },
+ format: { with: /\A(ssh|ecdsa)-.*\Z/ }
+ validates :key,
+ format: { without: /\n|\r/, message: 'should be a single line' }
+ validates :fingerprint,
+ uniqueness: true,
+ presence: { message: 'cannot be generated' }
delegate :name, :email, to: :user, prefix: true
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 891dffac648..7a545f752b6 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -12,17 +12,17 @@ class Namespace < ActiveRecord::Base
validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
validates :name,
- length: { within: 0..255 },
- namespace_name: true,
presence: true,
- uniqueness: true
+ uniqueness: true,
+ length: { maximum: 255 },
+ namespace_name: true
- validates :description, length: { within: 0..255 }
+ validates :description, length: { maximum: 255 }
validates :path,
- length: { within: 1..255 },
- namespace: true,
presence: true,
- uniqueness: { case_sensitive: false }
+ uniqueness: { case_sensitive: false },
+ length: { maximum: 255 },
+ namespace: true
delegate :name, to: :owner, allow_nil: true, prefix: true
diff --git a/app/models/project.rb b/app/models/project.rb
index f01cb613b85..e783e455a49 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -172,13 +172,13 @@ class Project < ActiveRecord::Base
validates :description, length: { maximum: 2000 }, allow_blank: true
validates :name,
presence: true,
- length: { within: 0..255 },
+ length: { maximum: 255 },
format: { with: Gitlab::Regex.project_name_regex,
message: Gitlab::Regex.project_name_regex_message }
validates :path,
presence: true,
project_path: true,
- length: { within: 0..255 },
+ length: { maximum: 255 },
format: { with: Gitlab::Regex.project_path_regex,
message: Gitlab::Regex.project_path_regex_message }
validates :namespace, presence: true
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 8ff4e7ae718..99493e561ab 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -27,9 +27,9 @@ class Snippet < ActiveRecord::Base
delegate :name, :email, to: :author, prefix: true, allow_nil: true
validates :author, presence: true
- validates :title, presence: true, length: { within: 0..255 }
+ validates :title, presence: true, length: { maximum: 255 }
validates :file_name,
- length: { within: 0..255 },
+ length: { maximum: 255 },
format: { with: Gitlab::Regex.file_name_regex,
message: Gitlab::Regex.file_name_regex_message }
@@ -94,6 +94,10 @@ class Snippet < ActiveRecord::Base
0
end
+ def file_name
+ super.to_s
+ end
+
# alias for compatibility with blobs and highlighting
def path
file_name