spec/lib/contentful/management/entry_spec.rb in contentful-management-0.9.0 vs spec/lib/contentful/management/entry_spec.rb in contentful-management-1.0.0
- old
+ new
@@ -9,52 +9,62 @@
let(:space_id) { 'yr5m0jky5hsh' }
let(:entry_id) { '4Rouux8SoUCKwkyCq2I0E0' }
let!(:client) { Client.new(token) }
- subject { Contentful::Management::Entry }
+ subject { client.entries }
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 }
+ end
it 'returns a Contentful::Array' do
vcr('entry/all') { expect(subject.all('bfsvtul0c41g')).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 }
end
it 'returns entries in context of specified content type' do
vcr('entry/content_type_entires') do
- entries = Contentful::Management::Entry.all('bfsvtul0c41g', content_type: 'category_content_type')
+ entries = subject.all('bfsvtul0c41g', 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 = Contentful::Management::Entry.all('bfsvtul0c41g', limit: 20, skip: 2)
+ entries = subject.all('bfsvtul0c41g', 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
end
describe '.all_published' do
let!(:space_id) { 'bjwq7b86vgmm' }
+ 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
+ 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 }
+ end
+
it 'returns null as nil on empty Symbols' do
vcr('entry/find-with-null-symbols') do
- space = Contentful::Management::Space.find space_id
+ space = client.spaces.find(space_id)
entry = space.entries.find(entry_id)
expect(entry.fields[:videoid]).to_not be_kind_of(String)
expect(entry.fields[:videoid]).to be_nil
end
end
@@ -231,34 +241,35 @@
end
end
describe '.create' do
let(:content_type_id) { '5DSpuKrl04eMAGQoQckeIq' }
- let(:content_type) { Contentful::Management::ContentType.find(space_id, content_type_id) }
+ let(:content_type) { client.content_types.find(space_id, content_type_id) }
it 'create with all attributes' do
vcr('entry/create') do
- content_type = Contentful::Management::ContentType.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c')
+ content_type = client.content_types.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c')
location = Location.new.tap do |location|
location.lat = 22.44
location.lon = 33.33
end
- file = Asset.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG')
- entry_att = Entry.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm')
- entry = subject.create(content_type,
- name: 'Test name',
- number: 30,
- float1: 1.1,
- boolean: true, date: '2000-07-12T11:11:00+02:00',
- time: '2000-07-12T11:11:00+02:00',
- location: location,
- file: file,
- image: file,
- array: %w(PL USD XX),
- entry: entry_att,
- entries: [entry_att, entry_att],
- object_json: {'test' => {'@type' => 'Codequest'}}
+ file = client.assets.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG')
+ entry_att = subject.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm')
+ entry = subject.create(
+ content_type,
+ name: 'Test name',
+ number: 30,
+ float1: 1.1,
+ boolean: true, date: '2000-07-12T11:11:00+02:00',
+ time: '2000-07-12T11:11:00+02:00',
+ location: location,
+ file: file,
+ image: file,
+ array: %w(PL USD XX),
+ entry: entry_att,
+ entries: [entry_att, entry_att],
+ object_json: {'test' => {'@type' => 'Codequest'}}
)
expect(entry.name).to eq 'Test name'
expect(entry.number).to eq 30
expect(entry.float1).to eq 1.1
expect(entry.boolean).to eq true
@@ -286,21 +297,21 @@
end
end
it 'with entry' do
vcr('entry/create_with_entry') do
- entry_att = Entry.find(space_id, '4o6ghKSmSko4i828YCYaEo')
+ entry_att = client.entries.find(space_id, '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 = Entry.find(space_id, '1d1QDYzeiyWmgqQYysae8u')
+ entry_att = subject.find(space_id, '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'
@@ -308,18 +319,18 @@
end
end
it 'with asset' do
vcr('entry/create_with_asset') do
- asset = Asset.find(space_id, 'codequest_id_test_custom')
+ asset = client.assets.find(space_id, '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 = Asset.find(space_id, 'codequest_id_test_custom')
+ asset = client.assets.find(space_id, '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
@@ -335,20 +346,20 @@
expect(entry.id).to eq 'custom_id'
end
end
it 'to specified locale' do
vcr('entry/create_with_specified_locale') do
- space = Contentful::Management::Space.find('s37a4pe35l1x')
+ space = client.spaces.find('s37a4pe35l1x')
ct = space.content_types.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 = Contentful::Management::Space.find('286arvy86ry9')
+ space = client.spaces.find('286arvy86ry9')
invalid_entry = space.entries.find('1YNepnMpXGiMWikaKC4GG0')
ct = space.content_types.find('5lIEiXrCIoKoIKaSW2C8aa')
entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
publish = entry.publish
expect(publish).to be_a RateLimitExceeded
@@ -356,11 +367,11 @@
end
end
it 'with just an id' do
vcr('entry/create_with_just_id') do
- space = Contentful::Management::Space.find('bbukbffokvih')
+ space = client.spaces.find('bbukbffokvih')
entry = space.content_types.all.first.entries.create({'id' => 'yol'})
entry.save
expect(entry).to be_a Contentful::Management::Entry
end
end
@@ -368,13 +379,13 @@
describe '#update' do
let(:entry_id) { '1I3qWOiP8k2WWYCogKy88S' }
it 'update entry' do
vcr('entry/update') do
- asset = Asset.find(space_id, 'codequest_id_test_custom_id')
- entry_att = Entry.find(space_id, '1d1QDYzeiyWmgqQYysae8u')
- entry = Contentful::Management::Entry.find(space_id, '4o6ghKSmSko4i828YCYaEo')
+ asset = client.assets.find(space_id, 'codequest_id_test_custom_id')
+ entry_att = subject.find(space_id, '1d1QDYzeiyWmgqQYysae8u')
+ entry = subject.find(space_id, '4o6ghKSmSko4i828YCYaEo')
location = Location.new
location.lat = 22.44
location.lon = 33.33
@@ -398,36 +409,36 @@
end
end
it 'update entry for custom locale' do
vcr('entry/update_with_custom_locale') do
- entry = Contentful::Management::Entry.find(space_id, '3U7JqGuVzOWIimU40mKeem')
+ entry = subject.find(space_id, '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 = Asset.find(space_id, 'codequest_id_test_custom_id')
+ asset = client.assets.find(space_id, 'codequest_id_test_custom_id')
location = Location.new
location.lat = 22.44
location.lon = 33.33
- entry = Contentful::Management::Entry.find(space_id, '3U7JqGuVzOWIimU40mKeem')
+ entry = subject.find(space_id, '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 = Contentful::Management::Space.find('fujuvqn6zcl1')
+ space = client.spaces.find('fujuvqn6zcl1')
content_type = space.content_types.find('1kUEViTN4EmGiEaaeC6ouY')
q = content_type.entries.new
q.name_with_locales = {'en-US' => 'Hello World'}
q.yolo_with_locales = {'en-US' => false}
@@ -441,11 +452,11 @@
end
describe '#save' do
it 'save updated' do
vcr('entry/save_update') do
- entry = Contentful::Management::Entry.find(space_id, '664EPJ6zHqAeMO6O0mGggU')
+ entry = subject.find(space_id, '664EPJ6zHqAeMO6O0mGggU')
entry.fields[:carMark] = 'Merc'
entry.save
expect(entry).to be_kind_of Contentful::Management::Entry
expect(entry.fields[:carMark]).to eq 'Merc'
end
@@ -454,11 +465,11 @@
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 = Contentful::Management::Space.find(space_id)
+ space = client.spaces.find(space_id)
entry = space.entries.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
@@ -469,11 +480,11 @@
end
end
describe 'search filters' do
let(:space) do
- Contentful::Management::Space.find('bfsvtul0c41g')
+ 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')
@@ -630,44 +641,44 @@
end
describe 'handling of localized values' do
it 'retrieves localized value if it exists' do
vcr('entry/locales/retrieve_localized') do
- space = Contentful::Management::Space.find('0agypmo1waov')
+ space = client.spaces.find('0agypmo1waov')
entry = space.entries.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 = Contentful::Management::Space.find('0agypmo1waov')
+ space = client.spaces.find('0agypmo1waov')
entry = space.entries.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 = Contentful::Management::Space.find('0agypmo1waov')
+ space = client.spaces.find('0agypmo1waov')
entry = space.entries.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 = Contentful::Management::Space.find('0agypmo1waov')
+ space = client.spaces.find('0agypmo1waov')
entry = space.entries.find('4epXENbO8wsaOukgqquYcI')
entry.yolo_with_locales = {'de-DE' => 'changed'}
entry.locale = 'de-DE'
@@ -731,11 +742,11 @@
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 = Contentful::Management::Space.find('9sh5dtmfyzhj')
+ space = client.spaces.find('9sh5dtmfyzhj')
entry_non_default_locale = space.entries.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})
@@ -749,11 +760,11 @@
it 'can save with multiple locales assigned - #73' do
vcr('entry/issue_73') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = Contentful::Management::ContentType.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types.find('u2viwgfeal0o', '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'}
@@ -774,21 +785,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 = Contentful::Management::ContentType.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types.find('u2viwgfeal0o', '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 = Contentful::Management::Entry.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
expect(expected_entry.value).to eq 'goodbye'
ensure
new_entry.destroy
end
@@ -797,21 +808,21 @@
it 'on a previously empty field' do
vcr('entry/issue_61.2') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = Contentful::Management::ContentType.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types.find('u2viwgfeal0o', '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 = Contentful::Management::Entry.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
expect(expected_entry.value).to eq 'goodbye'
ensure
new_entry.destroy
end
@@ -822,16 +833,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 = Contentful::Management::ContentType.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types.find('u2viwgfeal0o', 'someType')
new_entry = content_type.entries.create(id: 'issue61_3', value: 'hello')
expect(new_entry.value).to eq 'hello'
- expected_entry = Contentful::Management::Entry.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
expected_entry.value = 'goodbye'
expected_entry.save
expected_entry.publish
@@ -845,14 +856,14 @@
it 'on a previously empty field' do
vcr('entry/issue_61.4') {
begin
client.configuration[:default_locale] = 'en-GB'
- content_type = Contentful::Management::ContentType.find('u2viwgfeal0o', 'someType')
+ content_type = client.content_types.find('u2viwgfeal0o', 'someType')
new_entry = content_type.entries.create(id: 'issue61_4')
- expected_entry = Contentful::Management::Entry.find('u2viwgfeal0o', new_entry.id)
+ expected_entry = subject.find('u2viwgfeal0o', new_entry.id)
expected_entry.value = 'goodbye'
expected_entry.save
expected_entry.publish
@@ -872,11 +883,11 @@
it 'on an already populated field' do
vcr('entry/issue_61.5') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = Contentful::Management::Entry.find('u2viwgfeal0o', 'fIpsfQSOd22IsqMQCiG0K')
+ expected_entry = subject.find('u2viwgfeal0o', 'fIpsfQSOd22IsqMQCiG0K')
expect(expected_entry.value).to eq 'hello'
expected_entry.value = 'goodbye'
@@ -896,11 +907,11 @@
it 'on a previously empty field' do
vcr('entry/issue_61.6') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = Contentful::Management::Entry.find('u2viwgfeal0o', '2GmtCwDBcIu4giMgQGIIcq')
+ expected_entry = subject.find('u2viwgfeal0o', '2GmtCwDBcIu4giMgQGIIcq')
expect(expected_entry.value).to eq nil
expected_entry.value = 'goodbye'
@@ -923,11 +934,11 @@
it 'on an already populated field' do
vcr('entry/issue_61.7') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = Contentful::Management::Entry.find('u2viwgfeal0o', 'fIpsfQSOd22IsqMQCiG0K')
+ expected_entry = subject.find('u2viwgfeal0o', 'fIpsfQSOd22IsqMQCiG0K')
expect(expected_entry.value).to eq 'hello'
expected_entry.value = 'goodbye'
@@ -947,10 +958,10 @@
it 'on a previously empty field' do
vcr('entry/issue_61.8') {
begin
client.configuration[:default_locale] = 'en-GB'
- expected_entry = Contentful::Management::Entry.find('u2viwgfeal0o', '2GmtCwDBcIu4giMgQGIIcq')
+ expected_entry = subject.find('u2viwgfeal0o', '2GmtCwDBcIu4giMgQGIIcq')
expect(expected_entry.value).to eq nil
expected_entry.value = 'goodbye'