Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ rvm:
- jruby-19mode
before_install:
- git submodule update --init --recursive
- gem update bundler
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in json-patch.gemspec
gem 'minitest'
gem 'coveralls', require: false
gem 'rake', '~> 10.5.0' if RUBY_VERSION < '1.9.3'
gem 'rake' if RUBY_VERSION >= '1.9.3'
gemspec
6 changes: 4 additions & 2 deletions lib/json/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def add_operation(target_doc, path, value)
end

def add_object(target_doc, target_item, ref_token, value)
raise JSON::PatchError if target_item.nil?
raise JSON::PatchError if (target_item.nil? || !(Hash === target_item))
if ref_token.nil?
target_doc.replace(value)
else
Expand Down Expand Up @@ -130,8 +130,10 @@ def remove_operation(target_doc, path)

if Array === target_item
target_item.delete_at ref_token.to_i if valid_index?(target_item, ref_token)
else
elsif Hash === target_item
target_item.delete ref_token
else
raise JSON::PatchError
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/ietf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
describe "JSON::Patch.new" do
it "#{comment || spec['error'] || index}" do

target_doc = spec['doc'] if spec['doc']
target_doc = Marshal.load(Marshal.dump(spec['doc'])) if spec['doc']
operations_doc = spec['patch'] if spec['patch']
expected_doc = spec['expected'] if spec['expected']

Expand Down
23 changes: 23 additions & 0 deletions test/json-patch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@
end
end

describe "the target location MUST reference" do
let(:target_document) { %q'{"foo":"bar","baz":"wat"}' }
let(:operation_document) { %q'[{ "op": "add", "path": "/baz/quux", "value": "qux" }]' }

it "will raise exception if the target location is string (neither an array nor object)" do
assert_raises(JSON::PatchError) do
JSON.patch(target_document, operation_document)
end
end
end

=begin
TODO
When the operation is applied, the target location MUST reference one of:
Expand Down Expand Up @@ -176,6 +187,18 @@
end
end

describe "The target location MUST exist for the operation to be successful." do
let(:target_document) { %q'{"foo":"bar","baz":"qux"}' }
let(:operation_document) { %q'[{ "op": "remove", "path": "/foo/baz" }]' }

it "will rails an exception if the member in the path does not exist" do
assert_raises(JSON::PatchError) do
JSON.patch(target_document, operation_document)
end
end
end


end

describe "Section 4.3: The replace operation" do
Expand Down