contentful 2.16.0 → 2.16.1

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