diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-20 13:14:06 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-07-20 13:14:06 +0300 |
commit | 4f0780cc04af34aeaab40d75373d22f015893cb6 (patch) | |
tree | 75c450738516e5ba7a2035e57c95e852b314252a /spec/lib | |
parent | ef2edcc10007d5d838acf278ed1e9e0c07cdc4fc (diff) |
Ensure to_json methods take optional argument
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/diff/position_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
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 |