diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-15 11:12:17 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-15 11:12:17 +0200 |
| commit | f598cc789789bcde01e3c703d9149204247c0a46 (patch) | |
| tree | a95d42cbd39649c71065c1660f7e955a41759d79 /app/models/note.rb | |
| parent | bda7fe38d0b0e39a408c4eb44374a330c24c3a49 (diff) | |
| download | gitlab-ce-f598cc789789bcde01e3c703d9149204247c0a46.tar.gz | |
change logic on line_code
Diffstat (limited to 'app/models/note.rb')
| -rw-r--r-- | app/models/note.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 3ad03cc601b..ded126b4bf1 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -33,7 +33,7 @@ class Note < ActiveRecord::Base delegate :name, :email, to: :author, prefix: true validates :note, :project, presence: true - validates :line_code, format: { with: /\A\d+_\d+_\d+\Z/ }, allow_blank: true + validates :line_code, format: { with: /\A[a-z0-9]+_\d+_\d+\Z/ }, allow_blank: true validates :attachment, file_size: { maximum: 10.megabytes.to_i } validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } @@ -69,11 +69,17 @@ class Note < ActiveRecord::Base end def diff - noteable.diffs[diff_file_index] + if noteable.diffs.present? + noteable.diffs.select do |d| + if d.b_path + Digest::SHA1.hexdigest(d.b_path) == diff_file_index + end + end.first + end end def diff_file_index - line_code.split('_')[0].to_i + line_code.split('_')[0] end def diff_file_name @@ -85,7 +91,7 @@ class Note < ActiveRecord::Base end def discussion_id - @discussion_id ||= [:discussion, noteable_type.underscore, noteable_id, line_code].join("-").to_sym + @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id, line_code].join("-").to_sym end # Returns true if this is a downvote note, |
