contentful 2.12.0 → 2.17.0

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