Commit 565f7f09 authored by Stan Hu's avatar Stan Hu

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

json gem upgrade to 2.3.0

See merge request gitlab-org/gitlab!30852
parents 3effc546 c595a63b
......@@ -496,3 +496,6 @@ gem 'lockbox', '~> 0.3.3'
# Email validation
gem 'valid_email', '~> 0.1'
# JSON
gem 'json', '~> 2.3.0'
......@@ -555,7 +555,7 @@ GEM
character_set (~> 1.1)
regexp_parser (~> 1.1)
regexp_property_values (~> 0.3)
json (1.8.6)
json (2.3.0)
json-jwt (1.11.0)
activesupport (>= 4.2)
aes_key_wrap
......@@ -1280,6 +1280,7 @@ DEPENDENCIES
invisible_captcha (~> 0.12.1)
jira-ruby (~> 2.0.0)
js_regex (~> 3.1)
json (~> 2.3.0)
json-schema (~> 2.8.0)
jwt (~> 2.1.0)
kaminari (~> 1.0)
......
---
title: Upgrade json gem to 2.3.0
merge_request: 30852
author:
type: performance
......@@ -17,18 +17,16 @@ RSpec.describe Gitlab::Json do
expect(subject.parse('[{ "foo": "bar" }]')).to eq([{ "foo" => "bar" }])
end
# These tests will change expectations when the gem is upgraded
it "raises an error on a string" do
expect { subject.parse('"foo"') }.to raise_error(JSON::ParserError)
it "parses a string" do
expect(subject.parse('"foo"', legacy_mode: false)).to eq("foo")
end
it "raises an error on a true bool" do
expect { subject.parse("true") }.to raise_error(JSON::ParserError)
it "parses a true bool" do
expect(subject.parse("true", legacy_mode: false)).to be(true)
end
it "raises an error on a false bool" do
expect { subject.parse("false") }.to raise_error(JSON::ParserError)
it "parses a false bool" do
expect(subject.parse("false", legacy_mode: false)).to be(false)
end
end
......@@ -53,6 +51,32 @@ RSpec.describe Gitlab::Json do
expect { subject.parse("false", legacy_mode: true) }.to raise_error(JSON::ParserError)
end
end
context "feature flag is disabled" do
before do
stub_feature_flags(json_wrapper_legacy_mode: false)
end
it "parses an object" do
expect(subject.parse('{ "foo": "bar" }', legacy_mode: true)).to eq({ "foo" => "bar" })
end
it "parses an array" do
expect(subject.parse('[{ "foo": "bar" }]', legacy_mode: true)).to eq([{ "foo" => "bar" }])
end
it "parses a string" do
expect(subject.parse('"foo"', legacy_mode: true)).to eq("foo")
end
it "parses a true bool" do
expect(subject.parse("true", legacy_mode: true)).to be(true)
end
it "parses a false bool" do
expect(subject.parse("false", legacy_mode: true)).to be(false)
end
end
end
describe ".parse!" do
......@@ -65,18 +89,16 @@ RSpec.describe Gitlab::Json do
expect(subject.parse!('[{ "foo": "bar" }]')).to eq([{ "foo" => "bar" }])
end
# These tests will change expectations when the gem is upgraded
it "raises an error on a string" do
expect { subject.parse!('"foo"') }.to raise_error(JSON::ParserError)
it "parses a string" do
expect(subject.parse!('"foo"', legacy_mode: false)).to eq("foo")
end
it "raises an error on a true bool" do
expect { subject.parse!("true") }.to raise_error(JSON::ParserError)
it "parses a true bool" do
expect(subject.parse!("true", legacy_mode: false)).to be(true)
end
it "raises an error on a false bool" do
expect { subject.parse!("false") }.to raise_error(JSON::ParserError)
it "parses a false bool" do
expect(subject.parse!("false", legacy_mode: false)).to be(false)
end
end
......@@ -101,6 +123,32 @@ RSpec.describe Gitlab::Json do
expect { subject.parse!("false", legacy_mode: true) }.to raise_error(JSON::ParserError)
end
end
context "feature flag is disabled" do
before do
stub_feature_flags(json_wrapper_legacy_mode: false)
end
it "parses an object" do
expect(subject.parse!('{ "foo": "bar" }', legacy_mode: true)).to eq({ "foo" => "bar" })
end
it "parses an array" do
expect(subject.parse!('[{ "foo": "bar" }]', legacy_mode: true)).to eq([{ "foo" => "bar" }])
end
it "parses a string" do
expect(subject.parse!('"foo"', legacy_mode: true)).to eq("foo")
end
it "parses a true bool" do
expect(subject.parse!("true", legacy_mode: true)).to be(true)
end
it "parses a false bool" do
expect(subject.parse!("false", legacy_mode: true)).to be(false)
end
end
end
describe ".dump" do
......
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