Commit a7efc44f authored by James Lopez's avatar James Lopez

Merge branch 'json-gem-upgrade-fix-1' into 'master'

Cover sent_notification position JSON parsing

See merge request gitlab-org/gitlab!31718
parents ada79afb f4e940d8
...@@ -82,6 +82,8 @@ class SentNotification < ApplicationRecord ...@@ -82,6 +82,8 @@ class SentNotification < ApplicationRecord
if new_position.is_a?(Hash) if new_position.is_a?(Hash)
new_position = new_position.with_indifferent_access new_position = new_position.with_indifferent_access
new_position = Gitlab::Diff::Position.new(new_position) new_position = Gitlab::Diff::Position.new(new_position)
else
new_position = nil
end end
super(new_position) super(new_position)
......
...@@ -326,4 +326,26 @@ describe SentNotification do ...@@ -326,4 +326,26 @@ describe SentNotification do
end end
end end
end end
describe "#position=" do
subject { build(:sent_notification, noteable: create(:issue)) }
it "doesn't accept non-hash JSON passed as a string" do
subject.position = "true"
expect(subject.attributes_before_type_cast["position"]).to be(nil)
end
it "does accept a position hash as a string" do
subject.position = '{ "base_sha": "test" }'
expect(subject.position.base_sha).to eq("test")
end
it "does accept a hash" do
subject.position = { "base_sha" => "test" }
expect(subject.position.base_sha).to eq("test")
end
end
end end
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