Commit f5ceb638 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-sent-notification-position' into 'master'

Allow SentNotification#position to be set as string or hash

Fixes https://sentry.gitlap.com/gitlab/staginggitlabcom/issues/8491/

See merge request !5189
parents ef9ba905 ea40c08d
......@@ -72,6 +72,19 @@ class SentNotification < ActiveRecord::Base
end
end
def position=(new_position)
if new_position.is_a?(String)
new_position = JSON.parse(new_position) rescue nil
end
if new_position.is_a?(Hash)
new_position = new_position.with_indifferent_access
new_position = Gitlab::Diff::Position.new(new_position)
end
super(new_position)
end
def to_param
self.reply_key
end
......
......@@ -293,6 +293,30 @@ describe NotificationService, services: true do
end
end
end
context "merge request diff note" do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, source_project: project, assignee: user) }
let(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request) }
before do
build_team(note.project)
project.team << [merge_request.author, :master]
project.team << [merge_request.assignee, :master]
end
describe :new_note do
it "records sent notifications" do
# Ensure create SentNotification by noteable = merge_request 6 times, not noteable = note
expect(SentNotification).to receive(:record_note).with(note, any_args).exactly(4).times.and_call_original
notification.new_note(note)
expect(SentNotification.last.position).to eq(note.position)
end
end
end
end
describe 'Issues' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment