summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-03-12 14:01:06 +0000
committerDouwe Maan <douwe@gitlab.com>2016-03-12 14:01:06 +0000
commit8ee1c0ffe538f1b0a4eecf859c3e79724ffae5ef (patch)
treec5cee2ec002cbfad3f70dbc4594581dbdce3f096 /app/models
parent0dae84200529dd97a0a3db3e7d56b7c33108fbe5 (diff)
parent01f6db4f643380d143772958b22d3f318b1db3a7 (diff)
downloadgitlab-ce-8ee1c0ffe538f1b0a4eecf859c3e79724ffae5ef.tar.gz
Merge branch 'rs-disallow-blank-line-code' into 'master'
Disallow blank (non-null) values for a Note's `line_code` attribute It's unclear how these blank values got added, but GitLab.com had a few: ``` irb(main):002:0> Note.where("line_code IS NOT NULL AND line_code = ''").count => 439 ``` We've added a migration to convert any existing records to use a NULL value when blank, and updated Note to set blank values to nil before validation. See merge request !3118
Diffstat (limited to 'app/models')
-rw-r--r--app/models/note.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 8b0610ff77e..2e084b5c80c 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -44,6 +44,7 @@ class Note < ActiveRecord::Base
delegate :name, :email, to: :author, prefix: true
before_validation :set_award!
+ before_validation :clear_blank_line_code!
validates :note, :project, presence: true
validates :note, uniqueness: { scope: [:author, :noteable_type, :noteable_id] }, if: ->(n) { n.is_award }
@@ -63,7 +64,7 @@ class Note < ActiveRecord::Base
scope :nonawards, ->{ where(is_award: false) }
scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) }
scope :inline, ->{ where("line_code IS NOT NULL") }
- scope :not_inline, ->{ where(line_code: [nil, '']) }
+ scope :not_inline, ->{ where(line_code: nil) }
scope :system, ->{ where(system: true) }
scope :user, ->{ where(system: false) }
scope :common, ->{ where(noteable_type: ["", nil]) }
@@ -375,6 +376,10 @@ class Note < ActiveRecord::Base
private
+ def clear_blank_line_code!
+ self.line_code = nil if self.line_code.blank?
+ end
+
def awards_supported?
(for_issue? || for_merge_request?) && !for_diff_line?
end