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
data/spec/asset_spec.rb DELETED
@@ -1,192 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::Asset do
4
- let(:asset) { vcr('asset') { create_client.asset('nyancat') } }
5
-
6
- describe 'SystemProperties' do
7
- it 'has a #sys getter returning a hash with symbol keys' do
8
- expect(asset.sys).to be_a Hash
9
- expect(asset.sys.keys.sample).to be_a Symbol
10
- end
11
-
12
- it 'has #id' do
13
- expect(asset.id).to eq 'nyancat'
14
- end
15
-
16
- it 'has #type' do
17
- expect(asset.type).to eq 'Asset'
18
- end
19
-
20
- it 'has #space' do
21
- expect(asset.space).to be_a Contentful::Link
22
- end
23
-
24
- it 'has #created_at' do
25
- expect(asset.created_at).to be_a DateTime
26
- end
27
-
28
- it 'has #updated_at' do
29
- expect(asset.updated_at).to be_a DateTime
30
- end
31
-
32
- it 'has #revision' do
33
- expect(asset.revision).to eq 1
34
- end
35
- end
36
-
37
- describe 'Fields' do
38
- it 'has #title' do
39
- expect(asset.title).to eq 'Nyan Cat'
40
- end
41
-
42
- it 'could have #description' do
43
- expect(asset).to respond_to :description
44
- end
45
-
46
- it 'has #file' do
47
- expect(asset.file).to be_a Contentful::File
48
- end
49
- end
50
-
51
- describe '#image_url' do
52
- it 'returns #url of #file without parameter' do
53
- expect(asset.image_url).to eq asset.file.url
54
- end
55
-
56
- it 'adds image options if given' do
57
- url = asset.image_url(width: 100, format: 'jpg', quality: 50, focus: 'top_right', fit: 'thumb', fl: 'progressive', background: 'rgb:ff0000')
58
- expect(url).to include asset.file.url
59
- expect(url).to include '?w=100&fm=jpg&q=50&f=top_right&bg=rgb%3Aff0000&fit=thumb&fl=progressive'
60
- end
61
- end
62
-
63
- describe '#url' do
64
- it 'returns #url of #file without parameter' do
65
- expect(asset.url).to eq asset.file.url
66
- end
67
-
68
- it 'adds image options if given' do
69
- url = asset.url(width: 100, format: 'jpg', quality: 50, focus: 'top_right', fit: 'thumb', fl: 'progressive', background: 'rgb:ff0000')
70
- expect(url).to include asset.file.url
71
- expect(url).to include '?w=100&fm=jpg&q=50&f=top_right&bg=rgb%3Aff0000&fit=thumb&fl=progressive'
72
- end
73
- end
74
-
75
- it 'can be marshalled' do
76
- marshalled = Marshal.dump(asset)
77
- unmarshalled = Marshal.load(marshalled)
78
-
79
- expect(unmarshalled.title).to eq 'Nyan Cat'
80
- expect(unmarshalled.file).to be_a Contentful::File
81
- end
82
-
83
-
84
- describe 'incoming links' do
85
- let(:client) { create_client }
86
-
87
- it 'will fetch entries referencing the asset using a query' do
88
- vcr('entry/search_link_to_asset') {
89
- entries = client.entries(links_to_asset: 'nyancat')
90
- expect(entries).not_to be_empty
91
- expect(entries.count).to eq 1
92
- expect(entries.first.id).to eq 'nyancat'
93
- }
94
- end
95
-
96
- it 'will fetch entries referencing the entry using instance method' do
97
- vcr('entry/search_link_to_asset') {
98
- entries = asset.incoming_references client
99
- expect(entries).not_to be_empty
100
- expect(entries.count).to eq 1
101
- expect(entries.first.id).to eq 'nyancat'
102
- }
103
- end
104
-
105
- end
106
-
107
- describe 'select operator' do
108
- let(:client) { create_client }
109
-
110
- context 'with sys sent' do
111
- it 'properly creates an entry' do
112
- vcr('asset/select_only_sys') {
113
- asset = client.assets(select: ['sys']).first
114
- expect(asset.fields).to be_empty
115
- expect(asset.sys).not_to be_empty
116
- }
117
- end
118
-
119
- it 'can contain only one field' do
120
- vcr('asset/select_one_field') {
121
- asset = client.assets(select: ['sys', 'fields.file']).first
122
- expect(asset.fields.keys).to eq([:file])
123
- }
124
- end
125
- end
126
-
127
- context 'without sys sent' do
128
- it 'will enforce sys anyway' do
129
- vcr('asset/select_no_sys') {
130
- asset = client.assets(select: ['fields'], 'sys.id' => 'nyancat').first
131
-
132
- expect(asset.id).to eq 'nyancat'
133
- expect(asset.sys).not_to be_empty
134
- }
135
- end
136
-
137
- it 'works with empty array as well, as sys is enforced' do
138
- vcr('asset/select_empty_array') {
139
- asset = client.assets(select: [], 'sys.id' => 'nyancat').first
140
-
141
- expect(asset.id).to eq 'nyancat'
142
- expect(asset.sys).not_to be_empty
143
- }
144
- end
145
- end
146
- end
147
-
148
- describe 'issues' do
149
- it 'serializes files correctly for every locale - #129' do
150
- vcr('assets/issues_129') {
151
- client = create_client(
152
- space: 'bht13amj0fva',
153
- access_token: 'bb703a05e107148bed6ee246a9f6b3678c63fed7335632eb68fe1b689c801534'
154
- )
155
-
156
- asset = client.assets('sys.id' => '14bZJKTr6AoaGyeg4kYiWq', locale: '*').first
157
-
158
- expect(asset.file).to be_a ::Contentful::File
159
- expect(asset.file.file_name).to eq 'Flag_of_the_United_States.svg'
160
-
161
- expect(asset.fields[:file]).to be_a ::Contentful::File
162
- expect(asset.fields[:file].file_name).to eq 'Flag_of_the_United_States.svg'
163
-
164
- expect(asset.fields('es')[:file]).to be_a ::Contentful::File
165
- expect(asset.fields('es')[:file].file_name).to eq 'Flag_of_Spain.svg'
166
- }
167
- end
168
-
169
- it 'properly serializes files for non-default locales on localized requests - jekyll-contentful-data-import #46' do
170
- vcr('assets/issues_jekyll_46') {
171
- client = create_client(
172
- space: 'bht13amj0fva',
173
- access_token: 'bb703a05e107148bed6ee246a9f6b3678c63fed7335632eb68fe1b689c801534',
174
- )
175
-
176
- asset = client.assets('sys.id' => '14bZJKTr6AoaGyeg4kYiWq', locale: 'es').first
177
-
178
- expect(asset.file).to be_a ::Contentful::File
179
- expect(asset.file.file_name).to eq 'Flag_of_Spain.svg'
180
- }
181
- end
182
- end
183
-
184
- describe 'camelCase' do
185
- it 'properties now are accessed with camelcase' do
186
- vcr('asset') {
187
- asset = create_client(use_camel_case: true).asset('nyancat')
188
- expect(asset.file.fileName).to eq 'Nyan_cat_250px_frame.png'
189
- }
190
- end
191
- end
192
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Auto-include resources' do
4
- let(:entries) { vcr('entries') { create_client.entries } } # entries come with asset includes
5
-
6
- it 'replaces Contentful::Links which are actually included with the resource' do
7
- asset = entries.items[1].fields[:image]
8
-
9
- expect(asset).not_to be_a Contentful::Link
10
- expect(asset).to be_a Contentful::Asset
11
- end
12
- end
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::Client do
4
- describe '#get' do
5
- let(:client) { create_client() }
6
- let(:proxy_client) { create_client(proxy_host: '183.207.232.194',
7
- proxy_port: 8080,
8
- secure: false) }
9
- let(:timeout_client) { create_client(timeout_connect: 1, timeout_read: 2, timeout_write: 3) }
10
- let(:request) { Contentful::Request.new(nil, client.environment_url('/content_types'), nil, 'cat') }
11
-
12
- it 'uses #base_url' do
13
- expect(client).to receive(:base_url).and_call_original
14
-
15
- vcr('content_type') {
16
- client.get(request)
17
- }
18
- end
19
-
20
- it 'uses #request_headers' do
21
- expect(client).to receive(:request_headers).and_call_original
22
- vcr('content_type') { client.get(request) }
23
- end
24
-
25
- it 'uses Request#url' do
26
- expect(request).to receive(:url).and_call_original
27
- vcr('content_type') { client.get(request) }
28
- end
29
-
30
- it 'uses Request#query' do
31
- expect(request).to receive(:query).thrice.and_call_original
32
- vcr('content_type') { client.get(request) }
33
- end
34
-
35
- it 'calls #get_http' do
36
- expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params, client.timeout_params) { raw_fixture('content_type') }
37
- client.get(request)
38
- end
39
-
40
- it 'calls #get_http via proxy' do
41
- expect(proxy_client.class).to receive(:get_http).with(proxy_client.base_url + request.url, request.query, proxy_client.request_headers, proxy_client.proxy_params, client.timeout_params) { raw_fixture('content_type') }
42
- proxy_client.get(request)
43
- expect(proxy_client.proxy_params[:host]).to eq '183.207.232.194'
44
- expect(proxy_client.proxy_params[:port]).to eq 8080
45
- end
46
-
47
- describe 'timeout params' do
48
- context 'with timeouts configured' do
49
- it 'calls #get_http with timeouts' do
50
- expect(timeout_client.class).to receive(:get_http).with(timeout_client.base_url + request.url, request.query, timeout_client.request_headers, timeout_client.proxy_params, timeout_client.timeout_params) { raw_fixture('content_type') }
51
- timeout_client.get(request)
52
- expect(timeout_client.timeout_params[:connect]).to eq 1
53
- expect(timeout_client.timeout_params[:read]).to eq 2
54
- expect(timeout_client.timeout_params[:write]).to eq 3
55
- end
56
- end
57
-
58
- context 'without timeouts' do
59
- it 'calls #get_http with timeouts' do
60
- expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params, client.timeout_params) { raw_fixture('content_type') }
61
- client.get(request)
62
- expect(client.timeout_params).to eq({})
63
- end
64
- end
65
- end
66
-
67
- describe 'build_resources parameter' do
68
- it 'returns Contentful::Resource object if second parameter is true [default]' do
69
- res = vcr('content_type') { client.get(request) }
70
- expect(res).to be_a Contentful::BaseResource
71
- end
72
-
73
- it 'returns a Contentful::Response object if second parameter is not true' do
74
- res = vcr('content_type') { client.get(request, false) }
75
- expect(res).to be_a Contentful::Response
76
- end
77
- end
78
-
79
- end
80
-
81
- describe '#sync' do
82
- it 'creates a new Sync object' do
83
- expect(create_client.sync).to be_a Contentful::Sync
84
- end
85
- end
86
- end
@@ -1,377 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Client Configuration Options' do
4
- describe ':space' do
5
- it 'is required' do
6
- expect do
7
- Contentful::Client.new(access_token: 'b4c0n73n7fu1')
8
- end.to raise_error(ArgumentError)
9
- end
10
- end
11
-
12
- describe ':access_token' do
13
- it 'is required' do
14
- expect do
15
- Contentful::Client.new(space: 'cfexampleapi')
16
- end.to raise_error(ArgumentError)
17
- end
18
- end
19
-
20
- describe ':secure' do
21
- it 'will use https [default]' do
22
- expect(
23
- create_client.base_url
24
- ).to start_with 'https://'
25
- end
26
-
27
- it 'will use http when secure set to false' do
28
- expect(
29
- create_client(secure: false).base_url
30
- ).to start_with 'http://'
31
- end
32
- end
33
-
34
- describe ':raise_errors' do
35
- it 'will raise response errors if set to true [default]' do
36
- expect_vcr('not found')do
37
- create_client.content_type 'not found'
38
- end.to raise_error Contentful::NotFound
39
- end
40
-
41
- it 'will not raise response errors if set to false' do
42
- res = nil
43
-
44
- expect_vcr('not found')do
45
- res = create_client(raise_errors: false).content_type 'not found'
46
- end.not_to raise_error
47
- expect(res).to be_instance_of Contentful::NotFound
48
- end
49
- end
50
-
51
- describe ':dynamic_entries' do
52
- before :each do
53
- Contentful::ContentTypeCache.clear!
54
- end
55
-
56
- it 'will create dynamic entries if dynamic_entry_cache is not empty' do
57
- client = create_client(dynamic_entries: :manual)
58
- vcr('entry_cache') { client.update_dynamic_entry_cache! }
59
- entry = vcr('nyancat') { client.entry('nyancat') }
60
-
61
- expect(entry).to be_a Contentful::Entry
62
- end
63
-
64
- context ':auto' do
65
- it 'will call update dynamic_entry_cache on start-up' do
66
- vcr('entry_cache') do
67
- create_client(dynamic_entries: :auto)
68
- end
69
- expect(Contentful::ContentTypeCache.cache).not_to be_empty
70
- end
71
- end
72
-
73
- context ':manual' do
74
- it 'will not call #update_dynamic_entry_cache! on start-up' do
75
- create_client(dynamic_entries: :manual)
76
- expect(Contentful::ContentTypeCache.cache).to be_empty
77
- end
78
- end
79
-
80
- describe '#update_dynamic_entry_cache!' do
81
- let(:client) { create_client(dynamic_entries: :manual) }
82
-
83
- it 'will fetch all content_types' do
84
- expect(client).to receive(:content_types).with(limit: 1000) { {} }
85
- client.update_dynamic_entry_cache!
86
- end
87
-
88
- it 'will save dynamic entries in @dynamic_entry_cache' do
89
- vcr('entry_cache')do
90
- client.update_dynamic_entry_cache!
91
- end
92
- expect(Contentful::ContentTypeCache.cache).not_to be_empty
93
- end
94
- end
95
-
96
- describe '#register_dynamic_entry' do
97
- let(:client) { create_client(dynamic_entries: :manual) }
98
-
99
- it 'can be used to register a dynamic entry manually' do
100
- cat = vcr('content_type') { client.content_type 'cat' }
101
- client.register_dynamic_entry 'cat', cat
102
-
103
- expect(Contentful::ContentTypeCache.cache).not_to be_empty
104
- end
105
- end
106
- end
107
-
108
- describe ':api_url' do
109
- it 'is "cdn.contentful.com" [default]' do
110
- expect(
111
- create_client.configuration[:api_url]
112
- ).to eq 'cdn.contentful.com'
113
- end
114
-
115
- it 'will be used as base url' do
116
- expect(
117
- create_client(api_url: 'cdn2.contentful.com').base_url
118
- ).to start_with 'https://cdn2.contentful.com'
119
- end
120
- end
121
-
122
- describe ':api_version' do
123
- it 'is 1 [default]' do
124
- expect(
125
- create_client.configuration[:api_version]
126
- ).to eq 1
127
- end
128
-
129
- it 'will used for the http content type request header' do
130
- expect(
131
- create_client(api_version: 2).request_headers['Content-Type']
132
- ).to eq 'application/vnd.contentful.delivery.v2+json'
133
- end
134
- end
135
-
136
- describe ':authentication_mechanism' do
137
- describe ':header [default]' do
138
- it 'will add the :access_token as authorization bearer token request header' do
139
- expect(
140
- create_client.request_headers['Authorization']
141
- ).to eq 'Bearer b4c0n73n7fu1'
142
- end
143
-
144
- it 'will not add :access_token to query' do
145
- expect(
146
- create_client.request_query({})['access_token']
147
- ).to be_nil
148
- end
149
- end
150
-
151
- describe ':query_string' do
152
- it 'will add the :access_token to query' do
153
- expect(
154
- create_client(authentication_mechanism: :query_string).
155
- request_query({})['access_token']
156
- ).to eq 'b4c0n73n7fu1'
157
- end
158
-
159
- it 'will not add the :access_token as authorization bearer token request header' do
160
- expect(
161
- create_client(authentication_mechanism: :query_string).
162
- request_headers['Authorization']
163
- ).to be_nil
164
- end
165
- end
166
- end
167
-
168
- describe ':resource_mapping' do
169
- it 'lets you register your own resource classes for certain response types' do
170
- class MyBetterAsset < Contentful::Asset
171
- def https_image_url
172
- image_url.sub %r{\A//}, 'https://'
173
- end
174
- end
175
-
176
- client = create_client(
177
- resource_mapping: {
178
- 'Asset' => MyBetterAsset,
179
- }
180
- )
181
-
182
- nyancat = vcr('asset') { client.asset 'nyancat' }
183
- expect(nyancat).to be_a MyBetterAsset
184
- expect(nyancat.https_image_url).to start_with 'https'
185
- end
186
- end
187
-
188
- describe ':entry_mapping' do
189
- it 'lets you register your own entry classes for certain entry types' do
190
- class Cat < Contentful::Entry
191
- end
192
-
193
- client = create_client(
194
- entry_mapping: {
195
- 'cat' => Cat
196
- }
197
- )
198
-
199
- nyancat = vcr('entry') { client.entry 'nyancat' }
200
- finn = vcr('human') { client.entry 'finn' }
201
- expect(nyancat).to be_a Cat
202
- expect(finn).to be_a Contentful::Entry
203
- end
204
- end
205
-
206
- describe 'X-Contentful-User-Agent headers' do
207
- it 'default values' do
208
- expected = [
209
- "sdk contentful.rb/#{Contentful::VERSION};",
210
- "platform ruby/#{RUBY_VERSION};",
211
- ]
212
-
213
- client = create_client
214
- expected.each do |h|
215
- expect(client.contentful_user_agent).to include(h)
216
- end
217
-
218
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
219
-
220
- ['integration', 'app'].each do |h|
221
- expect(client.contentful_user_agent).not_to include(h)
222
- end
223
- end
224
-
225
- it 'with integration name only' do
226
- expected = [
227
- "sdk contentful.rb/#{Contentful::VERSION};",
228
- "platform ruby/#{RUBY_VERSION};",
229
- "integration foobar;"
230
- ]
231
-
232
- client = create_client(integration_name: 'foobar')
233
- expected.each do |h|
234
- expect(client.contentful_user_agent).to include(h)
235
- end
236
-
237
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
238
-
239
- ['app'].each do |h|
240
- expect(client.contentful_user_agent).not_to include(h)
241
- end
242
- end
243
-
244
- it 'with integration' do
245
- expected = [
246
- "sdk contentful.rb/#{Contentful::VERSION};",
247
- "platform ruby/#{RUBY_VERSION};",
248
- "integration foobar/0.1.0;"
249
- ]
250
-
251
- client = create_client(integration_name: 'foobar', integration_version: '0.1.0')
252
- expected.each do |h|
253
- expect(client.contentful_user_agent).to include(h)
254
- end
255
-
256
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
257
-
258
- ['app'].each do |h|
259
- expect(client.contentful_user_agent).not_to include(h)
260
- end
261
- end
262
-
263
- it 'with application name only' do
264
- expected = [
265
- "sdk contentful.rb/#{Contentful::VERSION};",
266
- "platform ruby/#{RUBY_VERSION};",
267
- "app fooapp;"
268
- ]
269
-
270
- client = create_client(application_name: 'fooapp')
271
- expected.each do |h|
272
- expect(client.contentful_user_agent).to include(h)
273
- end
274
-
275
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
276
-
277
- ['integration'].each do |h|
278
- expect(client.contentful_user_agent).not_to include(h)
279
- end
280
- end
281
-
282
- it 'with application' do
283
- expected = [
284
- "sdk contentful.rb/#{Contentful::VERSION};",
285
- "platform ruby/#{RUBY_VERSION};",
286
- "app fooapp/1.0.0;"
287
- ]
288
-
289
- client = create_client(application_name: 'fooapp', application_version: '1.0.0')
290
- expected.each do |h|
291
- expect(client.contentful_user_agent).to include(h)
292
- end
293
-
294
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
295
-
296
- ['integration'].each do |h|
297
- expect(client.contentful_user_agent).not_to include(h)
298
- end
299
- end
300
-
301
- it 'with all' do
302
- expected = [
303
- "sdk contentful.rb/#{Contentful::VERSION};",
304
- "platform ruby/#{RUBY_VERSION};",
305
- "integration foobar/0.1.0;",
306
- "app fooapp/1.0.0;"
307
- ]
308
-
309
- client = create_client(
310
- integration_name: 'foobar',
311
- integration_version: '0.1.0',
312
- application_name: 'fooapp',
313
- application_version: '1.0.0'
314
- )
315
-
316
- expected.each do |h|
317
- expect(client.contentful_user_agent).to include(h)
318
- end
319
-
320
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
321
- end
322
-
323
- it 'when only version numbers, skips header' do
324
- expected = [
325
- "sdk contentful.rb/#{Contentful::VERSION};",
326
- "platform ruby/#{RUBY_VERSION};"
327
- ]
328
-
329
- client = create_client(
330
- integration_version: '0.1.0',
331
- application_version: '1.0.0'
332
- )
333
-
334
- expected.each do |h|
335
- expect(client.contentful_user_agent).to include(h)
336
- end
337
-
338
- expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
339
-
340
- ['integration', 'app'].each do |h|
341
- expect(client.contentful_user_agent).not_to include(h)
342
- end
343
- end
344
-
345
- it 'headers include X-Contentful-User-Agent' do
346
- client = create_client
347
- expect(client.request_headers['X-Contentful-User-Agent']).to eq client.contentful_user_agent
348
- end
349
- end
350
-
351
- describe 'timeout options' do
352
- let(:full_options) { { timeout_connect: 1, timeout_read: 2, timeout_write: 3 } }
353
-
354
- it 'allows the three options to be present together' do
355
- expect do
356
- create_client(full_options)
357
- end.not_to raise_error
358
- end
359
-
360
- it 'allows the three options to be omitted' do
361
- expect do
362
- create_client()
363
- end.not_to raise_error
364
- end
365
-
366
- it 'does not allow only some options to be set' do
367
- # Test that any combination of 1 or 2 keys is rejected
368
- 1.upto(2) do |options_count|
369
- full_options.keys.combination(options_count).each do |option_keys|
370
- expect do
371
- create_client(full_options.select { |key, _| option_keys.include?(key) })
372
- end.to raise_error(ArgumentError)
373
- end
374
- end
375
- end
376
- end
377
- end