Commit f4e940d8 authored by Robert May's avatar Robert May

Cover sent_notification position JSON parsing

This provides a couple of specs and a fix to cover changes in how
JSON parsing will affect this method.
parent 0eb40aab
......@@ -82,6 +82,8 @@ class SentNotification < ApplicationRecord
if new_position.is_a?(Hash)
new_position = new_position.with_indifferent_access
new_position = Gitlab::Diff::Position.new(new_position)
else
new_position = nil
end
super(new_position)
......
......@@ -326,4 +326,26 @@ describe SentNotification do
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
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