contentful 2.15.1 → 2.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +11 -0
  4. data/lib/contentful/array_like.rb +11 -2
  5. data/lib/contentful/asset.rb +4 -0
  6. data/lib/contentful/base_resource.rb +14 -2
  7. data/lib/contentful/client.rb +1 -2
  8. data/lib/contentful/entry.rb +2 -1
  9. data/lib/contentful/request.rb +6 -1
  10. data/lib/contentful/version.rb +1 -1
  11. metadata +10 -371
  12. data/.gitignore +0 -7
  13. data/.rspec +0 -1
  14. data/.rubocop.yml +0 -31
  15. data/.rubocop_todo.yml +0 -35
  16. data/.travis.yml +0 -14
  17. data/.yardopts +0 -4
  18. data/Gemfile +0 -9
  19. data/Guardfile +0 -24
  20. data/RELEASE.md +0 -8
  21. data/Rakefile +0 -33
  22. data/contentful.gemspec +0 -44
  23. data/examples/custom_classes.rb +0 -39
  24. data/examples/example_queries.rb +0 -26
  25. data/examples/raise_errors.rb +0 -20
  26. data/examples/raw_mode.rb +0 -14
  27. data/spec/array_spec.rb +0 -167
  28. data/spec/asset_spec.rb +0 -192
  29. data/spec/auto_includes_spec.rb +0 -12
  30. data/spec/client_class_spec.rb +0 -86
  31. data/spec/client_configuration_spec.rb +0 -377
  32. data/spec/content_type_spec.rb +0 -49
  33. data/spec/deleted_asset_spec.rb +0 -38
  34. data/spec/deleted_entry_spec.rb +0 -38
  35. data/spec/entry_spec.rb +0 -766
  36. data/spec/error_class_spec.rb +0 -327
  37. data/spec/error_requests_spec.rb +0 -87
  38. data/spec/field_spec.rb +0 -95
  39. data/spec/file_spec.rb +0 -33
  40. data/spec/fixtures/json_responses/400_details_errors_object.json +0 -14
  41. data/spec/fixtures/json_responses/400_details_errors_string.json +0 -12
  42. data/spec/fixtures/json_responses/400_details_string.json +0 -8
  43. data/spec/fixtures/json_responses/403_reasons.json +0 -13
  44. data/spec/fixtures/json_responses/404_details_string.json +0 -8
  45. data/spec/fixtures/json_responses/404_id.json +0 -11
  46. data/spec/fixtures/json_responses/404_sys_type.json +0 -12
  47. data/spec/fixtures/json_responses/404_type.json +0 -10
  48. data/spec/fixtures/json_responses/content_type.json +0 -83
  49. data/spec/fixtures/json_responses/default_400.json +0 -7
  50. data/spec/fixtures/json_responses/default_401.json +0 -7
  51. data/spec/fixtures/json_responses/default_403.json +0 -7
  52. data/spec/fixtures/json_responses/default_404.json +0 -7
  53. data/spec/fixtures/json_responses/default_429.json +0 -7
  54. data/spec/fixtures/json_responses/default_500.json +0 -7
  55. data/spec/fixtures/json_responses/default_502.json +0 -7
  56. data/spec/fixtures/json_responses/default_503.json +0 -7
  57. data/spec/fixtures/json_responses/includes.json +0 -111
  58. data/spec/fixtures/json_responses/link_array.json +0 -43
  59. data/spec/fixtures/json_responses/not_found.json +0 -13
  60. data/spec/fixtures/json_responses/nyancat.json +0 -48
  61. data/spec/fixtures/json_responses/other_error.json +0 -9
  62. data/spec/fixtures/json_responses/other_error_no_details.json +0 -8
  63. data/spec/fixtures/json_responses/other_error_no_message.json +0 -8
  64. data/spec/fixtures/json_responses/other_error_no_request_id.json +0 -8
  65. data/spec/fixtures/json_responses/other_error_nothing.json +0 -6
  66. data/spec/fixtures/json_responses/self_link.json +0 -82
  67. data/spec/fixtures/json_responses/unparsable.json +0 -13
  68. data/spec/fixtures/vcr_cassettes/array.yml +0 -288
  69. data/spec/fixtures/vcr_cassettes/array/marshal_custom_classes.yml +0 -159
  70. data/spec/fixtures/vcr_cassettes/array/marshal_unpublished.yml +0 -315
  71. data/spec/fixtures/vcr_cassettes/array/nested_resources.yml +0 -159
  72. data/spec/fixtures/vcr_cassettes/arrayField.yml +0 -87
  73. data/spec/fixtures/vcr_cassettes/array_page_1.yml +0 -106
  74. data/spec/fixtures/vcr_cassettes/array_page_2.yml +0 -73
  75. data/spec/fixtures/vcr_cassettes/asset.yml +0 -96
  76. data/spec/fixtures/vcr_cassettes/asset/select_empty_array.yml +0 -104
  77. data/spec/fixtures/vcr_cassettes/asset/select_no_sys.yml +0 -119
  78. data/spec/fixtures/vcr_cassettes/asset/select_one_field.yml +0 -97
  79. data/spec/fixtures/vcr_cassettes/asset/select_only_sys.yml +0 -88
  80. data/spec/fixtures/vcr_cassettes/assets/issues_129.yml +0 -90
  81. data/spec/fixtures/vcr_cassettes/assets/issues_jekyll_46.yml +0 -115
  82. data/spec/fixtures/vcr_cassettes/bad_request.yml +0 -76
  83. data/spec/fixtures/vcr_cassettes/content_type.yml +0 -147
  84. data/spec/fixtures/vcr_cassettes/entries.yml +0 -561
  85. data/spec/fixtures/vcr_cassettes/entries/empty_fields.yml +0 -246
  86. data/spec/fixtures/vcr_cassettes/entries/issue_117.yml +0 -201
  87. data/spec/fixtures/vcr_cassettes/entries/issue_125.yml +0 -198
  88. data/spec/fixtures/vcr_cassettes/entries/rich_text.yml +0 -1707
  89. data/spec/fixtures/vcr_cassettes/entries/rich_text_hydration_issue.yml +0 -460
  90. data/spec/fixtures/vcr_cassettes/entries/rich_text_nested_fields.yml +0 -653
  91. data/spec/fixtures/vcr_cassettes/entries/rich_text_unresolved_relationships.yml +0 -983
  92. data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml +0 -159
  93. data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml +0 -167
  94. data/spec/fixtures/vcr_cassettes/entry.yml +0 -102
  95. data/spec/fixtures/vcr_cassettes/entry/custom_resource.yml +0 -168
  96. data/spec/fixtures/vcr_cassettes/entry/include_resolution.yml +0 -101
  97. data/spec/fixtures/vcr_cassettes/entry/include_resolution_uniques.yml +0 -81
  98. data/spec/fixtures/vcr_cassettes/entry/json_objects.yml +0 -88
  99. data/spec/fixtures/vcr_cassettes/entry/json_objects_client.yml +0 -86
  100. data/spec/fixtures/vcr_cassettes/entry/marshal_138.yml +0 -159
  101. data/spec/fixtures/vcr_cassettes/entry/marshal_unpublished.yml +0 -303
  102. data/spec/fixtures/vcr_cassettes/entry/marshall.yml +0 -293
  103. data/spec/fixtures/vcr_cassettes/entry/raw.yml +0 -201
  104. data/spec/fixtures/vcr_cassettes/entry/search_link_to_asset.yml +0 -81
  105. data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry.yml +0 -81
  106. data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry_with_custom_query.yml +0 -115
  107. data/spec/fixtures/vcr_cassettes/entry/select_empty_array.yml +0 -111
  108. data/spec/fixtures/vcr_cassettes/entry/select_no_sys.yml +0 -102
  109. data/spec/fixtures/vcr_cassettes/entry/select_one_field.yml +0 -76
  110. data/spec/fixtures/vcr_cassettes/entry/select_one_field_proper.yml +0 -114
  111. data/spec/fixtures/vcr_cassettes/entry/select_only_sys.yml +0 -111
  112. data/spec/fixtures/vcr_cassettes/entry_cache.yml +0 -288
  113. data/spec/fixtures/vcr_cassettes/entry_locales.yml +0 -104
  114. data/spec/fixtures/vcr_cassettes/field.yml +0 -147
  115. data/spec/fixtures/vcr_cassettes/human.yml +0 -118
  116. data/spec/fixtures/vcr_cassettes/linkField.yml +0 -83
  117. data/spec/fixtures/vcr_cassettes/locale.yml +0 -83
  118. data/spec/fixtures/vcr_cassettes/locale_from_environment.yml +0 -121
  119. data/spec/fixtures/vcr_cassettes/location.yml +0 -193
  120. data/spec/fixtures/vcr_cassettes/multi_locale_array_reference.yml +0 -196
  121. data/spec/fixtures/vcr_cassettes/multi_locale_reference.yml +0 -214
  122. data/spec/fixtures/vcr_cassettes/not_found.yml +0 -76
  123. data/spec/fixtures/vcr_cassettes/nyancat.yml +0 -102
  124. data/spec/fixtures/vcr_cassettes/query_array_1.yml +0 -89
  125. data/spec/fixtures/vcr_cassettes/query_array_2.yml +0 -89
  126. data/spec/fixtures/vcr_cassettes/ratelimit.yml +0 -64
  127. data/spec/fixtures/vcr_cassettes/ratelimit_retry.yml +0 -294
  128. data/spec/fixtures/vcr_cassettes/reloaded_entry.yml +0 -102
  129. data/spec/fixtures/vcr_cassettes/space.yml +0 -83
  130. data/spec/fixtures/vcr_cassettes/sync_deleted_asset.yml +0 -174
  131. data/spec/fixtures/vcr_cassettes/sync_deleted_entry.yml +0 -89
  132. data/spec/fixtures/vcr_cassettes/sync_deletion.yml +0 -191
  133. data/spec/fixtures/vcr_cassettes/sync_environment.yml +0 -81
  134. data/spec/fixtures/vcr_cassettes/sync_page.yml +0 -637
  135. data/spec/fixtures/vcr_cassettes/sync_page_2.yml +0 -71
  136. data/spec/fixtures/vcr_cassettes/sync_page_short.yml +0 -106
  137. data/spec/fixtures/vcr_cassettes/unauthorized.yml +0 -64
  138. data/spec/fixtures/vcr_cassettes/unavailable.yml +0 -76
  139. data/spec/link_spec.rb +0 -50
  140. data/spec/locale_spec.rb +0 -37
  141. data/spec/location_spec.rb +0 -25
  142. data/spec/request_spec.rb +0 -57
  143. data/spec/resource_building_spec.rb +0 -31
  144. data/spec/response_spec.rb +0 -62
  145. data/spec/space_spec.rb +0 -31
  146. data/spec/spec_helper.rb +0 -14
  147. data/spec/support/client.rb +0 -6
  148. data/spec/support/json_responses.rb +0 -18
  149. data/spec/support/vcr.rb +0 -16
  150. data/spec/sync_page_spec.rb +0 -103
  151. 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,766 +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 'Symbol/Text field with null values should be serialized as nil - #117' do
