Commit b3c1d0d8df28d54c094b3980563394db97e25897

Authored by Dmitriy Zaporozhets
1 parent acbac26a

Added allow_blank to model validations

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/controllers/application_controller.rb
  1 +require 'gon'
  2 +
1 class ApplicationController < ActionController::Base 3 class ApplicationController < ActionController::Base
2 before_filter :authenticate_user! 4 before_filter :authenticate_user!
3 before_filter :reject_blocked! 5 before_filter :reject_blocked!
app/models/project.rb
@@ -77,7 +77,7 @@ class Project &lt; ActiveRecord::Base @@ -77,7 +77,7 @@ class Project &lt; ActiveRecord::Base
77 77
78 # Validations 78 # Validations
79 validates :creator, presence: true 79 validates :creator, presence: true
80 - validates :description, length: { within: 0..2000 } 80 + validates :description, length: { maximum: 2000 }, allow_blank: true
81 validates :name, presence: true, length: { within: 0..255 }, 81 validates :name, presence: true, length: { within: 0..255 },
82 format: { with: Gitlab::Regex.project_name_regex, 82 format: { with: Gitlab::Regex.project_name_regex,
83 message: "only letters, digits, spaces & '_' '-' '.' allowed. Letter or digit should be first" } 83 message: "only letters, digits, spaces & '_' '-' '.' allowed. Letter or digit should be first" }
@@ -87,7 +87,7 @@ class Project &lt; ActiveRecord::Base @@ -87,7 +87,7 @@ class Project &lt; ActiveRecord::Base
87 message: "only letters, digits & '_' '-' '.' allowed. Letter or digit should be first" } 87 message: "only letters, digits & '_' '-' '.' allowed. Letter or digit should be first" }
88 validates :issues_enabled, :wall_enabled, :merge_requests_enabled, 88 validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
89 :wiki_enabled, inclusion: { in: [true, false] } 89 :wiki_enabled, inclusion: { in: [true, false] }
90 - validates :issues_tracker_id, length: { within: 0..255 } 90 + validates :issues_tracker_id, length: { maximum: 255 }, allow_blank: true
91 91
92 validates :namespace, presence: true 92 validates :namespace, presence: true
93 validates_uniqueness_of :name, scope: :namespace_id 93 validates_uniqueness_of :name, scope: :namespace_id
app/models/user.rb
@@ -104,7 +104,7 @@ class User &lt; ActiveRecord::Base @@ -104,7 +104,7 @@ class User &lt; ActiveRecord::Base
104 # 104 #
105 validates :name, presence: true 105 validates :name, presence: true
106 validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ } 106 validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ }
107 - validates :bio, length: { within: 0..255 } 107 + validates :bio, length: { maximum: 255 }, allow_blank: true
108 validates :extern_uid, allow_blank: true, uniqueness: {scope: :provider} 108 validates :extern_uid, allow_blank: true, uniqueness: {scope: :provider}
109 validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0} 109 validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0}
110 validates :username, presence: true, uniqueness: true, 110 validates :username, presence: true, uniqueness: true,