spec/lib/contentful/management/entry_spec.rb in contentful-management-1.10.1 vs spec/lib/contentful/management/entry_spec.rb in contentful-management-2.0.0
- old
+ new
@@ -16,113 +16,95 @@
end
module Contentful
module Management
describe Entry do
- let(:token) { '<ACCESS_TOKEN>' }
+ let(:token) { ENV.fetch('CF_TEST_CMA_TOKEN', '<ACCESS_TOKEN>') }
let(:space_id) { 'yr5m0jky5hsh' }
let(:entry_id) { '4Rouux8SoUCKwkyCq2I0E0' }
let!(:client) { Client.new(token) }
- subject { client.entries }
+ subject { client.entries(space_id, 'master') }
describe '.all' do
it 'class method also works' do
- vcr('entry/all') { expect(Contentful::Management::Entry.all(client, 'bfsvtul0c41g')).to be_kind_of Contentful::Management::Array }
+ vcr('entry/all') { expect(Contentful::Management::Entry.all(client, 'bfsvtul0c41g', 'master')).to be_kind_of Contentful::Management::Array }
end
it 'returns a Contentful::Array' do
- vcr('entry/all') { expect(subject.all('bfsvtul0c41g')).to be_kind_of Contentful::Management::Array }
+ vcr('entry/all') { expect(described_class.all(client, 'bfsvtul0c41g', 'master')).to be_kind_of Contentful::Management::Array }
end
it 'builds a Contentful::Management::Entry object' do
- vcr('entry/all') { expect(subject.all('bfsvtul0c41g').first).to be_kind_of Contentful::Management::Entry }
+ vcr('entry/all') { expect(described_class.all(client, 'bfsvtul0c41g', 'master').first).to be_kind_of Contentful::Management::Entry }
end
it 'returns entries in context of specified content type' do
vcr('entry/content_type_entires') do
- entries = subject.all('bfsvtul0c41g', content_type: 'category_content_type')
+ entries = described_class.all(client, 'bfsvtul0c41g', 'master', content_type: 'category_content_type')
expect(entries).to be_kind_of Contentful::Management::Array
expect(entries.first).to be_kind_of Contentful::Management::Entry
expect(entries.first.sys[:contentType].id).to eq 'category_content_type'
end
end
it 'return limited number of entries with next_page' do
vcr('entry/limited_entries') do
- entries = subject.all('bfsvtul0c41g', limit: 20, skip: 2)
+ entries = described_class.all(client, 'bfsvtul0c41g', 'master', limit: 20, skip: 2)
expect(entries).to be_kind_of Contentful::Management::Array
expect(entries.limit).to eq 20
expect(entries.skip).to eq 2
entries.next_page
end
end
it 'supports select operator' do
vcr('entry/select_operator') do
- nyancat = subject.all('cfexampleapi', 'sys.id' => 'nyancat', content_type: 'cat', select: 'fields.lives').first
+ nyancat = described_class.all(client, 'cfexampleapi', 'master', 'sys.id' => 'nyancat', content_type: 'cat', select: 'fields.lives').first
expect(nyancat.fields).to eq({lives: 1337})
end
end
end
- describe '.all_published' do
- let!(:space_id) { 'bjwq7b86vgmm' }
-
- before :each do
- expect_any_instance_of(Contentful::Management::Entry.client_association_class).to receive(:warn)
- end
-
- it 'class method also works' do
- vcr('entry/all_public') { expect(Contentful::Management::Entry.all_published(client, space_id)).to be_kind_of Contentful::Management::Array }
- end
- it 'returns a Contentful::Array' do
- vcr('entry/all_public') { expect(subject.all_published(space_id)).to be_kind_of Contentful::Management::Array }
- end
- it 'builds a Contentful::Management::Entry object' do
- vcr('entry/all_public') { expect(subject.all_published(space_id).first).to be_kind_of Contentful::Management::Entry }
- end
- end
-
describe '.find' do
it 'class method also works' do
- vcr('entry/find') { expect(Contentful::Management::Entry.find(client, space_id, entry_id)).to be_kind_of Contentful::Management::Entry }
+ vcr('entry/find') { expect(Contentful::Management::Entry.find(client, space_id, 'master', entry_id)).to be_kind_of Contentful::Management::Entry }
end
it 'returns null as nil on empty Symbols' do
vcr('entry/find-with-null-symbols') do
space = client.spaces.find(space_id)
- entry = space.entries.find(entry_id)
+ entry = client.entries(space.id, 'master').find(entry_id)
expect(entry.fields[:videoid]).to_not be_kind_of(String)
expect(entry.fields[:videoid]).to be_nil
end
end
it 'returns a Contentful::Management::Entry' do
- vcr('entry/find') { expect(subject.find(space_id, entry_id)).to be_kind_of Contentful::Management::Entry }
+ vcr('entry/find') { expect(subject.find(entry_id)).to be_kind_of Contentful::Management::Entry }
end
it 'returns the entry for a given key' do
vcr('entry/find') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
expect(entry.id).to eql entry_id
end
end
it 'returns an error when entry does not exists' do
vcr('entry/find_not_found') do
- result = subject.find(space_id, 'not_exist')
+ result = subject.find('not_exist')
expect(result).to be_kind_of Contentful::Management::NotFound
end
end
context 'raise_error when space not found' do
let!(:client) { Client.new(token, raise_errors: true) }
it 'returns an error when entry does not exists' do
expect_vcr('entry/find_not_found') do
- subject.find(space_id, 'not_exist')
+ subject.find('not_exist')
end.to raise_error Contentful::Management::NotFound
end
end
it 'returns an error when service is unavailable' do
vcr('entry/service_unavailable') do
- result = subject.find(space_id, 'not_exist')
+ result = subject.find('not_exist')
expect(result).to be_kind_of Contentful::Management::ServiceUnavailable
message = [
"HTTP status code: 503 Service Unavailable",
"Message: Service unavailable."
].join("\n")
@@ -132,111 +114,111 @@
end
describe '#destroy' do
it 'returns Contentful::BadRequest error when content type is published' do
vcr('entry/destory_published') do
- result = subject.find(space_id, '3U7JqGuVzOWIimU40mKeem').destroy
+ result = subject.find('3U7JqGuVzOWIimU40mKeem').destroy
expect(result).to be_kind_of Contentful::Management::BadRequest
message = [
"HTTP status code: 400 Bad Request",
"Message: Cannot deleted published"
].join("\n")
expect(result.message).to eq message
end
end
it 'returns true when entry is not published' do
vcr('entry/destroy') do
- result = subject.find(space_id, '3U7JqGuVzOWIimU40mKeem').destroy
+ result = subject.find('3U7JqGuVzOWIimU40mKeem').destroy
expect(result).to eq true
end
end
end
describe '#unpublish' do
it 'unpublish the entry' do
vcr('entry/unpublish') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
initial_version = entry.sys[:version]
entry.unpublish
expect(entry).to be_kind_of Contentful::Management::Entry
expect(entry.sys[:version]).to eql initial_version + 1
end
end
it 'returns BadRequest error when already unpublished' do
vcr('entry/unpublish_already_unpublished') do
- result = subject.find(space_id, entry_id).unpublish
+ result = subject.find(entry_id).unpublish
expect(result).to be_kind_of Contentful::Management::BadRequest
message = [
"HTTP status code: 400 Bad Request",
"Message: Not published"
].join("\n")
expect(result.message).to eq message
expect(result.error[:message]).to eq 'Not published'
- expect(result.error[:url]).to eq 'spaces/yr5m0jky5hsh/entries/4Rouux8SoUCKwkyCq2I0E0/published'
+ expect(result.error[:url]).to eq 'spaces/yr5m0jky5hsh/environments/master/entries/4Rouux8SoUCKwkyCq2I0E0/published'
expect(result.error[:details]).to eq "{\n \"sys\": {\n \"type\": \"Error\",\n \"id\": \"BadRequest\"\n },\n \"message\": \"Not published\"\n}\n"
end
end
end
describe '#publish' do
it 'returns Contentful::Management::Entry' do
vcr('entry/publish') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
initial_version = entry.sys[:version]
entry.publish
expect(entry).to be_kind_of Contentful::Management::Entry
expect(entry.sys[:version]).to eql initial_version + 1
end
end
it 'returns BadRequest error when already published' do
vcr('entry/publish_already_published') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
entry.sys[:version] = -1
result = entry.publish
expect(result).to be_kind_of Contentful::Management::Conflict
end
end
end
describe '#published?' do
it 'returns true if entry is published' do
vcr('entry/published_true') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
entry.publish
expect(entry.published?).to be_truthy
end
end
it 'returns false if entry is not published' do
vcr('entry/published_false') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
entry.unpublish
expect(entry.published?).to be_falsey
end
end
end
describe '#unarchive' do
it 'unarchive the entry' do
vcr('entry/unarchive') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
initial_version = entry.sys[:version]
entry.unarchive
expect(entry).to be_kind_of Contentful::Management::Entry
expect(entry.sys[:version]).to eql initial_version + 1
end
end
it 'returns BadRequest error when already unpublished' do
vcr('entry/unarchive_already_unarchived') do
- result = subject.find(space_id, entry_id).unarchive
+ result = subject.find(entry_id).unarchive
expect(result).to be_kind_of Contentful::Management::BadRequest
end
end
it 'returns BadRequest error when already unarchived' do
vcr('entry/unarchive_already_unarchived') do
- result = subject.find(space_id, entry_id).unarchive
+ result = subject.find(entry_id).unarchive
expect(result).to be_kind_of Contentful::Management::BadRequest
message = [
"HTTP status code: 400 Bad Request",
"Message: Not archived"
].join("\n")
@@ -246,20 +228,20 @@
end
describe '#archive' do
it 'entry' do
vcr(:'entry/archive') do
- entry = subject.find(space_id, '3U7JqGuVzOWIimU40mKeem')
+ entry = subject.find('3U7JqGuVzOWIimU40mKeem')
initial_version = entry.sys[:version]
entry.archive
expect(entry).to be_kind_of Contentful::Management::Entry
expect(entry.sys[:version]).to eql initial_version + 1
end
end
it 'returns error when archive published entry' do
vcr('entry/archive_published') do
- entry = subject.find(space_id, entry_id).archive
+ entry = subject.find(entry_id).archive
expect(entry).to be_kind_of Contentful::Management::BadRequest
message = [
"HTTP status code: 400 Bad Request",
"Message: Cannot archive published"
].join("\n")
@@ -269,38 +251,38 @@
end
describe '#archived?' do
it 'returns true if entry is archived' do
vcr('entry/archived_true') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
entry.archive
expect(entry.archived?).to be_truthy
end
end
it 'returns false if entry is not archived' do
vcr('entry/archived_false') do
- entry = subject.find(space_id, entry_id)
+ entry = subject.find(entry_id)
entry.unarchive
expect(entry.archived?).to be_falsey
end
end
end
describe '.create' do
let(:content_type_id) { '5DSpuKrl04eMAGQoQckeIq' }
- let(:content_type) { client.content_types.find(space_id, content_type_id) }
+ let(:content_type) { client.content_types(space_id, 'master').find(content_type_id) }
it 'create with all attributes' do
vcr('entry/create') do
- content_type = client.content_types.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c')
+ content_type = client.content_types('ene4qtp2sh7u', 'master').find('5BHZB1vi4ooq4wKcmA8e2c')
location = Location.new.tap do |loc|
loc.lat = 22.44
loc.lon = 33.33
end
- file = client.assets.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG')
- entry_att = subject.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm')
- entry = subject.create(
+ file = client.assets('ene4qtp2sh7u', 'master').find('2oNoT3vSAs82SOIQmKe0KG')
+ entry_att = described_class.find(client, 'ene4qtp2sh7u', 'master', '60zYC7nY9GcKGiCYwAs4wm')
+ entry = client.entries('ene4qtp2sh7u', 'master').create(
content_type,
name: 'Test name',
number: 30,
float1: 1.1,
boolean: true, date: '2000-07-12T11:11:00+02:00',
@@ -341,21 +323,21 @@
end
end
it 'with entry' do
vcr('entry/create_with_entry') do
- entry_att = client.entries.find(space_id, '4o6ghKSmSko4i828YCYaEo')
+ entry_att = client.entries(space_id, 'master').find('4o6ghKSmSko4i828YCYaEo')
entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
expect(entry.name).to eq 'EntryWithEntry'
expect(entry.age).to eq 20
expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
end
end
it 'with entries' do
vcr('entry/create_with_entries') do
- entry_att = subject.find(space_id, '1d1QDYzeiyWmgqQYysae8u')
+ entry_att = subject.find('1d1QDYzeiyWmgqQYysae8u')
new_entry = subject.create(content_type,
name: 'EntryWithEntries',
age: 20,
entries: [entry_att, entry_att, entry_att])
expect(new_entry.name).to eq 'EntryWithEntries'
@@ -380,21 +362,21 @@
end
#/ Only here because we want to keep the contentful.rb-dependency out
it 'with entry inherited from Contentful::Entry' do
vcr('entry/create_with_entry') do
- entry_att = Contentful::BaseEntry.new(client.entries.find(space_id, '4o6ghKSmSko4i828YCYaEo'))
+ entry_att = Contentful::BaseEntry.new(client.entries(space_id, 'master').find('4o6ghKSmSko4i828YCYaEo'))
entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
expect(entry.name).to eq 'EntryWithEntry'
expect(entry.age).to eq 20
expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
end
end
it 'with entries inherited from Contentful::Entry' do
vcr('entry/create_with_entries') do
- entry_att = Contentful::BaseEntry.new(subject.find(space_id, '1d1QDYzeiyWmgqQYysae8u'))
+ entry_att = Contentful::BaseEntry.new(subject.find('1d1QDYzeiyWmgqQYysae8u'))
new_entry = subject.create(content_type,
name: 'EntryWithEntries',
age: 20,
entries: [entry_att, entry_att, entry_att])
expect(new_entry.name).to eq 'EntryWithEntries'
@@ -402,18 +384,18 @@
end
end
it 'with asset' do
vcr('entry/create_with_asset') do
- asset = client.assets.find(space_id, 'codequest_id_test_custom')
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom')
entry = subject.create(content_type, name: 'OneAsset', asset: asset)
expect(entry.name).to eq 'OneAsset'
end
end
it 'with assets' do
vcr('entry/create_with_assets') do
- asset = client.assets.find(space_id, 'codequest_id_test_custom')
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom')
entry = subject.create(content_type, name: 'multiAssets', assets: [asset, asset, asset])
expect(entry.name).to eq 'multiAssets'
end
end
it 'with symbols' do
@@ -430,21 +412,21 @@
end
end
it 'to specified locale' do
vcr('entry/create_with_specified_locale') do
space = client.spaces.find('s37a4pe35l1x')
- ct = space.content_types.find('category_content_type')
+ ct = client.content_types(space.id, 'master').find('category_content_type')
entry = ct.entries.create(name: 'Create test', description: 'Test - create entry with specified locale.', locale: 'pl-PL')
expect(entry.name).to eq 'Create test'
end
end
it 'too many requests' do
vcr('entry/too_many_requests') do
space = client.spaces.find('286arvy86ry9')
- invalid_entry = space.entries.find('1YNepnMpXGiMWikaKC4GG0')
- ct = space.content_types.find('5lIEiXrCIoKoIKaSW2C8aa')
+ invalid_entry = client.entries(space.id, 'master').find('1YNepnMpXGiMWikaKC4GG0')
+ ct = client.content_types(space.id, 'master').find('5lIEiXrCIoKoIKaSW2C8aa')
entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
publish = entry.publish
expect(publish).to be_a RateLimitExceeded
expect(publish.error[:message]).to eq 'You have exceeded the rate limit of the Organization this Space belongs to by making too many API requests within a short timespan. Please wait a moment before trying the request again.'
end
@@ -452,36 +434,36 @@
it 'too many requests auto-retry' do
vcr('entry/too_many_requests_retry') do
logger = RetryLoggerMock.new(STDOUT)
space = Client.new(token, raise_errors: true, logger: logger).spaces.find('286arvy86ry9')
- invalid_entry = space.entries.find('1YNepnMpXGiMWikaKC4GG0')
- ct = space.content_types.find('5lIEiXrCIoKoIKaSW2C8aa')
+ invalid_entry = client.entries(space.id, 'master').find('1YNepnMpXGiMWikaKC4GG0')
+ ct = client.content_types(space.id, 'master').find('5lIEiXrCIoKoIKaSW2C8aa')
entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
entry.publish
expect(logger.retry_attempts).to eq 1
end
end
it 'with just an id' do
vcr('entry/create_with_just_id') do
space = client.spaces.find('bbukbffokvih')
- entry = space.content_types.all.first.entries.create({'id' => 'yol'})
+ entry = client.content_types(space.id, 'master').all.first.entries.create({'id' => 'yol'})
entry.save
expect(entry).to be_a Contentful::Management::Entry
end
end
end
describe '#update' do
let(:entry_id) { '1I3qWOiP8k2WWYCogKy88S' }
it 'update entry' do
vcr('entry/update') do
- asset = client.assets.find(space_id, 'codequest_id_test_custom_id')
- entry_att = subject.find(space_id, '1d1QDYzeiyWmgqQYysae8u')
- entry = subject.find(space_id, '4o6ghKSmSko4i828YCYaEo')
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom_id')
+ entry_att = subject.find('1d1QDYzeiyWmgqQYysae8u')
+ entry = subject.find('4o6ghKSmSko4i828YCYaEo')
location = Location.new
location.lat = 22.44
location.lon = 33.33
@@ -505,54 +487,54 @@
end
end
it 'update entry for custom locale' do
vcr('entry/update_with_custom_locale') do
- entry = subject.find(space_id, '3U7JqGuVzOWIimU40mKeem')
+ entry = subject.find('3U7JqGuVzOWIimU40mKeem')
entry.locale = 'pl'
result = entry.update(name: 'testName', bool: true)
expect(result).to be_kind_of Contentful::Management::Entry
expect(result.fields[:name]).to eq 'testName'
expect(result.fields[:bool]).to eq true
end
end
it 'return Error when update not localized field' do
vcr('entry/update_unlocalized_field') do
- asset = client.assets.find(space_id, 'codequest_id_test_custom_id')
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom_id')
location = Location.new
location.lat = 22.44
location.lon = 33.33
- entry = subject.find(space_id, '3U7JqGuVzOWIimU40mKeem')
+ entry = subject.find('3U7JqGuVzOWIimU40mKeem')
entry.locale = 'pl'
result = entry.update(name: 'DoestMatter', bool: false, city: location, asset: asset)
expect(result).to be_kind_of Contentful::Management::Error
end
end
it 'can update boolean fields to `false`' do
vcr('entry/update_bool_field') do
space = client.spaces.find('fujuvqn6zcl1')
- content_type = space.content_types.find('1kUEViTN4EmGiEaaeC6ouY')
+ content_type = client.content_types(space.id, 'master').find('1kUEViTN4EmGiEaaeC6ouY')
q = content_type.entries.new
q.name_with_locales = {'en-US' => 'Hello World'}
q.yolo_with_locales = {'en-US' => false}
expected = q.fields
q.save
- p = space.entries.find(q.id)
+ p = client.entries(space.id, 'master').find(q.id)
expect(p.fields).to match(expected)
end
end
end
describe '#save' do
it 'save updated' do
vcr('entry/save_update') do
- entry = subject.find(space_id, '664EPJ6zHqAeMO6O0mGggU')
+ entry = subject.find('664EPJ6zHqAeMO6O0mGggU')
entry.fields[:carMark] = 'Merc'
entry.save
expect(entry).to be_kind_of Contentful::Management::Entry
expect(entry.fields[:carMark]).to eq 'Merc'
end
@@ -562,11 +544,13 @@
describe '#reload' do
let(:space_id) { 'bfsvtul0c41g' }
it 'update the current version of the object to the version on the system' do
vcr('entry/reload') do
space = client.spaces.find(space_id)
- entry = space.entries.find('2arjcjtY7ucC4AGeIOIkok')
+ client.content_types(space.id, 'master').all # warm-up cache
+
+ entry = client.entries(space.id, 'master').find('2arjcjtY7ucC4AGeIOIkok')
entry.sys[:version] = 999
update_entry = entry.update(post_title: 'Updated title')
expect(update_entry).to be_kind_of Contentful::Management::Conflict
entry.reload
update_entry = entry.update(post_title: 'Updated title')
@@ -581,29 +565,29 @@
client.spaces.find('bfsvtul0c41g')
end
context 'order' do
it 'returns ordered entries by createdAt' do
vcr('entry/search_filter/order_sys.createdAt') do
- ordered_entries = space.entries.all(order: 'sys.createdAt')
+ ordered_entries = client.entries(space.id, 'master').all(order: 'sys.createdAt')
expect(ordered_entries).to be_kind_of Contentful::Management::Array
expect(ordered_entries.first).to be_kind_of Contentful::Management::Entry
expect(ordered_entries.first.sys[:createdAt] < ordered_entries.to_a[4].sys[:createdAt]).to be_truthy
end
end
it 'returns ordered entries by updatedAt' do
vcr('entry/search_filter/order_sys.updatedAt') do
- ordered_entries = space.entries.all(order: 'sys.updatedAt')
+ ordered_entries = client.entries(space.id, 'master').all(order: 'sys.updatedAt')
expect(ordered_entries).to be_kind_of Contentful::Management::Array
expect(ordered_entries.first).to be_kind_of Contentful::Management::Entry
expect(ordered_entries.first.sys[:updatedAt] < ordered_entries.to_a[4].sys[:updatedAt]).to be_truthy
end
end
context 'reverse the sort-order' do
it 'returns reverse sort of ordered entries by updatedAt' do
vcr('entry/search_filter/reverse_order_sys.updatedAt') do
- reverse_ordered_entries = space.entries.all(order: '-sys.updatedAt')
+ reverse_ordered_entries = client.entries(space.id, 'master').all(order: '-sys.updatedAt')
expect(reverse_ordered_entries).to be_kind_of Contentful::Management::Array
expect(reverse_ordered_entries.first).to be_kind_of Contentful::Management::Entry
expect(reverse_ordered_entries.first.sys[:updatedAt] > reverse_ordered_entries.to_a[4].sys[:updatedAt]).to be_truthy
end
end
@@ -611,40 +595,40 @@
end
context 'Including linked Entries in search results' do
it 'returns content_type Entry and include 1 level of linked Entries' do
vcr('entry/search_filter/including_linked_entries') do
- filtered_entries = space.entries.all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS', include: 2)
+ filtered_entries = client.entries(space.id, 'master').all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS', include: 2)
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
end
end
end
context 'Equality and Inequality' do
context 'equality operator' do
it 'returns all Entries with specified ID(IDs are unique and there can only be one)' do
vcr('entry/search_filter/equality_operator') do
- filtered_entries = space.entries.all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS')
+ filtered_entries = client.entries(space.id, 'master').all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.first.sys[:id]).to eq '2Hs5BaU56oUmUIySMQQMUS'
end
end
it 'returns all entries by matching fields.number equal 33' do
vcr('entry/search_filter/matching_array_fields') do
- filtered_entries = space.entries.all(content_type: 'category_content_type', 'fields.number' => 33)
+ filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'fields.number' => 33)
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.size).to eq 2
end
end
end
context 'inequality operator' do
it 'returns all entries except entry with id = 2Hs5BaU56oUmUIySMQQMUS' do
vcr('entry/search_filter/inequality_operator') do
- filtered_entries = space.entries.all('sys.id[ne]' => '2Hs5BaU56oUmUIySMQQMUS')
+ filtered_entries = client.entries(space.id, 'master').all('sys.id[ne]' => '2Hs5BaU56oUmUIySMQQMUS')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_falsey
end
end
@@ -652,11 +636,11 @@
end
context 'Inclusion and Exclusion' do
context 'inclusion operator' do
it 'returns entries with specified IDs' do
vcr('entry/search_filter/inclusion_operator') do
- filtered_entries = space.entries.all('sys.id[in]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
+ filtered_entries = client.entries(space.id, 'master').all('sys.id[in]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_truthy
expect(filtered_entries.map(&:id).include?('2X3X7RHVzqsKGAgIEewgaS')).to be_truthy
expect(filtered_entries.size).to eq 2
@@ -664,11 +648,11 @@
end
end
context 'exclusion operator' do
it 'returns all entries except with specified IDs' do
vcr('entry/search_filter/exclusion_operator') do
- filtered_entries = space.entries.all(content_type: 'category_content_type', 'sys.id[nin]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
+ filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'sys.id[nin]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_falsy
expect(filtered_entries.map(&:id).include?('2X3X7RHVzqsKGAgIEewgaS')).to be_falsy
expect(filtered_entries.size).to eq 3
@@ -677,58 +661,58 @@
end
end
context 'Full-text Search' do
it 'returns all entries except with specified IDs' do
vcr('entry/search_filter/full_search') do
- filtered_entries = space.entries.all(query: 'find me')
+ filtered_entries = client.entries(space.id, 'master').all(query: 'find me')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.size).to eq 2
end
end
it 'returns all entries except with specified IDs' do
vcr('entry/search_filter/full_search_match_operator') do
- filtered_entries = space.entries.all(content_type: 'category_content_type', 'fields.description[match]' => 'find')
+ filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'fields.description[match]' => 'find')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.size).to eq 2
end
end
end
context 'Location-based search' do
it 'returns entries closest to a specific map location and order the results by distance' do
vcr('entry/search_filter/location_search_near_operator') do
- filtered_entries = space.entries.all('fields.location[near]' => '23.15758,53.1297098', content_type: '37TpyB8DcQkq0wkY8c4g2g')
+ filtered_entries = client.entries(space.id, 'master').all('fields.location[near]' => '23.15758,53.1297098', content_type: '37TpyB8DcQkq0wkY8c4g2g')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
end
end
it 'returns entries with fields.location is inside of the circle' do
vcr('entry/search_filter/location_search_within_operator') do
- filtered_entries = space.entries.all('fields.location[within]' => '52,23,300', content_type: '37TpyB8DcQkq0wkY8c4g2g')
+ filtered_entries = client.entries(space.id, 'master').all('fields.location[within]' => '52,23,300', content_type: '37TpyB8DcQkq0wkY8c4g2g')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
end
end
end
context 'Number & Date Ranges' do
context 'number' do
it 'returns entries with fields.number less then 20' do
vcr('entry/search_filter/range_operators_less') do
- filtered_entries = space.entries.all('fields.number[lte]' => '20', content_type: 'category_content_type')
+ filtered_entries = client.entries(space.id, 'master').all('fields.number[lte]' => '20', content_type: 'category_content_type')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.size).to eq 1
end
end
end
context 'date ranges' do
it 'returns entries have been updated since midnight August 19th 2013' do
vcr('entry/search_filter/range_operators_greater_than_or_equal') do
- filtered_entries = space.entries.all('sys.updatedAt[gte]' => '2014-08-19T00:00:00Z')
+ filtered_entries = client.entries(space.id, 'master').all('sys.updatedAt[gte]' => '2014-08-19T00:00:00Z')
expect(filtered_entries).to be_kind_of Contentful::Management::Array
expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
expect(filtered_entries.size).to eq 11
end
end
@@ -738,45 +722,49 @@
describe 'handling of localized values' do
it 'retrieves localized value if it exists' do
vcr('entry/locales/retrieve_localized') do
space = client.spaces.find('0agypmo1waov')
- entry = space.entries.find('5cMXsmSd5So6iggWi268eG')
+ entry = client.entries(space.id, 'master').find('5cMXsmSd5So6iggWi268eG')
entry.locale = 'de-DE'
expect(entry.fields.count).to eq 2
expect(entry.fields[:yolo]).to eq 'etwas Text'
end
end
it 'retrieves value of default locale if it has not been localized' do
vcr('entry/locales/fallback_to_default_locale') do
space = client.spaces.find('0agypmo1waov')
- entry = space.entries.find('4epXENbO8wsaOukgqquYcI')
+ entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
entry.locale = 'de-DE'
expect(entry.fields.count).to eq 2
expect(entry.fields[:yolo]).to eq 'YOLO'
end
end
it 'sets value for the default locale when using simple assignments' do
vcr('entry/locales/simple_assignments_use_default_locale') do
space = client.spaces.find('0agypmo1waov')
- entry = space.entries.find('4epXENbO8wsaOukgqquYcI')
+ client.content_types(space.id, 'master').all # warm-up cache
+ entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
+
entry.yolo = 'changed'
expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
end
end
it 'sets value for the specified locales when using *_with_locales' do
vcr('entry/locales/simple_assignments_use_specified_locale') do
space = client.spaces.find('0agypmo1waov')
- entry = space.entries.find('4epXENbO8wsaOukgqquYcI')
+ client.content_types(space.id, 'master').all # warm-up cache
+ entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
+
entry.yolo_with_locales = {'de-DE' => 'changed'}
entry.locale = 'de-DE'
expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
end
@@ -838,11 +826,12 @@
describe 'fallback locales' do
let(:space) { client.spaces.find('wqjq16zu9s8b') }
it "if a property is nil, it's removed from the request to undefine it in the API" do
vcr('entry/fallback_undefined') {
- entry = space.entries.find('6HSlhD1o3eqkyEWWuMQYyU')
+ client.content_types(space.id, 'master').all # warm-up cache
+ entry = client.entries(space.id, 'master').find('6HSlhD1o3eqkyEWWuMQYyU')
expect(entry.name).to eq 'Foo'
expect(entry.fields('es')[:name]).to eq 'Bar'
expect(entry.fields('zh')[:name]).to eq 'Baz'
@@ -859,28 +848,29 @@
describe 'issues' do
describe 'handles multiple locales even when they are not all defined for the default locale - #70' do
it 'merges all present locales' do
vcr('entry/issue_70') {
space = client.spaces.find('9sh5dtmfyzhj')
+ client.content_types(space.id, 'master').all # warm-up cache
- entry_non_default_locale = space.entries.find('1PdCkb5maYgqsSUCOweseM')
+ entry_non_default_locale = client.entries(space.id, 'master').find('1PdCkb5maYgqsSUCOweseM')
expect(entry_non_default_locale.name_with_locales).to match({"de-DE" => nil, "es" => "Futbolista"})
expect(entry_non_default_locale.non_localized_with_locales).to match({"de-DE" => "baz", "es" => nil})
- entry_with_all_locales = space.entries.find('1QKkNRf9AEW2wqwWowgscs')
+ entry_with_all_locales = client.entries(space.id, 'master').find('1QKkNRf9AEW2wqwWowgscs')
expect(entry_with_all_locales.name_with_locales).to match({"de-DE" => "Junge", "en-US" => "Boy", "es" => "Chico"})
expect(entry_with_all_locales.non_localized_with_locales).to match({"de-DE" => "foobar", "en-US" => nil, "es" => nil})
}
end
it 'can save with multiple locales assigned - #73' do
vcr('entry/issue_73') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = client.content_types.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
new_entry = content_type.entries.create(id: 'hello-world')
new_entry.name = 'Hello World!'
new_entry.locale = 'en-GB'
new_entry.value_with_locales = {'en-GB'=>'hello world', 'es-ES'=>'hola mundo'}
@@ -889,18 +879,18 @@
expect(res.respond_to?(:error)).to be_falsey
expect(res.is_a?(Contentful::Management::DynamicEntry)).to be_truthy
expect(res.value_with_locales).to match('en-GB' => 'hello world', 'es-ES' => 'hola mundo')
ensure
- new_entry.destroy
+ #new_entry.destroy
end
}
end
it 'fields_for_query get properly updated when setting a field using _with_locales - #91' do
vcr('entry/issue_91') {
- entry = client.entries.find('iv4sic0eru9h', '5GrMLWzfyMs0eKoi4sg2ug')
+ entry = client.entries('iv4sic0eru9h', 'master').find('5GrMLWzfyMs0eKoi4sg2ug')
expect(entry.test_with_locales).to eq('en-US' => 'foo', 'es' => 'bar')
entry.test_with_locales = {'en-US' => 'baz', 'es' => 'foobar'}
@@ -914,21 +904,21 @@
describe 'before refetch' do
it 'on an already populated field' do
vcr('entry/issue_61.1') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = client.content_types.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
new_entry = content_type.entries.create(id: 'issue61_1', value: 'hello')
expect(new_entry.value).to eq 'hello'
new_entry.value = 'goodbye'
new_entry.save
new_entry.publish
- expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
expect(expected_entry.value).to eq 'goodbye'
ensure
new_entry.destroy
end
@@ -937,21 +927,21 @@
it 'on a previously empty field' do
vcr('entry/issue_61.2') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = client.content_types.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
new_entry = content_type.entries.create(id: 'issue61_2')
new_entry.value = 'goodbye'
new_entry.save
new_entry.publish
expect(new_entry.value).to eq 'goodbye'
- expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
expect(expected_entry.value).to eq 'goodbye'
ensure
new_entry.destroy
end
@@ -962,16 +952,16 @@
describe 'after refetch' do
it 'on an already populated field' do
vcr('entry/issue_61.3') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = client.content_types.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
new_entry = content_type.entries.create(id: 'issue61_3', value: 'hello')
expect(new_entry.value).to eq 'hello'
- expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
expected_entry.value = 'goodbye'
expected_entry.save
expected_entry.publish
@@ -985,14 +975,14 @@
it 'on a previously empty field' do
vcr('entry/issue_61.4') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = client.content_types.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
new_entry = content_type.entries.create(id: 'issue61_4')
- expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
expected_entry.value = 'goodbye'
expected_entry.save
expected_entry.publish
@@ -1006,17 +996,17 @@
end
end
describe 'on an entry created through the ui' do
describe 'with dynamic_entries' do
- let!(:client) { vcr('entry/issue_61_spaces') { Client.new(token, dynamic_entries: ['u2viwgfeal0o']) } }
+ let!(:client) { vcr('entry/issue_61_spaces') { Client.new(token, dynamic_entries: {'u2viwgfeal0o' => 'master'}) } }
it 'on an already populated field' do
vcr('entry/issue_61.5') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = subject.find('u2viwgfeal0o', 'fIpsfQSOd22IsqMQCiG0K')
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
expect(expected_entry.value).to eq 'hello'
expected_entry.value = 'goodbye'
@@ -1036,11 +1026,11 @@
it 'on a previously empty field' do
vcr('entry/issue_61.6') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = subject.find('u2viwgfeal0o', '2GmtCwDBcIu4giMgQGIIcq')
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
expect(expected_entry.value).to eq nil
expected_entry.value = 'goodbye'
@@ -1063,11 +1053,11 @@
it 'on an already populated field' do
vcr('entry/issue_61.7') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = subject.find('u2viwgfeal0o', 'fIpsfQSOd22IsqMQCiG0K')
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
expect(expected_entry.value).to eq 'hello'
expected_entry.value = 'goodbye'
@@ -1087,10 +1077,10 @@
it 'on a previously empty field' do
vcr('entry/issue_61.8') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = subject.find('u2viwgfeal0o', '2GmtCwDBcIu4giMgQGIIcq')
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
expect(expected_entry.value).to eq nil
expected_entry.value = 'goodbye'