490
- vcr('entries/issue_117') {
491
- client = create_client(space: '8jbbayggj9gj', access_token: '4ce0108f04e55c76476ba84ab0e6149734db73d67cd1b429323ef67f00977e07')
492
- entry = client.entries.first
493
-
494
- expect(entry.nil).to be_nil
495
- expect(entry.nil).not_to eq ''
496
- }
497
- end
498
-
499
- describe 'JSON Fields should not be treated as locale data - #96' do
500
- before do
501
- vcr('entry/json_objects_client') {
502
- @client = create_client(
503
- space: 'h425t6gef30p',
504
- access_token: '278f7aa72f2eb90c0e002d60f85bf2144c925acd2d37dd990d3ca274f25076cf',
505
- dynamic_entries: :auto
506
- )
507
-
508
- }
509
- vcr('entry/json_objects') {
510
- @entry = @client.entries.first
511
- }
512
- end
513
-
514
- it 'only has default locale' do
515
- expect(@entry.locales).to eq ['en-US']
516
- end
517
-
518
- it 'can obtain all values properly' do
519
- expect(@entry.name).to eq('Test')
520
- expect(@entry.object_test).to eq({
521
- null: nil,
522
- text: 'some text',
523
- array: [1, 2, 3],
524
- number: 123,
525
- boolean: true,
526
- object: {
527
- null: nil,
528
- text: 'bar',
529
- array: [1, 2, 3],
530
- number: 123,
531
- boolean: false,
532
- object: {foo: 'bar'}
533
- }
534
- })
535
- end
536
- end
537
-
538
- it 'Number (Integer and Decimal) values get properly serialized - #125' do
539
- vcr('entries/issue_125') {
540
- client = create_client(space: 'zui87wsu8q80', access_token: '64ff902c58cd14ea063d3ded810d1111a0266537e9aba283bad3319b1762c302', dynamic_entries: :auto)
541
- entry = client.entries.first
542
-
543
- expect(entry.integer).to eq 123
544
- expect(entry.decimal).to eq 12.3
545
- }
546
- end
547
-
548
- it 'unresolvable entries get filtered from results' do
549
- vcr('entries/unresolvable_filter') {
550
- client = create_client(space: '011npgaszg5o', access_token: '42c9d93410a7319e9a735671fc1e415348f65e94a99fc768b70a7c649859d4fd', dynamic_entries: :auto)
551
- entry = client.entry('1HR1QvURo4MoSqO0eqmUeO')
552
-
553
- expect(entry.modules.size).to eq 2
554
- }
555
- end
556
-
557
- it 'unresolvable entries get filtered from results in deeply nested objects - #177' do
558
- vcr('entries/unresolvable_filter_deeply_nested') {
559
- client = create_client(space: 'z471hdso7l1a', access_token: '8a0e09fe71f1cb41e8788ace86a8c8d9d084599fe43a40070f232045014d2585', dynamic_entries: :auto)
560
- entry = client.entry('1hb8sipClkQ8ggeGaeSQWm', include: 3)
561
- expect(entry.should_published.first.should_unpublished.size).to eq 0
562
- }
563
- end
564
- end
565
-
566
- describe 'camel case' do
567
- it 'supports camel case' do
568
- vcr('entry') {
569
- entry = create_client(use_camel_case: true).entry 'nyancat'
570
-
571
- expect(entry.bestFriend.name).to eq 'Happy Cat'
572
- expect(entry.createdAt).to be_a DateTime
573
- }
574
- end
575
- end
576
-
577
- describe 'empty fields' do
578
- context 'when default configuration' do
579
- it 'raises an exception by default' do
580
- vcr('entries/empty_fields') {
581
- entry = create_client(
582
- space: 'z4ssexir3p93',
583
- access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
584
- dynamic_entries: :auto
585
- ).entry('2t1x77MgUA4SM2gMiaUcsy')
586
-
587
- expect { entry.title }.to raise_error Contentful::EmptyFieldError
588
- }
589
- end
590
-
591
- it 'returns nil if raise_for_empty_fields is false' do
592
- vcr('entries/empty_fields') {
593
- entry = create_client(
594
- space: 'z4ssexir3p93',
595
- access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
596
- dynamic_entries: :auto,
597
- raise_for_empty_fields: false
598
- ).entry('2t1x77MgUA4SM2gMiaUcsy')
599
-
600
- expect(entry.title).to be_nil
601
- }
602
- end
603
-
604
- it 'will properly raise NoMethodError for non-fields' do
605
- vcr('entries/empty_fields') {
606
- entry = create_client(
607
- space: 'z4ssexir3p93',
608
- access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
609
- dynamic_entries: :auto
610
- ).entry('2t1x77MgUA4SM2gMiaUcsy')
611
-
612
- expect { entry.unexisting_field }.to raise_error NoMethodError
613
- }
614
- end
615
- end
616
-
617
- context 'when use_camel_case is true it should still work' do
618
- it 'raises an exception by default' do
619
- vcr('entries/empty_fields') {
620
- entry = create_client(
621
- space: 'z4ssexir3p93',
622
- access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
623
- dynamic_entries: :auto,
624
- use_camel_case: true
625
- ).entry('2t1x77MgUA4SM2gMiaUcsy')
626
-
627
- expect { entry.title }.to raise_error Contentful::EmptyFieldError
628
- }
629
- end
630
-
631
- it 'returns nil if raise_for_empty_fields is false' do
632
- vcr('entries/empty_fields') {
633
- entry = create_client(
634
- space: 'z4ssexir3p93',
635
- access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
636
- dynamic_entries: :auto,
637
- raise_for_empty_fields: false,
638
- use_camel_case: true
639
- ).entry('2t1x77MgUA4SM2gMiaUcsy')
640
-
641
- expect(entry.title).to be_nil
642
- }
643
- end
644
-
645
- it 'will properly raise NoMethodError for non-fields' do
646
- vcr('entries/empty_fields') {
647
- entry = create_client(
648
- space: 'z4ssexir3p93',
649
- access_token: 'e157fdaf7b325b71d07a94b7502807d4cfbbb1a34e69b7856838e25b92777bc6',
650
- dynamic_entries: :auto,
651
- use_camel_case: true
652
- ).entry('2t1x77MgUA4SM2gMiaUcsy')
653
-
654
- expect { entry.unexisting_field }.to raise_error NoMethodError
655
- }
656
- end
657
- end
658
- end
659
-
660
- describe 'rich text support' do
661
- it 'properly serializes and resolves includes' do
662
- vcr('entries/rich_text') {
663
- entry = create_client(
664
- space: 'jd7yc4wnatx3',
665
- access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
666
- raise_errors: true,
667
- dynamic_entries: :auto,
668
- gzip_encoded: false
669
- ).entry('4BupPSmi4M02m0U48AQCSM')
670
-
671
- expected_entry_occurrances = 2
672
- embedded_entry_index = 1
673
- entry.body['content'].each do |content|
674
- if content['nodeType'] == 'embedded-entry-block'
675
- expect(content['data']['target']).to be_a Contentful::Entry
676
- expect(content['data']['target'].body).to eq "Embedded #{embedded_entry_index}"
677
- expected_entry_occurrances -= 1
678
- embedded_entry_index += 1
679
- end
680
- end
681
-
682
- expect(expected_entry_occurrances).to eq 0
683
- }
684
- end
685
-
686
- it 'doesnt hydrate the same entry twice - #194' do
687
- vcr('entries/rich_text_hydration_issue') {
688
- entry = nil
689
-
690
- expect {
691
- entry = create_client(
692
- space: 'fds721b88p6b',
693
- access_token: '45ba81cc69423fcd2e3f0a4779de29481bb5c11495bc7e14649a996cf984e98e',
694
- raise_errors: true,
695
- dynamic_entries: :auto,
696
- gzip_encoded: false
697
- ).entry('1tBAu0wP9qAQEg6qCqMics')
698
- }.not_to raise_error
699
-
700
- expect(entry.children[0].id).to eq entry.children[1].id
701
- expect(entry.children[0].body).to eq entry.children[1].body
702
- }
703
- end
704
-
705
- it 'respects content in data attribute if its not a Link' do
706
- vcr('entries/rich_text_nested_fields') {
707
- entry = create_client(
708
- space: 'jd7yc4wnatx3',
709
- access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
710
- raise_errors: true,
711
- dynamic_entries: :auto,
712
- gzip_encoded: false
713
- ).entry('6NGLswCREsGA28kGouScyY')
714
-
715
- expect(entry.body['content'][0]).to eq({
716
- 'data' => {},
717
- 'content' => [
718
- {'marks' => [], 'value' => 'A link to ', 'nodeType' => 'text', 'nodeClass' => 'text'},
719
- {
720
- 'data' => {'uri' => 'https://google.com'},
721
- 'content' => [{'marks' => [], 'value' => 'google', 'nodeType' => 'text', 'nodeClass' => 'text'}],
722
- 'nodeType' => 'hyperlink',
723
- 'nodeClass' => 'inline'
724
- },
725
- {'marks' => [], 'value' => '', 'nodeType' => 'text', 'nodeClass' => 'text'}
726
- ],
727
- 'nodeType' => 'paragraph',
728
- 'nodeClass' => 'block'
729
- })
730
- }
731
- end
732
-
733
- it 'supports includes in nested fields' do
734
- vcr('entries/rich_text_nested_fields') {
735
- entry = create_client(
736
- space: 'jd7yc4wnatx3',
737
- access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
738
- raise_errors: true,
739
- dynamic_entries: :auto,
740
- gzip_encoded: false
741
- ).entry('6NGLswCREsGA28kGouScyY')
742
-
743
- expect(entry.body['content'][3]['nodeType']).to eq('unordered-list')
744
- expect(entry.body['content'][3]['content'][2]['content'][0]['data']['target'].is_a?(Contentful::Entry)).to be_truthy
745
-
746
- expect(entry.body['content'][4]['nodeType']).to eq('ordered-list')
747
- expect(entry.body['content'][4]['content'][2]['content'][0]['data']['target'].is_a?(Contentful::Entry)).to be_truthy
748
- }
749
- end
750
-
751
- it 'returns a link when resource is valid but unreachable' do
752
- vcr('entries/rich_text_unresolved_relationships') {
753
- parent = create_client(
754
- space: 'jd7yc4wnatx3',
755
- access_token: '6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
756
- raise_errors: true,
757
- dynamic_entries: :auto,
758
- gzip_encoded: false
759
- ).entry('4fvSwl5Ob6UEWKg6MQicuC')
760
-
761
- entry = parent.rich_text_child
762
- expect(entry.body['content'][19]['data']['target'].is_a?(Contentful::Link)).to be_truthy
763
- }
764
- end
765
- end
766
- end