Skip to content

Commit

Permalink
Merge pull request #118 from contentful/dl/fix-nil-string-serialization
Browse files Browse the repository at this point in the history
Fix string serialization
  • Loading branch information
realityking authored Jan 3, 2017
2 parents 003ce33 + 26cc62c commit 8e8cb1b
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 1 deletion.
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 Symbol/Text field serialization when value is `null` [#117](https://github.com/contentful/contentful.rb/issues/117)

## 1.2.1
### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/contentful/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Resource
# @private
# rubocop:disable Style/DoubleNegation
COERCIONS = {
string: ->(v) { v.to_s },
string: ->(v) { v.nil? ? nil : v.to_s },
integer: ->(v) { v.to_i },
float: ->(v) { v.to_f },
boolean: ->(v) { !!v },
Expand Down
12 changes: 12 additions & 0 deletions spec/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,16 @@ def test_dump(nyancat)
end
end
end

describe 'issues' do
it 'Symbol/Text field with null values should be serialized as nil - #117' do
vcr('entries/issue_117') {
client = create_client(space: '8jbbayggj9gj', access_token: '4ce0108f04e55c76476ba84ab0e6149734db73d67cd1b429323ef67f00977e07', dynamic_entries: :auto)
entry = client.entries.first

expect(entry.nil).to be_nil
expect(entry.nil).not_to eq ''
}
end
end
end
201 changes: 201 additions & 0 deletions spec/fixtures/vcr_cassettes/entries/issue_117.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e8cb1b

Please sign in to comment.