Commit 4f0780cc authored by Sean McGivern's avatar Sean McGivern

Ensure to_json methods take optional argument

parent ef2edcc1
......@@ -73,8 +73,8 @@ module Gitlab
diff_refs.complete?
end
def to_json
JSON.generate(self.to_h)
def to_json(opts = nil)
JSON.generate(self.to_h, opts)
end
def type
......
......@@ -8,8 +8,8 @@ module Gitlab
@message = message
end
def to_json
{ status: @status, message: @message }.to_json
def to_json(opts = nil)
{ status: @status, message: @message }.to_json(opts)
end
end
end
......@@ -338,4 +338,28 @@ describe Gitlab::Diff::Position, lib: true do
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
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