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 49fc17d commit 60e0cd1
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change Log
## Unreleased
* `Sync API` now works with `:raw_mode` enabled [#68](https://github.com/contentful/contentful.rb/issues/68)

## 0.6.0
### Fixed
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.

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

describe 'raw_mode' do
before do
@sync = create_client(raw_mode: true).sync(initial: true)
end

it 'should not fail' do
vcr('sync_page_short') {
expect { @sync.first_page }.not_to raise_error
}
end

it 'should return a raw Response' do
vcr('sync_page_short') {
expect(@sync.first_page).to be_a Contentful::Response
}
end

it 'should return JSON' do
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 60e0cd1

Please sign in to comment.