Skip to content

Commit

Permalink
Merge pull request #76 from contentful/fix-field-items
Browse files Browse the repository at this point in the history
Bugfix for `Field.items`
  • Loading branch information
dlitvakb committed Nov 5, 2015
2 parents 2d4aa0e + f6aa943 commit 6686e13
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* `Sync API` now works with `:raw_mode` enabled [#68](https://github.com/contentful/contentful.rb/issues/68)
* Handles multiple locales when requesting with `locale: "*"` [contentful_middleman/#39](https://github.com/contentful-labs/contentful_middleman/issues/39)
* Add support for querying a field's `linkType` [#75](https://github.com/contentful/contentful.rb/pull/75)
* Bugfix for `Field.items` [#76](https://github.com/contentful/contentful.rb/pull/76)

## 0.6.0
### Fixed
Expand Down
1 change: 1 addition & 0 deletions lib/contentful/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def coerce_value_or_array(value, what = nil)
def should_coerce_hash?(value)
value.is_a?(::Hash) &&
!self.is_a?(Asset) &&
!self.is_a?(Field) &&
!is_location?(value) &&
!is_link?(value) &&
!is_image?(value)
Expand Down
17 changes: 17 additions & 0 deletions spec/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
let(:linkField) { vcr('linkField') {
create_client.content_type('cat').fields.select { |f| f.id == 'image' }.first
} }
let(:arrayField) { vcr('arrayField') {
Contentful::Client.new(
space: 'wl1z0pal05vy',
access_token: '9b76e1bbc29eb513611a66b9fc5fb7acd8d95e83b0f7d6bacfe7ec926c819806'
).content_type('2PqfXUJwE8qSYKuM0U6w8M').fields.select { |f| f.id == 'categories' }.first
} }

describe 'Properties' do
it 'has a #properties getter returning a hash with symbol keys' do
Expand Down Expand Up @@ -46,4 +52,15 @@
expect(linkField.link_type).to eq 'Asset'
end
end

describe 'Array field properties' do
it 'has #type' do
expect(arrayField.type).to eq 'Array'
end

it 'has #items' do
expect(arrayField.items.type).to eq 'Link'
expect(arrayField.items.link_type).to eq 'Entry'
end
end
end
87 changes: 87 additions & 0 deletions spec/fixtures/vcr_cassettes/arrayField.yml

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

0 comments on commit 6686e13

Please sign in to comment.