Skip to content

Commit da65936

Browse files
authored
Merge pull request #18 from CareMessagePlatform/bc_072
Fixed issue where updated snapshots would have missing nodes
2 parents 08e4c2d + 0fcf511 commit da65936

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [v0.7.2]
4+
5+
### Fixed
6+
- Fixed issue where updated snapshots would have missing nodes
7+
38
## [v0.7.1]
49

510
### Fixed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
rspec-request_snapshot (0.7.1)
4+
rspec-request_snapshot (0.7.2)
55
rspec (~> 3.0)
66

77
GEM

lib/rspec/request_snapshot/updaters/json.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def deep_update_hash(expected_json, stored_json)
2525
keys = expected_json.keys | stored_json.keys
2626
keys.each do |key|
2727
# If key present on expected and not stored, add it to stored
28-
if stored_json[key].nil?
28+
unless stored_json.key?(key)
2929
stored_json[key] = expected_json[key]
3030
next
3131
end
3232

3333
# If key only present on stored, remove it from stored
34-
if expected_json[key].nil?
34+
unless expected_json.key?(key)
3535
stored_json.delete(key)
3636
next
3737
end

lib/rspec/request_snapshot/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# rubocop:disable Style/ClassAndModuleChildren
44
module Rspec
55
module RequestSnapshot
6-
VERSION = "0.7.1"
6+
VERSION = "0.7.2"
77
end
88
end
99
# rubocop:enable Style/ClassAndModuleChildren
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"object": {
3+
"book": {
4+
"id": 1,
5+
"name": "Name",
6+
"created_at": "2019-06-10T12:25:20-07:00"
7+
}
8+
}
9+
}

spec/rspec/updaters_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
end
2929
end
3030

31+
context "when updating hash elements that contain nil on actual" do
32+
let(:snapshot_name) { "updaters/null_json" }
33+
let(:json) { { object: { book: { id: 10, name: "Name changed", created_at: nil } } }.to_json }
34+
35+
it "updates snapshot node value" do
36+
expected_json = JSON.pretty_generate(
37+
object: { book: { id: 1, name: "Name changed", created_at: "2019-06-10T12:25:20-07:00" } }
38+
)
39+
expect(File.read(snapshot_path)).to eq(expected_json)
40+
end
41+
end
42+
3143
context "when adding a new node" do
3244
let(:snapshot_name) { "updaters/add_json" }
3345
let(:json) { { object: { book: { id: 10, name: "Name changed", value: 29.99 } } }.to_json }

0 commit comments

Comments
 (0)