Commit 1e4bbff2 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '20003-newnoteworker-failing-repeatedly-with-argumenterror-wrong-number-of-arguments' into 'master'

Ensure to_json methods take optional argument

If only Ruby had static checking for interfaces like this 😀 

Closes #20003.

See merge request !5359
parents 1ae2be23 4f0780cc
...@@ -73,8 +73,8 @@ module Gitlab ...@@ -73,8 +73,8 @@ module Gitlab
diff_refs.complete? diff_refs.complete?
end end
def to_json def to_json(opts = nil)
JSON.generate(self.to_h) JSON.generate(self.to_h, opts)
end end
def type def type
......
...@@ -8,8 +8,8 @@ module Gitlab ...@@ -8,8 +8,8 @@ module Gitlab
@message = message @message = message
end end
def to_json def to_json(opts = nil)
{ status: @status, message: @message }.to_json { status: @status, message: @message }.to_json(opts)
end end
end end
end end
...@@ -338,4 +338,28 @@ describe Gitlab::Diff::Position, lib: true do ...@@ -338,4 +338,28 @@ describe Gitlab::Diff::Position, lib: true do
end end
end end
end end
describe "#to_json" do
let(:hash) do
{
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
base_sha: nil,
head_sha: nil,
start_sha: nil
}
end
let(:diff_position) { described_class.new(hash) }
it "returns the position as JSON" do
expect(JSON.parse(diff_position.to_json)).to eq(hash.stringify_keys)
end
it "works when nested under another hash" do
expect(JSON.parse(JSON.generate(pos: diff_position))).to eq('pos' => hash.stringify_keys)
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