contentful 2.15.3 → 2.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +22 -11
- data/lib/contentful/array_like.rb +11 -2
- data/lib/contentful/asset.rb +4 -0
- data/lib/contentful/base_resource.rb +14 -2
- data/lib/contentful/client.rb +1 -2
- data/lib/contentful/fields_resource.rb +1 -0
- data/lib/contentful/version.rb +1 -1
- metadata +4 -367
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/.rubocop.yml +0 -31
- data/.rubocop_todo.yml +0 -35
- data/.travis.yml +0 -15
- data/.yardopts +0 -4
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -166
- data/Guardfile +0 -24
- data/RELEASE.md +0 -8
- data/Rakefile +0 -33
- data/contentful.gemspec +0 -44
- data/coverage/.last_run.json +0 -5
- data/coverage/.resultset.json +0 -5086
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.10.2/application.css +0 -799
- data/coverage/assets/0.10.2/application.js +0 -1707
- data/coverage/assets/0.10.2/colorbox/border.png +0 -0
- data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.2/favicon_green.png +0 -0
- data/coverage/assets/0.10.2/favicon_red.png +0 -0
- data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.2/loading.gif +0 -0
- data/coverage/assets/0.10.2/magnify.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +0 -0
- data/doc/Contentful/AccessDenied.html +0 -159
- data/doc/Contentful/Array.html +0 -844
- data/doc/Contentful/ArrayCoercion.html +0 -242
- data/doc/Contentful/ArrayLike.html +0 -624
- data/doc/Contentful/Asset.html +0 -486
- data/doc/Contentful/BadGateway.html +0 -159
- data/doc/Contentful/BadRequest.html +0 -159
- data/doc/Contentful/BaseCoercion.html +0 -445
- data/doc/Contentful/BaseResource.html +0 -598
- data/doc/Contentful/BooleanCoercion.html +0 -242
- data/doc/Contentful/Client.html +0 -1738
- data/doc/Contentful/ContentType.html +0 -617
- data/doc/Contentful/ContentTypeCache.html +0 -428
- data/doc/Contentful/DateCoercion.html +0 -244
- data/doc/Contentful/DeletedAsset.html +0 -156
- data/doc/Contentful/DeletedEntry.html +0 -156
- data/doc/Contentful/EmptyFieldError.html +0 -217
- data/doc/Contentful/Entry.html +0 -334
- data/doc/Contentful/Error.html +0 -407
- data/doc/Contentful/Field.html +0 -935
- data/doc/Contentful/FieldsResource.html +0 -583
- data/doc/Contentful/File.html +0 -218
- data/doc/Contentful/FloatCoercion.html +0 -238
- data/doc/Contentful/IntegerCoercion.html +0 -238
- data/doc/Contentful/Link.html +0 -246
- data/doc/Contentful/LinkCoercion.html +0 -156
- data/doc/Contentful/Locale.html +0 -536
- data/doc/Contentful/Location.html +0 -382
- data/doc/Contentful/LocationCoercion.html +0 -238
- data/doc/Contentful/NotFound.html +0 -159
- data/doc/Contentful/ObjectCoercion.html +0 -238
- data/doc/Contentful/RateLimitExceeded.html +0 -346
- data/doc/Contentful/Request.html +0 -895
- data/doc/Contentful/ResourceBuilder.html +0 -1067
- data/doc/Contentful/ResourceReferences.html +0 -254
- data/doc/Contentful/Response.html +0 -708
- data/doc/Contentful/RichTextCoercion.html +0 -238
- data/doc/Contentful/ServerError.html +0 -159
- data/doc/Contentful/ServiceUnavailable.html +0 -159
- data/doc/Contentful/Space.html +0 -392
- data/doc/Contentful/StringCoercion.html +0 -242
- data/doc/Contentful/StructuredTextCoercion.html +0 -238
- data/doc/Contentful/Support.html +0 -788
- data/doc/Contentful/SymbolCoercion.html +0 -169
- data/doc/Contentful/Sync.html +0 -653
- data/doc/Contentful/SyncPage.html +0 -807
- data/doc/Contentful/TextCoercion.html +0 -169
- data/doc/Contentful/Unauthorized.html +0 -159
- data/doc/Contentful/UnparsableJson.html +0 -159
- data/doc/Contentful/UnparsableResource.html +0 -135
- data/doc/Contentful.html +0 -157
- data/doc/_index.html +0 -563
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -496
- data/doc/file.CHANGELOG.html +0 -708
- data/doc/file.LICENSE.html +0 -70
- data/doc/file.README.html +0 -758
- data/doc/file_list.html +0 -66
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -758
- data/doc/js/app.js +0 -303
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -1187
- data/doc/top-level-namespace.html +0 -110
- data/examples/custom_classes.rb +0 -39
- data/examples/example_queries.rb +0 -26
- data/examples/raise_errors.rb +0 -20
- data/examples/raw_mode.rb +0 -14
- data/spec/array_spec.rb +0 -167
- data/spec/asset_spec.rb +0 -192
- data/spec/auto_includes_spec.rb +0 -12
- data/spec/client_class_spec.rb +0 -86
- data/spec/client_configuration_spec.rb +0 -377
- data/spec/content_type_spec.rb +0 -49
- data/spec/deleted_asset_spec.rb +0 -38
- data/spec/deleted_entry_spec.rb +0 -38
- data/spec/entry_spec.rb +0 -777
- data/spec/error_class_spec.rb +0 -327
- data/spec/error_requests_spec.rb +0 -87
- data/spec/field_spec.rb +0 -95
- data/spec/file_spec.rb +0 -33
- data/spec/fixtures/json_responses/400_details_errors_object.json +0 -14
- data/spec/fixtures/json_responses/400_details_errors_string.json +0 -12
- data/spec/fixtures/json_responses/400_details_string.json +0 -8
- data/spec/fixtures/json_responses/403_reasons.json +0 -13
- data/spec/fixtures/json_responses/404_details_string.json +0 -8
- data/spec/fixtures/json_responses/404_id.json +0 -11
- data/spec/fixtures/json_responses/404_sys_type.json +0 -12
- data/spec/fixtures/json_responses/404_type.json +0 -10
- data/spec/fixtures/json_responses/content_type.json +0 -83
- data/spec/fixtures/json_responses/default_400.json +0 -7
- data/spec/fixtures/json_responses/default_401.json +0 -7
- data/spec/fixtures/json_responses/default_403.json +0 -7
- data/spec/fixtures/json_responses/default_404.json +0 -7
- data/spec/fixtures/json_responses/default_429.json +0 -7
- data/spec/fixtures/json_responses/default_500.json +0 -7
- data/spec/fixtures/json_responses/default_502.json +0 -7
- data/spec/fixtures/json_responses/default_503.json +0 -7
- data/spec/fixtures/json_responses/includes.json +0 -111
- data/spec/fixtures/json_responses/link_array.json +0 -43
- data/spec/fixtures/json_responses/not_found.json +0 -13
- data/spec/fixtures/json_responses/nyancat.json +0 -48
- data/spec/fixtures/json_responses/other_error.json +0 -9
- data/spec/fixtures/json_responses/other_error_no_details.json +0 -8
- data/spec/fixtures/json_responses/other_error_no_message.json +0 -8
- data/spec/fixtures/json_responses/other_error_no_request_id.json +0 -8
- data/spec/fixtures/json_responses/other_error_nothing.json +0 -6
- data/spec/fixtures/json_responses/self_link.json +0 -82
- data/spec/fixtures/json_responses/unparsable.json +0 -13
- data/spec/fixtures/vcr_cassettes/array/marshal_custom_classes.yml +0 -159
- data/spec/fixtures/vcr_cassettes/array/marshal_unpublished.yml +0 -315
- data/spec/fixtures/vcr_cassettes/array/nested_resources.yml +0 -159
- data/spec/fixtures/vcr_cassettes/array.yml +0 -288
- data/spec/fixtures/vcr_cassettes/arrayField.yml +0 -87
- data/spec/fixtures/vcr_cassettes/array_page_1.yml +0 -106
- data/spec/fixtures/vcr_cassettes/array_page_2.yml +0 -73
- data/spec/fixtures/vcr_cassettes/asset/select_empty_array.yml +0 -104
- data/spec/fixtures/vcr_cassettes/asset/select_no_sys.yml +0 -119
- data/spec/fixtures/vcr_cassettes/asset/select_one_field.yml +0 -97
- data/spec/fixtures/vcr_cassettes/asset/select_only_sys.yml +0 -88
- data/spec/fixtures/vcr_cassettes/asset.yml +0 -96
- data/spec/fixtures/vcr_cassettes/assets/issues_129.yml +0 -90
- data/spec/fixtures/vcr_cassettes/assets/issues_jekyll_46.yml +0 -115
- data/spec/fixtures/vcr_cassettes/bad_request.yml +0 -76
- data/spec/fixtures/vcr_cassettes/content_type.yml +0 -147
- data/spec/fixtures/vcr_cassettes/entries/empty_fields.yml +0 -246
- data/spec/fixtures/vcr_cassettes/entries/issue_117.yml +0 -201
- data/spec/fixtures/vcr_cassettes/entries/issue_125.yml +0 -198
- data/spec/fixtures/vcr_cassettes/entries/rich_text.yml +0 -1707
- data/spec/fixtures/vcr_cassettes/entries/rich_text_hydration_issue.yml +0 -460
- data/spec/fixtures/vcr_cassettes/entries/rich_text_nested_fields.yml +0 -653
- data/spec/fixtures/vcr_cassettes/entries/rich_text_unresolved_relationships.yml +0 -983
- data/spec/fixtures/vcr_cassettes/entries/unresolvable_assets.yml +0 -89
- data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml +0 -159
- data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml +0 -167
- data/spec/fixtures/vcr_cassettes/entries.yml +0 -561
- data/spec/fixtures/vcr_cassettes/entry/custom_resource.yml +0 -168
- data/spec/fixtures/vcr_cassettes/entry/include_resolution.yml +0 -101
- data/spec/fixtures/vcr_cassettes/entry/include_resolution_uniques.yml +0 -81
- data/spec/fixtures/vcr_cassettes/entry/json_objects.yml +0 -88
- data/spec/fixtures/vcr_cassettes/entry/json_objects_client.yml +0 -86
- data/spec/fixtures/vcr_cassettes/entry/marshal_138.yml +0 -159
- data/spec/fixtures/vcr_cassettes/entry/marshal_unpublished.yml +0 -303
- data/spec/fixtures/vcr_cassettes/entry/marshall.yml +0 -293
- data/spec/fixtures/vcr_cassettes/entry/raw.yml +0 -201
- data/spec/fixtures/vcr_cassettes/entry/search_link_to_asset.yml +0 -81
- data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry.yml +0 -81
- data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry_with_custom_query.yml +0 -115
- data/spec/fixtures/vcr_cassettes/entry/select_empty_array.yml +0 -111
- data/spec/fixtures/vcr_cassettes/entry/select_no_sys.yml +0 -102
- data/spec/fixtures/vcr_cassettes/entry/select_one_field.yml +0 -76
- data/spec/fixtures/vcr_cassettes/entry/select_one_field_proper.yml +0 -114
- data/spec/fixtures/vcr_cassettes/entry/select_only_sys.yml +0 -111
- data/spec/fixtures/vcr_cassettes/entry.yml +0 -102
- data/spec/fixtures/vcr_cassettes/entry_cache.yml +0 -288
- data/spec/fixtures/vcr_cassettes/entry_locales.yml +0 -104
- data/spec/fixtures/vcr_cassettes/field.yml +0 -147
- data/spec/fixtures/vcr_cassettes/human.yml +0 -118
- data/spec/fixtures/vcr_cassettes/linkField.yml +0 -83
- data/spec/fixtures/vcr_cassettes/locale.yml +0 -83
- data/spec/fixtures/vcr_cassettes/locale_from_environment.yml +0 -121
- data/spec/fixtures/vcr_cassettes/location.yml +0 -193
- data/spec/fixtures/vcr_cassettes/multi_locale_array_reference.yml +0 -196
- data/spec/fixtures/vcr_cassettes/multi_locale_reference.yml +0 -214
- data/spec/fixtures/vcr_cassettes/not_found.yml +0 -76
- data/spec/fixtures/vcr_cassettes/nyancat.yml +0 -102
- data/spec/fixtures/vcr_cassettes/query_array_1.yml +0 -89
- data/spec/fixtures/vcr_cassettes/query_array_2.yml +0 -89
- data/spec/fixtures/vcr_cassettes/ratelimit.yml +0 -64
- data/spec/fixtures/vcr_cassettes/ratelimit_retry.yml +0 -294
- data/spec/fixtures/vcr_cassettes/reloaded_entry.yml +0 -102
- data/spec/fixtures/vcr_cassettes/space.yml +0 -83
- data/spec/fixtures/vcr_cassettes/sync_deleted_asset.yml +0 -174
- data/spec/fixtures/vcr_cassettes/sync_deleted_entry.yml +0 -89
- data/spec/fixtures/vcr_cassettes/sync_deletion.yml +0 -191
- data/spec/fixtures/vcr_cassettes/sync_environment.yml +0 -81
- data/spec/fixtures/vcr_cassettes/sync_page.yml +0 -637
- data/spec/fixtures/vcr_cassettes/sync_page_2.yml +0 -71
- data/spec/fixtures/vcr_cassettes/sync_page_short.yml +0 -106
- data/spec/fixtures/vcr_cassettes/unauthorized.yml +0 -64
- data/spec/fixtures/vcr_cassettes/unavailable.yml +0 -76
- data/spec/link_spec.rb +0 -50
- data/spec/locale_spec.rb +0 -37
- data/spec/location_spec.rb +0 -25
- data/spec/request_spec.rb +0 -57
- data/spec/resource_building_spec.rb +0 -31
- data/spec/response_spec.rb +0 -62
- data/spec/space_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -14
- data/spec/support/client.rb +0 -6
- data/spec/support/json_responses.rb +0 -18
- data/spec/support/vcr.rb +0 -16
- data/spec/sync_page_spec.rb +0 -103
- data/spec/sync_spec.rb +0 -180
data/spec/entry_spec.rb
DELETED
@@ -1,777 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Contentful::Entry do
|
4
|
-
let(:entry) { vcr('entry') { create_client.entry 'nyancat' } }
|
5
|
-
|
6
|
-
let(:subclass) do
|
7
|
-
Class.new(described_class) do
|
8
|
-
# An overridden sys method:
|
9
|
-
def created_at; 'yesterday'; end
|
10
|
-
|
11
|
-
# An overridden field method:
|
12
|
-
def best_friend; 'octocat'; end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:raw) { entry.raw }
|
17
|
-
let(:subclassed_entry) { subclass.new(raw, create_client.configuration) }
|
18
|
-
|
19
|
-
describe 'SystemProperties' do
|
20
|
-
it 'has a #sys getter returning a hash with symbol keys' do
|
21
|
-
expect(entry.sys).to be_a Hash
|
22
|
-
expect(entry.sys.keys.sample).to be_a Symbol
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'has #id' do
|
26
|
-
expect(entry.id).to eq 'nyancat'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'has #type' do
|
30
|
-
expect(entry.type).to eq 'Entry'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'has #space' do
|
34
|
-
expect(entry.space).to be_a Contentful::Link
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'has #content_type' do
|
38
|
-
expect(entry.content_type).to be_a Contentful::Link
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'has #created_at' do
|
42
|
-
expect(entry.created_at).to be_a DateTime
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'has #updated_at' do
|
46
|
-
expect(entry.updated_at).to be_a DateTime
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'has #revision' do
|
50
|
-
expect(entry.revision).to eq 5
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when subclassed' do
|
54
|
-
it 'does not redefine existing methods' do
|
55
|
-
expect(subclassed_entry.created_at).to eq 'yesterday'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'Fields' do
|
61
|
-
it 'has a #fields getter returning a hash with symbol keys' do
|
62
|
-
expect(entry.sys).to be_a Hash
|
63
|
-
expect(entry.sys.keys.sample).to be_a Symbol
|
64
|
-
end
|
65
|
-
|
66
|
-
it "contains the entry's fields" do
|
67
|
-
expect(entry.fields[:color]).to eq 'rainbow'
|
68
|
-
expect(entry.fields[:best_friend]).to be_a Contentful::Entry
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'when subclassed' do
|
72
|
-
it 'does not redefine existing methods' do
|
73
|
-
expect(subclassed_entry.best_friend).to eq 'octocat'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'multiple locales' do
|
79
|
-
it 'can handle multiple locales' do
|
80
|
-
vcr('entry_locales') {
|
81
|
-
nyancat = create_client.entries(locale: "*", 'sys.id' => 'nyancat').items.first
|
82
|
-
expect(nyancat.fields('en-US')[:name]).to eq "Nyan Cat"
|
83
|
-
expect(nyancat.fields('tlh')[:name]).to eq "Nyan vIghro'"
|
84
|
-
|
85
|
-
|
86
|
-
expect(nyancat.fields(:'en-US')[:name]).to eq "Nyan Cat"
|
87
|
-
expect(nyancat.fields(:tlh)[:name]).to eq "Nyan vIghro'"
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#fields_with_locales' do
|
92
|
-
it 'can handle entries with just 1 locale' do
|
93
|
-
vcr('entry') {
|
94
|
-
nyancat = create_client.entry('nyancat')
|
95
|
-
expect(nyancat.fields_with_locales[:name].size).to eq(1)
|
96
|
-
expect(nyancat.fields_with_locales[:name][:'en-US']).to eq("Nyan Cat")
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'can handle entries with multiple locales' do
|
101
|
-
vcr('entry_locales') {
|
102
|
-
nyancat = create_client.entries(locale: "*", 'sys.id' => 'nyancat').items.first
|
103
|
-
expect(nyancat.fields_with_locales[:name].size).to eq(2)
|
104
|
-
expect(nyancat.fields_with_locales[:name][:'en-US']).to eq("Nyan Cat")
|
105
|
-
expect(nyancat.fields_with_locales[:name][:tlh]).to eq("Nyan vIghro'")
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'can have references in multiple locales and they are properly solved' do
|
110
|
-
vcr('multi_locale_reference') {
|
111
|
-
client = create_client(
|
112
|
-
space: '1sjfpsn7l90g',
|
113
|
-
access_token: 'e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9',
|
114
|
-
dynamic_entries: :auto
|
115
|
-
)
|
116
|
-
|
117
|
-
entry = client.entries(locale: '*').first
|
118
|
-
|
119
|
-
expect(entry.image).to be_a ::Contentful::Asset
|
120
|
-
expect(entry.fields('zh')[:image]).to be_a ::Contentful::Asset
|
121
|
-
expect(entry.fields('es')[:image]).to be_a ::Contentful::Asset
|
122
|
-
|
123
|
-
expect(entry.image.id).not_to eq entry.fields('zh')[:image].id
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'can have references with arrays in multiple locales and have them properly solved' do
|
128
|
-
vcr('multi_locale_array_reference') {
|
129
|
-
client = create_client(
|
130
|
-
space: 'cma9f9g4dxvs',
|
131
|
-
access_token: '3e4560614990c9ac47343b9eea762bdaaebd845766f619660d7230787fd545e1',
|
132
|
-
dynamic_entries: :auto
|
133
|
-
)
|
134
|
-
|
135
|
-
entry = client.entries(content_type: 'test', locale: '*').first
|
136
|
-
|
137
|
-
expect(entry.files).to be_a ::Array
|
138
|
-
expect(entry.references).to be_a ::Array
|
139
|
-
expect(entry.files.first).to be_a ::Contentful::Asset
|
140
|
-
expect(entry.references.first.entry?).to be_truthy
|
141
|
-
|
142
|
-
expect(entry.fields('zh')[:files]).to be_a ::Array
|
143
|
-
expect(entry.fields('zh')[:references]).to be_a ::Array
|
144
|
-
expect(entry.fields('zh')[:files].first).to be_a ::Contentful::Asset
|
145
|
-
expect(entry.fields('zh')[:references].first.entry?).to be_truthy
|
146
|
-
|
147
|
-
expect(entry.files.first.id).not_to eq entry.fields('zh')[:files].first.id
|
148
|
-
}
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
it '#raw' do
|
154
|
-
vcr('entry/raw') {
|
155
|
-
nyancat = create_client.entry('nyancat')
|
156
|
-
expect(nyancat.raw).to eq(create_client(raw_mode: true).entry('nyancat').object['items'].first)
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
describe 'can be marshalled' do
|
161
|
-
def test_dump(nyancat)
|
162
|
-
dump = Marshal.dump(nyancat)
|
163
|
-
yield if block_given?
|
164
|
-
new_cat = Marshal.load(dump)
|
165
|
-
|
166
|
-
# Attributes
|
167
|
-
expect(new_cat).to be_a Contentful::Entry
|
168
|
-
expect(new_cat.name).to eq "Nyan Cat"
|
169
|
-
expect(new_cat.lives).to eq 1337
|
170
|
-
|
171
|
-
# Single linked objects
|
172
|
-
expect(new_cat.best_friend).to be_a Contentful::Entry
|
173
|
-
expect(new_cat.best_friend.name).to eq "Happy Cat"
|
174
|
-
|
175
|
-
# Array of linked objects
|
176
|
-
expect(new_cat.cat_pack.count).to eq 2
|
177
|
-
expect(new_cat.cat_pack[0].name).to eq "Happy Cat"
|
178
|
-
expect(new_cat.cat_pack[1].name).to eq "Worried Cat"
|
179
|
-
|
180
|
-
# Nested Links
|
181
|
-
expect(new_cat.best_friend.best_friend).to be_a Contentful::Entry
|
182
|
-
expect(new_cat.best_friend.best_friend.name).to eq "Nyan Cat"
|
183
|
-
|
184
|
-
# Asset
|
185
|
-
expect(new_cat.image.file.url).to eq "//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png"
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'marshals properly when entry_mapping changed' do
|
189
|
-
vcr('entry/marshall') {
|
190
|
-
class TestEntryMapping; end
|
191
|
-
nyancat = create_client(gzip_encoded: false, max_include_resolution_depth: 2, entry_mapping: { 'irrelevant_model' => TestEntryMapping }).entries(include: 2, 'sys.id' => 'nyancat').first
|
192
|
-
test_dump(nyancat) { Object.send(:remove_const, :TestEntryMapping) }
|
193
|
-
}
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'marshals properly' do
|
197
|
-
vcr('entry/marshall') {
|
198
|
-
nyancat = create_client(gzip_encoded: false, max_include_resolution_depth: 2).entries(include: 2, 'sys.id' => 'nyancat').first
|
199
|
-
test_dump(nyancat)
|
200
|
-
}
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'can remarshall an unmarshalled object' do
|
204
|
-
vcr('entry/marshall') {
|
205
|
-
nyancat = create_client(max_include_resolution_depth: 2).entries(include: 2, 'sys.id' => 'nyancat').first
|
206
|
-
|
207
|
-
# The double load/dump is on purpose
|
208
|
-
test_dump(Marshal.load(Marshal.dump(nyancat)))
|
209
|
-
}
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'can properly marshal multiple level nested resources - #138' do
|
213
|
-
vcr('entry/marshal_138') {
|
214
|
-
parent = create_client(
|
215
|
-
space: 'j8tb59fszch7',
|
216
|
-
access_token: '5f711401f965951eb724ac72ac905e13d892294ba209268f13a9b32e896c8694',
|
217
|
-
dynamic_entries: :auto,
|
218
|
-
max_include_resolution_depth: 5
|
219
|
-
).entry('5aV3O0l5jU0cwQ2OkyYsyU')
|
220
|
-
|
221
|
-
rehydrated = Marshal.load(Marshal.dump(parent))
|
222
|
-
|
223
|
-
expect(rehydrated.childs.first.image1.url).to eq '//images.contentful.com/j8tb59fszch7/7FjliblAmAoGMwU62MeQ6k/62509df90ef4bed38c0701bb9aa8c74c/Funny-Cat-Pictures-with-Captions-25.jpg'
|
224
|
-
expect(rehydrated.childs.first.image2.url).to eq '//images.contentful.com/j8tb59fszch7/1pbGuWZ27O6GMO0OGemgcA/a4185036a3640ad4491f38d8926003ab/Funny-Cat-Pictures-with-Captions-1.jpg'
|
225
|
-
expect(rehydrated.childs.last.image1.url).to eq '//images.contentful.com/j8tb59fszch7/4SXVTr0KEUyWiMMCOaUeUU/c9fa2246d5529a9c8e1ec6f5387dc4f6/e0194eca1c8135636ce0e014341548c3.jpg'
|
226
|
-
expect(rehydrated.childs.last.image2.url).to eq '//images.contentful.com/j8tb59fszch7/1NU1YcNQJGIA22gAKmKqWo/56fa672bb17a7b7ae2773d08e101d059/57ee64921c25faa649fc79288197c313.jpg'
|
227
|
-
}
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'filters out unpublished resources after rehydration' do
|
231
|
-
vcr('entry/marshal_unpublished') {
|
232
|
-
parent = create_client(
|
233
|
-
space: 'z3eix6mwjid2',
|
234
|
-
access_token: '9047c4394a2130dff8e9dc544a7a3ec299703fdac8e52575eb5a6678be06c468',
|
235
|
-
dynamic_entries: :auto
|
236
|
-
).entry('5Etc0jWzIWwMeSu4W0SCi8')
|
237
|
-
|
238
|
-
rehydrated = Marshal.load(Marshal.dump(parent))
|
239
|
-
|
240
|
-
expect(rehydrated.children).to be_empty
|
241
|
-
|
242
|
-
preview_parent = create_client(
|
243
|
-
space: 'z3eix6mwjid2',
|
244
|
-
access_token: '38153b942011a70b5482fda61c6a3a9d22f5e8a512662dac00fcf7eb344b75f4',
|
245
|
-
dynamic_entries: :auto,
|
246
|
-
api_url: 'preview.contentful.com'
|
247
|
-
).entry('5Etc0jWzIWwMeSu4W0SCi8')
|
248
|
-
|
249
|
-
preview_rehydrated = Marshal.load(Marshal.dump(preview_parent))
|
250
|
-
|
251
|
-
expect(preview_rehydrated.children).not_to be_empty
|
252
|
-
expect(preview_rehydrated.children.first.title).to eq 'Child'
|
253
|
-
}
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
describe 'incoming links' do
|
258
|
-
let(:client) { create_client }
|
259
|
-
|
260
|
-
it 'will fetch entries referencing the entry using a query' do
|
261
|
-
vcr('entry/search_link_to_entry') {
|
262
|
-
entries = client.entries(links_to_entry: 'nyancat')
|
263
|
-
expect(entries).not_to be_empty
|
264
|
-
expect(entries.count).to eq 1
|
265
|
-
expect(entries.first.id).to eq 'happycat'
|
266
|
-
}
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'will fetch entries referencing the entry using instance method' do
|
270
|
-
vcr('entry/search_link_to_entry') {
|
271
|
-
entries = entry.incoming_references client
|
272
|
-
expect(entries).not_to be_empty
|
273
|
-
expect(entries.count).to eq 1
|
274
|
-
expect(entries.first.id).to eq 'happycat'
|
275
|
-
}
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'will fetch entries referencing the entry using instance method + query' do
|
279
|
-
vcr('entry/search_link_to_entry_with_custom_query') {
|
280
|
-
entries = entry.incoming_references(client, { content_type: 'cat', select: ['fields.name'] })
|
281
|
-
expect(entries).not_to be_empty
|
282
|
-
expect(entries.count).to eq 1
|
283
|
-
expect(entries.first.id).to eq 'happycat'
|
284
|
-
expect(entries.first.fields.keys).to eq([:name])
|
285
|
-
}
|
286
|
-
end
|
287
|
-
|
288
|
-
end
|
289
|
-
|
290
|
-
describe 'select operator' do
|
291
|
-
let(:client) { create_client }
|
292
|
-
|
293
|
-
context 'with sys sent' do
|
294
|
-
it 'properly creates an entry' do
|
295
|
-
vcr('entry/select_only_sys') {
|
296
|
-
entry = client.entries(select: ['sys'], 'sys.id' => 'nyancat').first
|
297
|
-
expect(entry.fields).to be_empty
|
298
|
-
expect(entry.entry?).to be_truthy
|
299
|
-
}
|
300
|
-
end
|
301
|
-
|
302
|
-
describe 'can contain only one field' do
|
303
|
-
context 'with content_type sent' do
|
304
|
-
it 'will properly create the entry with one field' do
|
305
|
-
vcr('entry/select_one_field_proper') {
|
306
|
-
entry = client.entries(content_type: 'cat', select: ['sys', 'fields.name'], 'sys.id' => 'nyancat').first
|
307
|
-
expect(entry.fields).not_to be_empty
|
308
|
-
expect(entry.entry?).to be_truthy
|
309
|
-
expect(entry.fields[:name]).to eq 'Nyan Cat'
|
310
|
-
expect(entry.fields).to eq({name: 'Nyan Cat'})
|
311
|
-
}
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
context 'without content_type sent' do
|
316
|
-
it 'will raise an error' do
|
317
|
-
vcr('entry/select_one_field') {
|
318
|
-
expect { client.entries(select: ['sys', 'fields.name'], 'sys.id' => 'nyancat') }.to raise_error Contentful::BadRequest
|
319
|
-
}
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
context 'without sys sent' do
|
326
|
-
it 'will enforce sys anyway' do
|
327
|
-
vcr('entry/select_no_sys') {
|
328
|
-
entry = client.entries(select: ['fields'], 'sys.id' => 'nyancat').first
|
329
|
-
|
330
|
-
expect(entry.id).to eq 'nyancat'
|
331
|
-
expect(entry.sys).not_to be_empty
|
332
|
-
}
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'works with empty array as well, as sys is enforced' do
|
336
|
-
vcr('entry/select_empty_array') {
|
337
|
-
entry = client.entries(select: [], 'sys.id' => 'nyancat').first
|
338
|
-
|
339
|
-
expect(entry.id).to eq 'nyancat'
|
340
|
-
expect(entry.sys).not_to be_empty
|
341
|
-
}
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe 'reuse objects' do
|
347
|
-
it 'should handle recursion as well as not reusing' do
|
348
|
-
vcr('entry/include_resolution') {
|
349
|
-
entry = create_client(reuse_objects: true).entry('nyancat', include: 2)
|
350
|
-
|
351
|
-
expect(entry.best_friend.name).to eq 'Happy Cat'
|
352
|
-
expect(entry
|
353
|
-
.best_friend.best_friend
|
354
|
-
.best_friend.best_friend
|
355
|
-
.best_friend.best_friend
|
356
|
-
.best_friend.best_friend
|
357
|
-
.best_friend.best_friend
|
358
|
-
.best_friend.best_friend
|
359
|
-
.best_friend.best_friend
|
360
|
-
.best_friend.best_friend
|
361
|
-
.best_friend.best_friend
|
362
|
-
.best_friend.best_friend.name).to eq 'Nyan Cat'
|
363
|
-
}
|
364
|
-
end
|
365
|
-
it 'should use the same object for the same entry' do
|
366
|
-
vcr('entry/include_resolution') {
|
367
|
-
entry = create_client(reuse_entries: true).entry('nyancat', include: 2)
|
368
|
-
|
369
|
-
expect(entry.best_friend.name).to eq 'Happy Cat'
|
370
|
-
expect(entry.best_friend.best_friend).to be(entry)
|
371
|
-
}
|
372
|
-
end
|
373
|
-
it 'works on nested structures with unique objects' do
|
374
|
-
vcr('entry/include_resolution_uniques') {
|
375
|
-
entry = create_client(
|
376
|
-
space: 'v7cxgyxt0w5x',
|
377
|
-
access_token: '96e5d256e9a5349ce30e84356597e409f8f1bb485cb4719285b555e0f78aa27e',
|
378
|
-
reuse_entries: true
|
379
|
-
).entry('1nLXjjWvk4MEeWeQCWmymc', include: 10)
|
380
|
-
|
381
|
-
expect(entry.title).to eq '1'
|
382
|
-
expect(entry
|
383
|
-
.child.child
|
384
|
-
.child.child
|
385
|
-
.child.child
|
386
|
-
.child.child
|
387
|
-
.child.title).to eq '10'
|
388
|
-
expect(entry
|
389
|
-
.child.child
|
390
|
-
.child.child
|
391
|
-
.child.child
|
392
|
-
.child.child
|
393
|
-
.child.child.title).to eq '1'
|
394
|
-
expect(entry
|
395
|
-
.child.child.child.child
|
396
|
-
.child.child.child.child
|
397
|
-
.child.child.child.child
|
398
|
-
.child.child.child.child
|
399
|
-
.child.child.child.child.title).to eq '1'
|
400
|
-
}
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
describe 'include resolution' do
|
405
|
-
it 'should not reuse objects by default' do
|
406
|
-
vcr('entry/include_resolution') {
|
407
|
-
entry = create_client.entry('nyancat', include: 2)
|
408
|
-
|
409
|
-
expect(entry.best_friend.name).to eq 'Happy Cat'
|
410
|
-
expect(entry.best_friend.best_friend).not_to be(entry)
|
411
|
-
}
|
412
|
-
end
|
413
|
-
it 'defaults to 20 depth' do
|
414
|
-
vcr('entry/include_resolution') {
|
415
|
-
entry = create_client.entry('nyancat', include: 2)
|
416
|
-
|
417
|
-
expect(entry.best_friend.name).to eq 'Happy Cat'
|
418
|
-
expect(entry
|
419
|
-
.best_friend.best_friend
|
420
|
-
.best_friend.best_friend
|
421
|
-
.best_friend.best_friend
|
422
|
-
.best_friend.best_friend
|
423
|
-
.best_friend.best_friend
|
424
|
-
.best_friend.best_friend
|
425
|
-
.best_friend.best_friend
|
426
|
-
.best_friend.best_friend
|
427
|
-
.best_friend.best_friend
|
428
|
-
.best_friend.best_friend.name).to eq 'Nyan Cat'
|
429
|
-
|
430
|
-
expect(entry
|
431
|
-
.best_friend.best_friend
|
432
|
-
.best_friend.best_friend
|
433
|
-
.best_friend.best_friend
|
434
|
-
.best_friend.best_friend
|
435
|
-
.best_friend.best_friend
|
436
|
-
.best_friend.best_friend
|
437
|
-
.best_friend.best_friend
|
438
|
-
.best_friend.best_friend
|
439
|
-
.best_friend.best_friend
|
440
|
-
.best_friend.best_friend
|
441
|
-
.best_friend).to be_a ::Contentful::Link
|
442
|
-
}
|
443
|
-
end
|
444
|
-
|
445
|
-
it 'can be configured arbitrarily' do
|
446
|
-
vcr('entry/include_resolution') {
|
447
|
-
entry = create_client(max_include_resolution_depth: 3).entry('nyancat', include: 2)
|
448
|
-
|
449
|
-
expect(entry.best_friend.name).to eq 'Happy Cat'
|
450
|
-
expect(entry
|
451
|
-
.best_friend.best_friend
|
452
|
-
.best_friend.name).to eq 'Happy Cat'
|
453
|
-
expect(entry
|
454
|
-
.best_friend.best_friend
|
455
|
-
.best_friend.best_friend).to be_a ::Contentful::Link
|
456
|
-
}
|
457
|
-
end
|
458
|
-
it 'works on nested structures with unique objects' do
|
459
|
-
vcr('entry/include_resolution_uniques') {
|
460
|
-
entry = create_client(
|
461
|
-
space: 'v7cxgyxt0w5x',
|
462
|
-
access_token: '96e5d256e9a5349ce30e84356597e409f8f1bb485cb4719285b555e0f78aa27e',
|
463
|
-
).entry('1nLXjjWvk4MEeWeQCWmymc', include: 10)
|
464
|
-
|
465
|
-
expect(entry.title).to eq '1'
|
466
|
-
expect(entry
|
467
|
-
.child.child
|
468
|
-
.child.child
|
469
|
-
.child.child
|
470
|
-
.child.child
|
471
|
-
.child.title).to eq '10'
|
472
|
-
expect(entry
|
473
|
-
.child.child
|
474
|
-
.child.child
|
475
|
-
.child.child
|
476
|
-
.child.child
|
477
|
-
.child.child.title).to eq '1'
|
478
|
-
expect(entry
|
479
|
-
.child.child.child.child
|
480
|
-
.child.child.child.child
|
481
|
-
.child.child.child.child
|
482
|
-
.child.child.child.child
|
483
|
-
.child.child.child.child.title).to eq '1'
|
484
|
-
}
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
describe 'issues' do
|
489
|
-
it 'filters out unresolvable assets' do
|
490
|
-
vcr('entries/unresolvable_assets') {
|
491
|
-
client = create_client(space: 'facgnwwgj5fe', access_token: '4d0f55d940975f78139daae5d965b463c0816e88ad16062d2c1ee3d6cb930521')
|
492
|
-
entry = client.entry('gLVzQlb09IeOeU181fwtz')
|
493
|
-
|
494
|
-
expect(entry.single_asset).to be_nil
|
495
|
-
expect(entry.multi_asset.size).to eq 1
|
496
|
-
expect(entry.raw["fields"]["multiAsset"].size).to eq 2
|
497
|
-
}
|
498
|
-
end
|
499
|
-
|
500
|
-
it 'Symbol/Text field with null values should be serialized as nil - #117' do
|
501
|
-
vcr('entries/issue_117') {
|
502
|
-
client = create_client(space: '8jbbayggj9gj', access_token: '4ce0108f04e55c76476ba84ab0e6149734db73d67cd1b429323ef67f00977e07')
|
503
|
-
entry = client.entries.first
|
504
|
-
|
505
|
-
expect(entry.nil).to be_nil
|
506
|
-
expect(entry.nil).not_to eq ''
|
507
|
-
}
|
508
|
-
end
|
509
|
-
|
510
|
-
describe 'JSON Fields should not be treated as locale data - #96' do
|
511
|
-
before do
|
512
|
-
vcr('entry/json_objects_client') {
|
513
|
-
@client = create_client(
|
514
|
-
space: 'h425t6gef30p',
|
515
|
-
access_token: '278f7aa72f2eb90c0e002d60f85bf2144c925acd2d37dd990d3ca274f25076cf',
|
516
|
-
dynamic_entries: :auto
|
517
|
-
)
|
518
|
-
|
519
|
-
}
|
520
|
-
vcr('entry/json_objects') {
|
521
|
-
@entry = @client.entries.first
|
522
|
-
}
|
523
|
-
end
|
524
|
-
|
525
|
-
it 'only has default locale' do
|
526
|
-
expect(@entry.locales).to eq ['en-US']
|
527
|
-
end
|
528
|
-
|
529
|
-
it 'can obtain all values properly' do
|
530
|
-
expect(@entry.name).to eq('Test')
|
531
|
-
expect(@entry.object_test).to eq({
|
532
|
-
null: nil,
|
533
|
-
text: 'some text',
|
534
|
-
array: [1, 2, 3],
|
535
|
-
number: 123,
|
536
|
-
boolean: true,
|
537
|
-
object: {
|
538
|
-
null: nil,
|
539
|
-
text: 'bar',
|
540
|
-
array: [1, 2, 3],
|
541
|
-
number: 123,
|
542
|
-
boolean: false,
|
543
|
-
object: {foo: 'bar'}
|
544
|
-
}
|
545
|
-
})
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
it 'Number (Integer and Decimal) values get properly serialized - #125' do
|
550
|
-
vcr('entries/issue_125') {
|
551
|
-
client = create_client(space: 'zui87wsu8q80', access_token: '64ff902c58cd14ea063d3ded810d1111a0266537e9aba283bad3319b1762c302', dynamic_entries: :auto)
|
552
|
-
entry = client.entries.first
|
553
|
-
|
554
|
-
expect(entry.integer).to eq 123
|
555
|
-
expect(entry.decimal).to eq 12.3
|
556
|
-
}
|
557
|
-
end
|
558
|
-
|
559
|
-
it 'unresolvable entries get filtered from results' do
|
560
|
-
vcr('entries/unresolvable_filter') {
|
561
|
-
client = create_client(space: '011npgaszg5o', access_token: '42c9d93410a7319e9a735671fc1e415348f65e94a99fc768b70a7c649859d4fd', dynamic_entries: :auto)
|
562
|
-
entry = client.entry('1HR1QvURo4MoSqO0eqmUeO')
|
563
|
-
|
564
|
-
expect(entry.modules.size).to eq 2
|
565
|
-
}
|
566
|
-
end
|
567
|
-
|
568
|
-
it 'unresolvable entries get filtered from results in deeply nested objects - #177' do
|
569
|
-
vcr('entries/unresolvable_filter_deeply_nested') {
|
570
|
-
client = create_client(space: 'z471hdso7l1a', access_token: '8a0e09fe71f1cb41e8788ace86a8c8d9d084599fe43a40070f232045014d2585', dynamic_entries: :auto)
|
571
|
-
entry = client.entry('1hb8sipClkQ8ggeGaeSQWm', include: 3)
|
572
|
-
expect(entry.should_published.first.should_unpublished.size).to eq 0
|
573
|
-
}
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
describe 'camel case' do
|
578
|
-
it 'supports camel case' do
|
579
|
-
vcr('entry') {
|
580
|
-
entry = create_client(use_camel_case: true).entry 'nyancat'
|
581
|
-
|
582
|
-
expect(entry.bestFriend.name).to eq 'Happy Cat'
|
583
|
-
expect(entry.createdAt).to be_a DateTime
|
584
|
-
}
|
585
|
-
end
|
586
|
-
end
|
587
|
-
|
588
|
-
describe 'empty fields' do
|
589
|
-
context 'when default configuration' do
|
590
|
-
it 'raises an exception by default' do
|
591
|
-
vcr('entries/empty_fields') {
|
592
|
-
entry = create_client(
|
593
|
-
space: 'z4ssexir3p93',
|
594
|
-
access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
|
595
|
-
dynamic_entries: :auto
|
596
|
-
).entry('2t1x77MgUA4SM2gMiaUcsy')
|
597
|
-
|
598
|
-
expect { entry.title }.to raise_error Contentful::EmptyFieldError
|
599
|
-
}
|
600
|
-
end
|
601
|
-
|
602
|
-
it 'returns nil if raise_for_empty_fields is false' do
|
603
|
-
vcr('entries/empty_fields') {
|
604
|
-
entry = create_client(
|
605
|
-
space: 'z4ssexir3p93',
|
606
|
-
access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
|
607
|
-
dynamic_entries: :auto,
|
608
|
-
raise_for_empty_fields: false
|
609
|
-
).entry('2t1x77MgUA4SM2gMiaUcsy')
|
610
|
-
|
611
|
-
expect(entry.title).to be_nil
|
612
|
-
}
|
613
|
-
end
|
614
|
-
|
615
|
-
it 'will properly raise NoMethodError for non-fields' do
|
616
|
-
vcr('entries/empty_fields') {
|
617
|
-
entry = create_client(
|
618
|
-
space: 'z4ssexir3p93',
|
619
|
-
access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
|
620
|
-
dynamic_entries: :auto
|
621
|
-
).entry('2t1x77MgUA4SM2gMiaUcsy')
|
622
|
-
|
623
|
-
expect { entry.unexisting_field }.to raise_error NoMethodError
|
624
|
-
}
|
625
|
-
end
|
626
|
-
end
|
627
|
-
|
628
|
-
context 'when use_camel_case is true it should still work' do
|
629
|
-
it 'raises an exception by default' do
|
630
|
-
vcr('entries/empty_fields') {
|
631
|
-
entry = create_client(
|
632
|
-
space: 'z4ssexir3p93',
|
633
|
-
access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
|
634
|
-
dynamic_entries: :auto,
|
635
|
-
use_camel_case: true
|
636
|
-
).entry('2t1x77MgUA4SM2gMiaUcsy')
|
637
|
-
|
638
|
-
expect { entry.title }.to raise_error Contentful::EmptyFieldError
|
639
|
-
}
|
640
|
-
end
|
641
|
-
|
642
|
-
it 'returns nil if raise_for_empty_fields is false' do
|
643
|
-
vcr('entries/empty_fields') {
|
644
|
-
entry = create_client(
|
645
|
-
space: 'z4ssexir3p93',
|
646
|
-
access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
|
647
|
-
dynamic_entries: :auto,
|
648
|
-
raise_for_empty_fields: false,
|
649
|
-
use_camel_case: true
|
650
|
-
).entry('2t1x77MgUA4SM2gMiaUcsy')
|
651
|
-
|
652
|
-
expect(entry.title).to be_nil
|
653
|
-
}
|
654
|
-
end
|
655
|
-
|
656
|
-
it 'will properly raise NoMethodError for non-fields' do
|
657
|
-
vcr('entries/empty_fields') {
|
658
|
-
entry = create_client(
|
659
|
-
space: 'z4ssexir3p93',
|
660
|
-
access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
|
661
|
-
dynamic_entries: :auto,
|
662
|
-
use_camel_case: true
|
663
|
-
).entry('2t1x77MgUA4SM2gMiaUcsy')
|
664
|
-
|
665
|
-
expect { entry.unexisting_field }.to raise_error NoMethodError
|
666
|
-
}
|
667
|
-
end
|
668
|
-
end
|
669
|
-
end
|
670
|
-
|
671
|
-
describe 'rich text support' do
|
672
|
-
it 'properly serializes and resolves includes' do
|
673
|
-
vcr('entries/rich_text') {
|
674
|
-
entry = create_client(
|
675
|
-
space: 'jd7yc4wnatx3',
|
676
|
-
access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
|
677
|
-
raise_errors: true,
|
678
|
-
dynamic_entries: :auto,
|
679
|
-
gzip_encoded: false
|
680
|
-
).entry('4BupPSmi4M02m0U48AQCSM')
|
681
|
-
|
682
|
-
expected_entry_occurrances = 2
|
683
|
-
embedded_entry_index = 1
|
684
|
-
entry.body['content'].each do |content|
|
685
|
-
if content['nodeType'] == 'embedded-entry-block'
|
686
|
-
expect(content['data']['target']).to be_a Contentful::Entry
|
687
|
-
expect(content['data']['target'].body).to eq "Embedded #{embedded_entry_index}"
|
688
|
-
expected_entry_occurrances -= 1
|
689
|
-
embedded_entry_index += 1
|
690
|
-
end
|
691
|
-
end
|
692
|
-
|
693
|
-
expect(expected_entry_occurrances).to eq 0
|
694
|
-
}
|
695
|
-
end
|
696
|
-
|
697
|
-
it 'doesnt hydrate the same entry twice - #194' do
|
698
|
-
vcr('entries/rich_text_hydration_issue') {
|
699
|
-
entry = nil
|
700
|
-
|
701
|
-
expect {
|
702
|
-
entry = create_client(
|
703
|
-
space: 'fds721b88p6b',
|
704
|
-
access_token: '45ba81cc69423fcd2e3f0a4779de29481bb5c11495bc7e14649a996cf984e98e',
|
705
|
-
raise_errors: true,
|
706
|
-
dynamic_entries: :auto,
|
707
|
-
gzip_encoded: false
|
708
|
-
).entry('1tBAu0wP9qAQEg6qCqMics')
|
709
|
-
}.not_to raise_error
|
710
|
-
|
711
|
-
expect(entry.children[0].id).to eq entry.children[1].id
|
712
|
-
expect(entry.children[0].body).to eq entry.children[1].body
|
713
|
-
}
|
714
|
-
end
|
715
|
-
|
716
|
-
it 'respects content in data attribute if its not a Link' do
|
717
|
-
vcr('entries/rich_text_nested_fields') {
|
718
|
-
entry = create_client(
|
719
|
-
space: 'jd7yc4wnatx3',
|
720
|
-
access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
|
721
|
-
raise_errors: true,
|
722
|
-
dynamic_entries: :auto,
|
723
|
-
gzip_encoded: false
|
724
|
-
).entry('6NGLswCREsGA28kGouScyY')
|
725
|
-
|
726
|
-
expect(entry.body['content'][0]).to eq({
|
727
|
-
'data' => {},
|
728
|
-
'content' => [
|
729
|
-
{'marks' => [], 'value' => 'A link to ', 'nodeType' => 'text', 'nodeClass' => 'text'},
|
730
|
-
{
|
731
|
-
'data' => {'uri' => 'https://google.com'},
|
732
|
-
'content' => [{'marks' => [], 'value' => 'google', 'nodeType' => 'text', 'nodeClass' => 'text'}],
|
733
|
-
'nodeType' => 'hyperlink',
|
734
|
-
'nodeClass' => 'inline'
|
735
|
-
},
|
736
|
-
{'marks' => [], 'value' => '', 'nodeType' => 'text', 'nodeClass' => 'text'}
|
737
|
-
],
|
738
|
-
'nodeType' => 'paragraph',
|
739
|
-
'nodeClass' => 'block'
|
740
|
-
})
|
741
|
-
}
|
742
|
-
end
|
743
|
-
|
744
|
-
it 'supports includes in nested fields' do
|
745
|
-
vcr('entries/rich_text_nested_fields') {
|
746
|
-
entry = create_client(
|
747
|
-
space: 'jd7yc4wnatx3',
|
748
|
-
access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
|
749
|
-
raise_errors: true,
|
750
|
-
dynamic_entries: :auto,
|
751
|
-
gzip_encoded: false
|
752
|
-
).entry('6NGLswCREsGA28kGouScyY')
|
753
|
-
|
754
|
-
expect(entry.body['content'][3]['nodeType']).to eq('unordered-list')
|
755
|
-
expect(entry.body['content'][3]['content'][2]['content'][0]['data']['target'].is_a?(Contentful::Entry)).to be_truthy
|
756
|
-
|
757
|
-
expect(entry.body['content'][4]['nodeType']).to eq('ordered-list')
|
758
|
-
expect(entry.body['content'][4]['content'][2]['content'][0]['data']['target'].is_a?(Contentful::Entry)).to be_truthy
|
759
|
-
}
|
760
|
-
end
|
761
|
-
|
762
|
-
it 'returns a link when resource is valid but unreachable' do
|
763
|
-
vcr('entries/rich_text_unresolved_relationships') {
|
764
|
-
parent = create_client(
|
765
|
-
space: 'jd7yc4wnatx3',
|
766
|
-
access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
|
767
|
-
raise_errors: true,
|
768
|
-
dynamic_entries: :auto,
|
769
|
-
gzip_encoded: false
|
770
|
-
).entry('4fvSwl5Ob6UEWKg6MQicuC')
|
771
|
-
|
772
|
-
entry = parent.rich_text_child
|
773
|
-
expect(entry.body['content'][19]['data']['target'].is_a?(Contentful::Link)).to be_truthy
|
774
|
-
}
|
775
|
-
end
|
776
|
-
end
|
777
|
-
end
|