Commit 3b5553d2 authored by Robert May's avatar Robert May

Cover diff_positionable_note JSON issue

Adds spec coverage and a fix for handling of position fields
once the `json` gem upgrade has taken place.
parent 8e4aa5de
......@@ -23,6 +23,8 @@ module DiffPositionableNote
if new_position.is_a?(Hash)
new_position = new_position.with_indifferent_access
new_position = Gitlab::Diff::Position.new(new_position)
elsif !new_position.is_a?(Gitlab::Diff::Position)
new_position = nil
end
return if new_position == read_attribute(meth)
......
......@@ -49,5 +49,29 @@ RSpec.shared_examples 'a valid diff positionable note' do |factory_on_commit|
expect(subject.errors).to have_key(:commit_id)
end
end
%i(original_position position change_position).each do |method|
describe "#{method}=" do
it "doesn't accept non-hash JSON passed as a string" do
subject.send(:"#{method}=", "true")
expect(subject.attributes_before_type_cast[method.to_s]).to be(nil)
end
it "does accept a position hash as a string" do
subject.send(:"#{method}=", position.to_json)
expect(subject.position).to eq(position)
end
it "doesn't accept an array" do
subject.send(:"#{method}=", ["test"])
expect(subject.attributes_before_type_cast[method.to_s]).to be(nil)
end
it "does accept a hash" do
subject.send(:"#{method}=", position.to_h)
expect(subject.position).to eq(position)
end
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