Skip to content

Commit

Permalink
Add support for :sync with :raw_mode on
Browse files Browse the repository at this point in the history
  • Loading branch information
dlitvakb committed Oct 23, 2015
1 parent 1e7211d commit 5b33197
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Unreleased
### Fixed
* Parse nested locales in `AssetFields` [#66](https://github.com/contentful/contentful.rb/pull/66)
* `Sync API` now works with `:raw_mode` enabled [#68](https://github.com/contentful/contentful.rb/issues/68)

### Other
* Update http.rb dependency to v0.8.0
Expand Down
4 changes: 4 additions & 0 deletions lib/contentful/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def get(options_or_url)
page = Request.new(@client, '/sync', options_or_url).get
end

if @client.configuration[:raw_mode]
return page
end

link_page_to_sync! page
update_sync_state_from! page

Expand Down
106 changes: 106 additions & 0 deletions spec/fixtures/vcr_cassettes/sync_page_short.yml

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

60 changes: 60 additions & 0 deletions spec/sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,64 @@
}
end
end

describe 'raw_mode' do
it 'should not fail' do
sync = create_client(raw_mode: true).sync(initial: true)

vcr('sync_page_short') {
expect { sync.first_page }.not_to raise_error
}
end

it 'should return a raw Response' do
sync = create_client(raw_mode: true).sync(initial: true)

vcr('sync_page_short') {
expect(sync.first_page).to be_a Contentful::Response
}
end

it 'should return JSON' do
sync = create_client(raw_mode: true).sync(initial: true)

expected = {
"sys" => {"type" => "Array"},
"items" => [
{
"sys" => {
"space" => {
"sys" => {
"type" => "Link",
"linkType" => "Space",
"id" => "cfexampleapi"}
},
"type" => "Entry",
"contentType" => {
"sys" => {
"type" => "Link",
"linkType" => "ContentType",
"id" => "1t9IbcfdCk6m04uISSsaIK"
}
},
"id" => "5ETMRzkl9KM4omyMwKAOki",
"revision" => 2,
"createdAt" => "2014-02-21T13:42:57.752Z",
"updatedAt" => "2014-04-16T12:44:02.691Z"
},
"fields" => {
"name" => {"en-US"=>"London"},
"center" => {
"en-US" => {"lat"=>51.508515, "lon"=>-0.12548719999995228}
}
}
}
],
"nextSyncUrl" => "https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg"
}
vcr('sync_page_short') {
expect(sync.first_page.object).to eql expected
}
end
end
end

0 comments on commit 5b33197

Please sign in to comment.