Commit ce1182b4 authored by Jan Provaznik's avatar Jan Provaznik

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

Cover diff_positionable_note JSON issue

See merge request gitlab-org/gitlab!31721
parents 17708336 3b5553d2
...@@ -23,6 +23,8 @@ module DiffPositionableNote ...@@ -23,6 +23,8 @@ module DiffPositionableNote
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)
elsif !new_position.is_a?(Gitlab::Diff::Position)
new_position = nil
end end
return if new_position == read_attribute(meth) return if new_position == read_attribute(meth)
......
...@@ -49,5 +49,29 @@ RSpec.shared_examples 'a valid diff positionable note' do |factory_on_commit| ...@@ -49,5 +49,29 @@ RSpec.shared_examples 'a valid diff positionable note' do |factory_on_commit|
expect(subject.errors).to have_key(:commit_id) expect(subject.errors).to have_key(:commit_id)
end end
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
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