diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-20 10:52:56 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-20 10:52:56 +0000 |
commit | 1e4bbff2ce8a26e232a5e23d84827276b097af5b (patch) | |
tree | 00310edfa6426e9917a532631d34cb1e46a2473c | |
parent | 1ae2be239a9ce32024a6de061dd850c68fbdb5c2 (diff) | |
parent | 4f0780cc04af34aeaab40d75373d22f015893cb6 (diff) | |
download | gitlab-ce-1e4bbff2ce8a26e232a5e23d84827276b097af5b.tar.gz |
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 :grinning:
Closes #20003.
See merge request !5359
-rw-r--r-- | lib/gitlab/diff/position.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/git_access_status.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/position_spec.rb | 24 |
3 files changed, 28 insertions, 4 deletions
diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb index 989fff8918e..2fdcf8d7838 100644 --- a/lib/gitlab/diff/position.rb +++ b/lib/gitlab/diff/position.rb @@ -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 diff --git a/lib/gitlab/git_access_status.rb b/lib/gitlab/git_access_status.rb index 5a806ff6e0d..09bb01be694 100644 --- a/lib/gitlab/git_access_status.rb +++ b/lib/gitlab/git_access_status.rb @@ -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 diff --git a/spec/lib/gitlab/diff/position_spec.rb b/spec/lib/gitlab/diff/position_spec.rb index cf28628cb96..10537bea008 100644 --- a/spec/lib/gitlab/diff/position_spec.rb +++ b/spec/lib/gitlab/diff/position_spec.rb @@ -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 |