Skip to content

Commit

Permalink
Fix RichText double coercion error (#195)
Browse files Browse the repository at this point in the history
* Squash bug when nodes are visited coerced more then once in a request

* return the target if this node has already been coerced

* Add RichText double coercion spec
  • Loading branch information
dlitvakb authored Jan 23, 2019
1 parent d6f721a commit 7aca21a
Show file tree
Hide file tree
Showing 4 changed files with 482 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log

## Unreleased
### Fixed
* Fixed coercion error when same entry was included more than once in the same RichText field. [#194](https://github.com/contentful/contentful.rb/pull/194)

## 2.11.0
### Added
Expand Down
1 change: 1 addition & 0 deletions lib/contentful/coercions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def coerce_block(block, configuration)

def coerce_link(node, configuration)
return node unless node.key?('data') && node['data'].key?('target')
return node['data']['target'] unless node['data']['target'].is_a?(::Hash)
return node unless node['data']['target']['sys']['type'] == 'Link'

return nil if Support.unresolvable?(node['data']['target'], configuration[:errors])
Expand Down
19 changes: 19 additions & 0 deletions spec/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,25 @@ def test_dump(nyancat)
}
end

it 'doesnt hydrate the same entry twice - #194' do
vcr('entries/rich_text_hydration_issue') {
entry = nil

expect {
entry = create_client(
space: 'fds721b88p6b',
access_token: '45ba81cc69423fcd2e3f0a4779de29481bb5c11495bc7e14649a996cf984e98e',
raise_errors: true,
dynamic_entries: :auto,
gzip_encoded: false
).entry('1tBAu0wP9qAQEg6qCqMics')
}.not_to raise_error

expect(entry.children[0].id).to eq entry.children[1].id
expect(entry.children[0].body).to eq entry.children[1].body
}
end

it 'respects content in data attribute if its not a Link' do
vcr('entries/rich_text_nested_fields') {
entry = create_client(
Expand Down
Loading

0 comments on commit 7aca21a

Please sign in to comment.