contentful-management 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db30baf0a7f6689a0e8d8e921a74dbe05623dcbe81cc2b1a5b6d4d3b19ca75d5
4
- data.tar.gz: 7e80ee8d30fa45107e20b337decd61799a574fc5521b2147dc3755591c35a6fb
3
+ metadata.gz: af6595494f26b3a85d5394e675069faa4518cfbb51b0fd7856da47a94a5e1d1d
4
+ data.tar.gz: b7da54f816b90d302c91995ac77beb1c383b3b385872cccadb07dfde301fc0c0
5
5
  SHA512:
6
- metadata.gz: a324983a49a14bbe3719a7c61b23ea5274eb40a0075c4a93ad6fd9558813f4728b7450549de9218e57851f94ac853042453a9600809495b8916bc67471d169ad
7
- data.tar.gz: c2241087a811637e1cd16243cfe08a9d08b5ced139e78090f0de98009d759f4367523665115272fc6c734085a04375d669fa6fedb40a357cad8a8784cd0169f5
6
+ metadata.gz: 6f04b5c262ee9182ad6562008968711b7df6627b03be6fc9b8a980594205560a0868c3de151c55a2c53c33e3da18805b8cdcb0b5ac4e1d8cd065bf721d0a09f2
7
+ data.tar.gz: e7e855348fba05bcd88da84a4645d221203a4de67a3dd346866fc8423f41a877297306ca2b30585147c1915754a5a7ac3c2c872d175a9cb10102e6d161b55597
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 2.0.2
6
+ ### Fixed
7
+ * Fixed environment ID fetching for environment aware resources.
8
+
5
9
  ## 2.0.1
6
10
  ### Fixed
7
11
  * Fixed environment proxy `find` method.
@@ -5,7 +5,15 @@ module Contentful
5
5
  module EnvironmentAware
6
6
  # Gets the environment ID for the resource.
7
7
  def environment_id
8
- sys.fetch(:environment, {}).fetch(:id, 'master')
8
+ env = sys.fetch(:environment, {})
9
+ case env
10
+ when ::Hash
11
+ env.fetch(:id, 'master')
12
+ when ::Contentful::Management::Link
13
+ env.id
14
+ else
15
+ 'master'
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '2.0.1'.freeze
6
+ VERSION = '2.0.2'.freeze
7
7
  end
8
8
  end
@@ -0,0 +1,299 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/9utsm1g0t7f5/environments/staging/entries/6yVdruR4GsKO2iKOqQS2CS
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful-management.rb/2.0.1; platform ruby/2.5.1; os macOS/16;
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Connection:
17
+ - close
18
+ Host:
19
+ - api.contentful.com
20
+ User-Agent:
21
+ - http.rb/2.2.2
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Access-Control-Allow-Headers:
28
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent,X-Contentful-Enable-Alpha-Feature
29
+ Access-Control-Allow-Methods:
30
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '1728000'
37
+ Cf-Space-Id:
38
+ - 9utsm1g0t7f5
39
+ Content-Type:
40
+ - application/vnd.contentful.management.v1+json
41
+ Date:
42
+ - Wed, 18 Apr 2018 11:56:48 GMT
43
+ Etag:
44
+ - '"eff4ba4b8ca26b96bc78c38c53632f9a"'
45
+ Server:
46
+ - Contentful
47
+ Strict-Transport-Security:
48
+ - max-age=15768000
49
+ X-Content-Type-Options:
50
+ - nosniff
51
+ X-Contentful-Ratelimit-Hour-Limit:
52
+ - '36000'
53
+ X-Contentful-Ratelimit-Hour-Remaining:
54
+ - '35972'
55
+ X-Contentful-Ratelimit-Reset:
56
+ - '0'
57
+ X-Contentful-Ratelimit-Second-Limit:
58
+ - '10'
59
+ X-Contentful-Ratelimit-Second-Remaining:
60
+ - '9'
61
+ X-Contentful-Request-Id:
62
+ - 898b936d88648999635e3df5f57f475d
63
+ Content-Length:
64
+ - '1265'
65
+ Connection:
66
+ - Close
67
+ Set-Cookie:
68
+ - incap_ses_408_673446=4xuFJNqPbWtzayCs+YKpBYAy11oAAAAAszyBHdC5iZe46FoVb8ArWA==;
69
+ path=/; Domain=.contentful.com
70
+ - nlbi_673446=6Ca4TQl4bFr9I6996lKYhQAAAAB0XeQw1xLq4MyDt9WKEY7P; path=/; Domain=.contentful.com
71
+ - visid_incap_673446=7tTt1gBTTsmSGemJKhzF1YAy11oAAAAAQUIPAAAAAACrveklOs/iZLLDNbcyhQGj;
72
+ expires=Thu, 18 Apr 2019 06:06:57 GMT; path=/; Domain=.contentful.com
73
+ X-Iinfo:
74
+ - 10-163941739-163941748 NNNN CT(86 87 0) RT(1524052608368 42) q(0 0 1 -1) r(3
75
+ 3) U5
76
+ X-Cdn:
77
+ - Incapsula
78
+ body:
79
+ encoding: ASCII-8BIT
80
+ string: |
81
+ {
82
+ "sys": {
83
+ "space": {
84
+ "sys": {
85
+ "type": "Link",
86
+ "linkType": "Space",
87
+ "id": "9utsm1g0t7f5"
88
+ }
89
+ },
90
+ "id": "6yVdruR4GsKO2iKOqQS2CS",
91
+ "type": "Entry",
92
+ "createdAt": "2018-04-18T11:29:43.526Z",
93
+ "updatedAt": "2018-04-18T11:46:50.040Z",
94
+ "environment": {
95
+ "sys": {
96
+ "id": "staging",
97
+ "type": "Link",
98
+ "linkType": "Environment"
99
+ }
100
+ },
101
+ "createdBy": {
102
+ "sys": {
103
+ "type": "Link",
104
+ "linkType": "User",
105
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
106
+ }
107
+ },
108
+ "updatedBy": {
109
+ "sys": {
110
+ "type": "Link",
111
+ "linkType": "User",
112
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
113
+ }
114
+ },
115
+ "publishedCounter": 2,
116
+ "version": 10,
117
+ "publishedBy": {
118
+ "sys": {
119
+ "type": "Link",
120
+ "linkType": "User",
121
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
122
+ }
123
+ },
124
+ "publishedVersion": 9,
125
+ "firstPublishedAt": "2018-04-18T11:29:53.072Z",
126
+ "publishedAt": "2018-04-18T11:46:50.040Z",
127
+ "contentType": {
128
+ "sys": {
129
+ "type": "Link",
130
+ "linkType": "ContentType",
131
+ "id": "foo"
132
+ }
133
+ }
134
+ },
135
+ "fields": {
136
+ "name": {
137
+ "en-US": "Test"
138
+ },
139
+ "content": {
140
+ "en-US": "Some content"
141
+ }
142
+ }
143
+ }
144
+ http_version:
145
+ recorded_at: Wed, 18 Apr 2018 11:56:48 GMT
146
+ - request:
147
+ method: get
148
+ uri: https://api.contentful.com/spaces/9utsm1g0t7f5/environments/staging/content_types/foo
149
+ body:
150
+ encoding: US-ASCII
151
+ string: ''
152
+ headers:
153
+ X-Contentful-User-Agent:
154
+ - sdk contentful-management.rb/2.0.1; platform ruby/2.5.1; os macOS/16;
155
+ Authorization:
156
+ - Bearer <ACCESS_TOKEN>
157
+ Content-Type:
158
+ - application/vnd.contentful.management.v1+json
159
+ Connection:
160
+ - close
161
+ Host:
162
+ - api.contentful.com
163
+ User-Agent:
164
+ - http.rb/2.2.2
165
+ response:
166
+ status:
167
+ code: 200
168
+ message: OK
169
+ headers:
170
+ Access-Control-Allow-Headers:
171
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent,X-Contentful-Enable-Alpha-Feature
172
+ Access-Control-Allow-Methods:
173
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
174
+ Access-Control-Allow-Origin:
175
+ - "*"
176
+ Access-Control-Expose-Headers:
177
+ - Etag
178
+ Access-Control-Max-Age:
179
+ - '1728000'
180
+ Cf-Space-Id:
181
+ - 9utsm1g0t7f5
182
+ Content-Type:
183
+ - application/vnd.contentful.management.v1+json
184
+ Date:
185
+ - Wed, 18 Apr 2018 11:56:49 GMT
186
+ Etag:
187
+ - '"b46a37e467f9263b4275d8e4f6e99cc1"'
188
+ Server:
189
+ - Contentful
190
+ Strict-Transport-Security:
191
+ - max-age=15768000
192
+ X-Content-Type-Options:
193
+ - nosniff
194
+ X-Contentful-Ratelimit-Hour-Limit:
195
+ - '36000'
196
+ X-Contentful-Ratelimit-Hour-Remaining:
197
+ - '35971'
198
+ X-Contentful-Ratelimit-Reset:
199
+ - '0'
200
+ X-Contentful-Ratelimit-Second-Limit:
201
+ - '10'
202
+ X-Contentful-Ratelimit-Second-Remaining:
203
+ - '9'
204
+ X-Contentful-Request-Id:
205
+ - f1dc2875979d9e5c11fbe8156ea40aaa
206
+ Content-Length:
207
+ - '1498'
208
+ Connection:
209
+ - Close
210
+ Set-Cookie:
211
+ - incap_ses_408_673446=CpfHPWO8Vny+ayCs+YKpBYEy11oAAAAAFJBXRClN3GSpdBdzYThZBw==;
212
+ path=/; Domain=.contentful.com
213
+ - nlbi_673446=volWEN8jM1nY1Bg36lKYhQAAAAA8dqPOHuP4zJEMSjjFDZBX; path=/; Domain=.contentful.com
214
+ - visid_incap_673446=Uss8yA4LR1Co+oADRUNk6oEy11oAAAAAQUIPAAAAAADngdyPUMJU5ZWb+NRns/76;
215
+ expires=Thu, 18 Apr 2019 06:06:57 GMT; path=/; Domain=.contentful.com
216
+ X-Iinfo:
217
+ - 10-163941888-163941903 NNNN CT(86 87 0) RT(1524052608772 43) q(0 0 1 -1) r(3
218
+ 3) U5
219
+ X-Cdn:
220
+ - Incapsula
221
+ body:
222
+ encoding: ASCII-8BIT
223
+ string: |
224
+ {
225
+ "sys": {
226
+ "space": {
227
+ "sys": {
228
+ "type": "Link",
229
+ "linkType": "Space",
230
+ "id": "9utsm1g0t7f5"
231
+ }
232
+ },
233
+ "id": "foo",
234
+ "type": "ContentType",
235
+ "createdAt": "2018-04-18T11:29:35.667Z",
236
+ "updatedAt": "2018-04-18T11:29:36.034Z",
237
+ "environment": {
238
+ "sys": {
239
+ "id": "staging",
240
+ "type": "Link",
241
+ "linkType": "Environment"
242
+ }
243
+ },
244
+ "createdBy": {
245
+ "sys": {
246
+ "type": "Link",
247
+ "linkType": "User",
248
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
249
+ }
250
+ },
251
+ "updatedBy": {
252
+ "sys": {
253
+ "type": "Link",
254
+ "linkType": "User",
255
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
256
+ }
257
+ },
258
+ "publishedCounter": 1,
259
+ "version": 2,
260
+ "publishedBy": {
261
+ "sys": {
262
+ "type": "Link",
263
+ "linkType": "User",
264
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
265
+ }
266
+ },
267
+ "publishedVersion": 1,
268
+ "firstPublishedAt": "2018-04-18T11:29:36.034Z",
269
+ "publishedAt": "2018-04-18T11:29:36.034Z"
270
+ },
271
+ "displayField": "name",
272
+ "name": "Foo",
273
+ "description": "",
274
+ "fields": [
275
+ {
276
+ "id": "name",
277
+ "name": "Name",
278
+ "type": "Symbol",
279
+ "localized": false,
280
+ "required": false,
281
+ "validations": [],
282
+ "disabled": false,
283
+ "omitted": false
284
+ },
285
+ {
286
+ "id": "content",
287
+ "name": "Content",
288
+ "type": "Text",
289
+ "localized": false,
290
+ "required": false,
291
+ "validations": [],
292
+ "disabled": false,
293
+ "omitted": false
294
+ }
295
+ ]
296
+ }
297
+ http_version:
298
+ recorded_at: Wed, 18 Apr 2018 11:56:49 GMT
299
+ recorded_with: VCR 4.0.0
@@ -15,1090 +15,1093 @@ class RetryLoggerMock < Logger
15
15
  end
16
16
  end
17
17
 
18
- module Contentful
19
- module Management
20
- describe Entry do
21
- let(:token) { ENV.fetch('CF_TEST_CMA_TOKEN', '<ACCESS_TOKEN>') }
22
- let(:space_id) { 'yr5m0jky5hsh' }
23
- let(:entry_id) { '4Rouux8SoUCKwkyCq2I0E0' }
18
+ describe Contentful::Management::Entry do
19
+ let(:token) { ENV.fetch('CF_TEST_CMA_TOKEN', '<ACCESS_TOKEN>') }
20
+ let(:space_id) { 'yr5m0jky5hsh' }
21
+ let(:entry_id) { '4Rouux8SoUCKwkyCq2I0E0' }
24
22
 
25
- let!(:client) { Client.new(token) }
23
+ let!(:client) { Contentful::Management::Client.new(token) }
26
24
 
27
- subject { client.entries(space_id, 'master') }
25
+ subject { client.entries(space_id, 'master') }
28
26
 
29
- describe '.all' do
30
- it 'class method also works' do
31
- vcr('entry/all') { expect(Contentful::Management::Entry.all(client, 'bfsvtul0c41g', 'master')).to be_kind_of Contentful::Management::Array }
32
- end
33
- it 'returns a Contentful::Array' do
34
- vcr('entry/all') { expect(described_class.all(client, 'bfsvtul0c41g', 'master')).to be_kind_of Contentful::Management::Array }
35
- end
36
- it 'builds a Contentful::Management::Entry object' do
37
- vcr('entry/all') { expect(described_class.all(client, 'bfsvtul0c41g', 'master').first).to be_kind_of Contentful::Management::Entry }
38
- end
39
- it 'returns entries in context of specified content type' do
40
- vcr('entry/content_type_entires') do
41
- entries = described_class.all(client, 'bfsvtul0c41g', 'master', content_type: 'category_content_type')
42
- expect(entries).to be_kind_of Contentful::Management::Array
43
- expect(entries.first).to be_kind_of Contentful::Management::Entry
44
- expect(entries.first.sys[:contentType].id).to eq 'category_content_type'
45
- end
46
- end
47
- it 'return limited number of entries with next_page' do
48
- vcr('entry/limited_entries') do
49
- entries = described_class.all(client, 'bfsvtul0c41g', 'master', limit: 20, skip: 2)
50
- expect(entries).to be_kind_of Contentful::Management::Array
51
- expect(entries.limit).to eq 20
52
- expect(entries.skip).to eq 2
53
- entries.next_page
54
- end
55
- end
56
- it 'supports select operator' do
57
- vcr('entry/select_operator') do
58
- nyancat = described_class.all(client, 'cfexampleapi', 'master', 'sys.id' => 'nyancat', content_type: 'cat', select: 'fields.lives').first
59
- expect(nyancat.fields).to eq({lives: 1337})
60
- end
61
- end
27
+ describe '.all' do
28
+ it 'class method also works' do
29
+ vcr('entry/all') { expect(Contentful::Management::Entry.all(client, 'bfsvtul0c41g', 'master')).to be_kind_of Contentful::Management::Array }
30
+ end
31
+ it 'returns a Contentful::Array' do
32
+ vcr('entry/all') { expect(described_class.all(client, 'bfsvtul0c41g', 'master')).to be_kind_of Contentful::Management::Array }
33
+ end
34
+ it 'builds a Contentful::Management::Entry object' do
35
+ vcr('entry/all') { expect(described_class.all(client, 'bfsvtul0c41g', 'master').first).to be_kind_of Contentful::Management::Entry }
36
+ end
37
+ it 'returns entries in context of specified content type' do
38
+ vcr('entry/content_type_entires') do
39
+ entries = described_class.all(client, 'bfsvtul0c41g', 'master', content_type: 'category_content_type')
40
+ expect(entries).to be_kind_of Contentful::Management::Array
41
+ expect(entries.first).to be_kind_of Contentful::Management::Entry
42
+ expect(entries.first.sys[:contentType].id).to eq 'category_content_type'
43
+ end
44
+ end
45
+ it 'return limited number of entries with next_page' do
46
+ vcr('entry/limited_entries') do
47
+ entries = described_class.all(client, 'bfsvtul0c41g', 'master', limit: 20, skip: 2)
48
+ expect(entries).to be_kind_of Contentful::Management::Array
49
+ expect(entries.limit).to eq 20
50
+ expect(entries.skip).to eq 2
51
+ entries.next_page
62
52
  end
53
+ end
54
+ it 'supports select operator' do
55
+ vcr('entry/select_operator') do
56
+ nyancat = described_class.all(client, 'cfexampleapi', 'master', 'sys.id' => 'nyancat', content_type: 'cat', select: 'fields.lives').first
57
+ expect(nyancat.fields).to eq({lives: 1337})
58
+ end
59
+ end
60
+ end
63
61
 
64
- describe '.find' do
65
- it 'class method also works' do
66
- vcr('entry/find') { expect(Contentful::Management::Entry.find(client, space_id, 'master', entry_id)).to be_kind_of Contentful::Management::Entry }
67
- end
62
+ describe '.find' do
63
+ it 'class method also works' do
64
+ vcr('entry/find') { expect(Contentful::Management::Entry.find(client, space_id, 'master', entry_id)).to be_kind_of Contentful::Management::Entry }
65
+ end
68
66
 
69
- it 'returns null as nil on empty Symbols' do
70
- vcr('entry/find-with-null-symbols') do
71
- space = client.spaces.find(space_id)
72
- entry = client.entries(space.id, 'master').find(entry_id)
73
- expect(entry.fields[:videoid]).to_not be_kind_of(String)
74
- expect(entry.fields[:videoid]).to be_nil
75
- end
76
- end
67
+ it 'returns null as nil on empty Symbols' do
68
+ vcr('entry/find-with-null-symbols') do
69
+ space = client.spaces.find(space_id)
70
+ entry = client.entries(space.id, 'master').find(entry_id)
71
+ expect(entry.fields[:videoid]).to_not be_kind_of(String)
72
+ expect(entry.fields[:videoid]).to be_nil
73
+ end
74
+ end
77
75
 
78
- it 'returns a Contentful::Management::Entry' do
79
- vcr('entry/find') { expect(subject.find(entry_id)).to be_kind_of Contentful::Management::Entry }
80
- end
76
+ it 'returns a Contentful::Management::Entry' do
77
+ vcr('entry/find') { expect(subject.find(entry_id)).to be_kind_of Contentful::Management::Entry }
78
+ end
81
79
 
82
- it 'returns the entry for a given key' do
83
- vcr('entry/find') do
84
- entry = subject.find(entry_id)
85
- expect(entry.id).to eql entry_id
86
- end
87
- end
88
- it 'returns an error when entry does not exists' do
89
- vcr('entry/find_not_found') do
90
- result = subject.find('not_exist')
91
- expect(result).to be_kind_of Contentful::Management::NotFound
92
- end
93
- end
94
- context 'raise_error when space not found' do
95
- let!(:client) { Client.new(token, raise_errors: true) }
96
- it 'returns an error when entry does not exists' do
97
- expect_vcr('entry/find_not_found') do
98
- subject.find('not_exist')
99
- end.to raise_error Contentful::Management::NotFound
100
- end
101
- end
80
+ it 'returns the entry for a given key' do
81
+ vcr('entry/find') do
82
+ entry = subject.find(entry_id)
83
+ expect(entry.id).to eql entry_id
84
+ end
85
+ end
86
+ it 'returns an error when entry does not exists' do
87
+ vcr('entry/find_not_found') do
88
+ result = subject.find('not_exist')
89
+ expect(result).to be_kind_of Contentful::Management::NotFound
90
+ end
91
+ end
92
+ context 'raise_error when space not found' do
93
+ let!(:client) { Contentful::Management::Client.new(token, raise_errors: true) }
94
+ it 'returns an error when entry does not exists' do
95
+ expect_vcr('entry/find_not_found') do
96
+ subject.find('not_exist')
97
+ end.to raise_error Contentful::Management::NotFound
98
+ end
99
+ end
102
100
 
103
- it 'returns an error when service is unavailable' do
104
- vcr('entry/service_unavailable') do
105
- result = subject.find('not_exist')
106
- expect(result).to be_kind_of Contentful::Management::ServiceUnavailable
107
- message = [
108
- "HTTP status code: 503 Service Unavailable",
109
- "Message: Service unavailable."
110
- ].join("\n")
111
- expect(result.message).to eq message
112
- end
113
- end
101
+ it 'returns an error when service is unavailable' do
102
+ vcr('entry/service_unavailable') do
103
+ result = subject.find('not_exist')
104
+ expect(result).to be_kind_of Contentful::Management::ServiceUnavailable
105
+ message = [
106
+ "HTTP status code: 503 Service Unavailable",
107
+ "Message: Service unavailable."
108
+ ].join("\n")
109
+ expect(result.message).to eq message
114
110
  end
111
+ end
112
+ end
115
113
 
116
- describe '#destroy' do
117
- it 'returns Contentful::BadRequest error when content type is published' do
118
- vcr('entry/destory_published') do
119
- result = subject.find('3U7JqGuVzOWIimU40mKeem').destroy
120
- expect(result).to be_kind_of Contentful::Management::BadRequest
121
- message = [
122
- "HTTP status code: 400 Bad Request",
123
- "Message: Cannot deleted published"
124
- ].join("\n")
125
- expect(result.message).to eq message
126
- end
127
- end
128
- it 'returns true when entry is not published' do
129
- vcr('entry/destroy') do
130
- result = subject.find('3U7JqGuVzOWIimU40mKeem').destroy
131
- expect(result).to eq true
132
- end
133
- end
114
+ describe '#destroy' do
115
+ it 'returns Contentful::BadRequest error when content type is published' do
116
+ vcr('entry/destory_published') do
117
+ result = subject.find('3U7JqGuVzOWIimU40mKeem').destroy
118
+ expect(result).to be_kind_of Contentful::Management::BadRequest
119
+ message = [
120
+ "HTTP status code: 400 Bad Request",
121
+ "Message: Cannot deleted published"
122
+ ].join("\n")
123
+ expect(result.message).to eq message
124
+ end
125
+ end
126
+ it 'returns true when entry is not published' do
127
+ vcr('entry/destroy') do
128
+ result = subject.find('3U7JqGuVzOWIimU40mKeem').destroy
129
+ expect(result).to eq true
134
130
  end
131
+ end
132
+ end
135
133
 
136
- describe '#unpublish' do
137
- it 'unpublish the entry' do
138
- vcr('entry/unpublish') do
139
- entry = subject.find(entry_id)
140
- initial_version = entry.sys[:version]
141
- entry.unpublish
142
- expect(entry).to be_kind_of Contentful::Management::Entry
143
- expect(entry.sys[:version]).to eql initial_version + 1
144
- end
145
- end
134
+ describe '#unpublish' do
135
+ it 'unpublish the entry' do
136
+ vcr('entry/unpublish') do
137
+ entry = subject.find(entry_id)
138
+ initial_version = entry.sys[:version]
139
+ entry.unpublish
140
+ expect(entry).to be_kind_of Contentful::Management::Entry
141
+ expect(entry.sys[:version]).to eql initial_version + 1
142
+ end
143
+ end
146
144
 
147
- it 'returns BadRequest error when already unpublished' do
148
- vcr('entry/unpublish_already_unpublished') do
149
- result = subject.find(entry_id).unpublish
150
- expect(result).to be_kind_of Contentful::Management::BadRequest
151
- message = [
152
- "HTTP status code: 400 Bad Request",
153
- "Message: Not published"
154
- ].join("\n")
155
- expect(result.message).to eq message
156
- expect(result.error[:message]).to eq 'Not published'
157
- expect(result.error[:url]).to eq 'spaces/yr5m0jky5hsh/environments/master/entries/4Rouux8SoUCKwkyCq2I0E0/published'
158
- expect(result.error[:details]).to eq "{\n \"sys\": {\n \"type\": \"Error\",\n \"id\": \"BadRequest\"\n },\n \"message\": \"Not published\"\n}\n"
159
- end
160
- end
145
+ it 'returns BadRequest error when already unpublished' do
146
+ vcr('entry/unpublish_already_unpublished') do
147
+ result = subject.find(entry_id).unpublish
148
+ expect(result).to be_kind_of Contentful::Management::BadRequest
149
+ message = [
150
+ "HTTP status code: 400 Bad Request",
151
+ "Message: Not published"
152
+ ].join("\n")
153
+ expect(result.message).to eq message
154
+ expect(result.error[:message]).to eq 'Not published'
155
+ expect(result.error[:url]).to eq 'spaces/yr5m0jky5hsh/environments/master/entries/4Rouux8SoUCKwkyCq2I0E0/published'
156
+ expect(result.error[:details]).to eq "{\n \"sys\": {\n \"type\": \"Error\",\n \"id\": \"BadRequest\"\n },\n \"message\": \"Not published\"\n}\n"
161
157
  end
158
+ end
159
+ end
162
160
 
163
- describe '#publish' do
164
- it 'returns Contentful::Management::Entry' do
165
- vcr('entry/publish') do
166
- entry = subject.find(entry_id)
167
- initial_version = entry.sys[:version]
168
- entry.publish
169
- expect(entry).to be_kind_of Contentful::Management::Entry
170
- expect(entry.sys[:version]).to eql initial_version + 1
171
- end
172
- end
173
- it 'returns BadRequest error when already published' do
174
- vcr('entry/publish_already_published') do
175
- entry = subject.find(entry_id)
176
- entry.sys[:version] = -1
177
- result = entry.publish
178
- expect(result).to be_kind_of Contentful::Management::Conflict
179
- end
180
- end
161
+ describe '#publish' do
162
+ it 'returns Contentful::Management::Entry' do
163
+ vcr('entry/publish') do
164
+ entry = subject.find(entry_id)
165
+ initial_version = entry.sys[:version]
166
+ entry.publish
167
+ expect(entry).to be_kind_of Contentful::Management::Entry
168
+ expect(entry.sys[:version]).to eql initial_version + 1
169
+ end
170
+ end
171
+ it 'returns BadRequest error when already published' do
172
+ vcr('entry/publish_already_published') do
173
+ entry = subject.find(entry_id)
174
+ entry.sys[:version] = -1
175
+ result = entry.publish
176
+ expect(result).to be_kind_of Contentful::Management::Conflict
181
177
  end
178
+ end
179
+ end
182
180
 
183
- describe '#published?' do
184
- it 'returns true if entry is published' do
185
- vcr('entry/published_true') do
186
- entry = subject.find(entry_id)
187
- entry.publish
188
- expect(entry.published?).to be_truthy
189
- end
190
- end
191
- it 'returns false if entry is not published' do
192
- vcr('entry/published_false') do
193
- entry = subject.find(entry_id)
194
- entry.unpublish
195
- expect(entry.published?).to be_falsey
196
- end
197
- end
181
+ describe '#published?' do
182
+ it 'returns true if entry is published' do
183
+ vcr('entry/published_true') do
184
+ entry = subject.find(entry_id)
185
+ entry.publish
186
+ expect(entry.published?).to be_truthy
187
+ end
188
+ end
189
+ it 'returns false if entry is not published' do
190
+ vcr('entry/published_false') do
191
+ entry = subject.find(entry_id)
192
+ entry.unpublish
193
+ expect(entry.published?).to be_falsey
198
194
  end
195
+ end
196
+ end
199
197
 
200
- describe '#unarchive' do
201
- it 'unarchive the entry' do
202
- vcr('entry/unarchive') do
203
- entry = subject.find(entry_id)
204
- initial_version = entry.sys[:version]
205
- entry.unarchive
206
- expect(entry).to be_kind_of Contentful::Management::Entry
207
- expect(entry.sys[:version]).to eql initial_version + 1
208
- end
209
- end
210
- it 'returns BadRequest error when already unpublished' do
211
- vcr('entry/unarchive_already_unarchived') do
212
- result = subject.find(entry_id).unarchive
213
- expect(result).to be_kind_of Contentful::Management::BadRequest
214
- end
215
- end
198
+ describe '#unarchive' do
199
+ it 'unarchive the entry' do
200
+ vcr('entry/unarchive') do
201
+ entry = subject.find(entry_id)
202
+ initial_version = entry.sys[:version]
203
+ entry.unarchive
204
+ expect(entry).to be_kind_of Contentful::Management::Entry
205
+ expect(entry.sys[:version]).to eql initial_version + 1
206
+ end
207
+ end
208
+ it 'returns BadRequest error when already unpublished' do
209
+ vcr('entry/unarchive_already_unarchived') do
210
+ result = subject.find(entry_id).unarchive
211
+ expect(result).to be_kind_of Contentful::Management::BadRequest
212
+ end
213
+ end
216
214
 
217
- it 'returns BadRequest error when already unarchived' do
218
- vcr('entry/unarchive_already_unarchived') do
219
- result = subject.find(entry_id).unarchive
220
- expect(result).to be_kind_of Contentful::Management::BadRequest
221
- message = [
222
- "HTTP status code: 400 Bad Request",
223
- "Message: Not archived"
224
- ].join("\n")
225
- expect(result.message).to eq message
226
- end
227
- end
215
+ it 'returns BadRequest error when already unarchived' do
216
+ vcr('entry/unarchive_already_unarchived') do
217
+ result = subject.find(entry_id).unarchive
218
+ expect(result).to be_kind_of Contentful::Management::BadRequest
219
+ message = [
220
+ "HTTP status code: 400 Bad Request",
221
+ "Message: Not archived"
222
+ ].join("\n")
223
+ expect(result.message).to eq message
228
224
  end
225
+ end
226
+ end
229
227
 
230
- describe '#archive' do
231
- it 'entry' do
232
- vcr(:'entry/archive') do
233
- entry = subject.find('3U7JqGuVzOWIimU40mKeem')
234
- initial_version = entry.sys[:version]
235
- entry.archive
236
- expect(entry).to be_kind_of Contentful::Management::Entry
237
- expect(entry.sys[:version]).to eql initial_version + 1
238
- end
239
- end
240
- it 'returns error when archive published entry' do
241
- vcr('entry/archive_published') do
242
- entry = subject.find(entry_id).archive
243
- expect(entry).to be_kind_of Contentful::Management::BadRequest
244
- message = [
245
- "HTTP status code: 400 Bad Request",
246
- "Message: Cannot archive published"
247
- ].join("\n")
248
- expect(entry.message).to eq message
249
- end
250
- end
228
+ describe '#archive' do
229
+ it 'entry' do
230
+ vcr(:'entry/archive') do
231
+ entry = subject.find('3U7JqGuVzOWIimU40mKeem')
232
+ initial_version = entry.sys[:version]
233
+ entry.archive
234
+ expect(entry).to be_kind_of Contentful::Management::Entry
235
+ expect(entry.sys[:version]).to eql initial_version + 1
236
+ end
237
+ end
238
+ it 'returns error when archive published entry' do
239
+ vcr('entry/archive_published') do
240
+ entry = subject.find(entry_id).archive
241
+ expect(entry).to be_kind_of Contentful::Management::BadRequest
242
+ message = [
243
+ "HTTP status code: 400 Bad Request",
244
+ "Message: Cannot archive published"
245
+ ].join("\n")
246
+ expect(entry.message).to eq message
251
247
  end
248
+ end
249
+ end
252
250
 
253
- describe '#archived?' do
254
- it 'returns true if entry is archived' do
255
- vcr('entry/archived_true') do
256
- entry = subject.find(entry_id)
257
- entry.archive
258
- expect(entry.archived?).to be_truthy
259
- end
260
- end
261
- it 'returns false if entry is not archived' do
262
- vcr('entry/archived_false') do
263
- entry = subject.find(entry_id)
264
- entry.unarchive
265
- expect(entry.archived?).to be_falsey
266
- end
267
- end
251
+ describe '#archived?' do
252
+ it 'returns true if entry is archived' do
253
+ vcr('entry/archived_true') do
254
+ entry = subject.find(entry_id)
255
+ entry.archive
256
+ expect(entry.archived?).to be_truthy
257
+ end
258
+ end
259
+ it 'returns false if entry is not archived' do
260
+ vcr('entry/archived_false') do
261
+ entry = subject.find(entry_id)
262
+ entry.unarchive
263
+ expect(entry.archived?).to be_falsey
268
264
  end
265
+ end
266
+ end
269
267
 
270
- describe '.create' do
271
- let(:content_type_id) { '5DSpuKrl04eMAGQoQckeIq' }
272
- let(:content_type) { client.content_types(space_id, 'master').find(content_type_id) }
268
+ describe '.create' do
269
+ let(:content_type_id) { '5DSpuKrl04eMAGQoQckeIq' }
270
+ let(:content_type) { client.content_types(space_id, 'master').find(content_type_id) }
271
+
272
+ it 'create with all attributes' do
273
+ vcr('entry/create') do
274
+ content_type = client.content_types('ene4qtp2sh7u', 'master').find('5BHZB1vi4ooq4wKcmA8e2c')
275
+ location = Contentful::Management::Location.new.tap do |loc|
276
+ loc.lat = 22.44
277
+ loc.lon = 33.33
278
+ end
279
+ file = client.assets('ene4qtp2sh7u', 'master').find('2oNoT3vSAs82SOIQmKe0KG')
280
+ entry_att = described_class.find(client, 'ene4qtp2sh7u', 'master', '60zYC7nY9GcKGiCYwAs4wm')
281
+ entry = client.entries('ene4qtp2sh7u', 'master').create(
282
+ content_type,
283
+ name: 'Test name',
284
+ number: 30,
285
+ float1: 1.1,
286
+ boolean: true, date: '2000-07-12T11:11:00+02:00',
287
+ time: '2000-07-12T11:11:00+02:00',
288
+ location: location,
289
+ file: file,
290
+ image: file,
291
+ array: %w(PL USD XX),
292
+ entry: entry_att,
293
+ entries: [entry_att, entry_att],
294
+ object_json: {'test' => {'@type' => 'Codequest'}}
295
+ )
296
+ expect(entry.name).to eq 'Test name'
297
+ expect(entry.number).to eq 30
298
+ expect(entry.float1).to eq 1.1
299
+ expect(entry.boolean).to eq true
300
+ expect(entry.date.to_s).to eq '2000-07-12T11:11:00+02:00'
301
+ expect(entry.time.to_s).to eq '2000-07-12T11:11:00+02:00'
302
+ expect(entry.file['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG'
303
+ expect(entry.image['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG'
304
+ expect(entry.array).to eq %w(PL USD XX)
305
+ expect(entry.entry['sys']['id']).to eq entry_att.id
306
+ expect(entry.entries.first['sys']['id']).to eq entry_att.id
307
+ end
308
+ end
309
+ it 'with location' do
310
+ vcr('entry/create_with_location') do
311
+ location = Contentful::Management::Location.new
312
+ location.lat = 22.44
313
+ location.lon = 33.33
314
+
315
+ entry = subject.create(content_type, name: 'Tom Handy', age: 30, city: location)
316
+ expect(entry).to be_kind_of Contentful::Management::Entry
317
+ expect(entry.name).to eq 'Tom Handy'
318
+ expect(entry.age).to eq 30
319
+ expect(entry.city.properties[:lat]).to eq location.lat
320
+ expect(entry.city.properties[:lon]).to eq location.lon
321
+ end
322
+ end
273
323
 
274
- it 'create with all attributes' do
275
- vcr('entry/create') do
276
- content_type = client.content_types('ene4qtp2sh7u', 'master').find('5BHZB1vi4ooq4wKcmA8e2c')
277
- location = Location.new.tap do |loc|
278
- loc.lat = 22.44
279
- loc.lon = 33.33
280
- end
281
- file = client.assets('ene4qtp2sh7u', 'master').find('2oNoT3vSAs82SOIQmKe0KG')
282
- entry_att = described_class.find(client, 'ene4qtp2sh7u', 'master', '60zYC7nY9GcKGiCYwAs4wm')
283
- entry = client.entries('ene4qtp2sh7u', 'master').create(
284
- content_type,
285
- name: 'Test name',
286
- number: 30,
287
- float1: 1.1,
288
- boolean: true, date: '2000-07-12T11:11:00+02:00',
289
- time: '2000-07-12T11:11:00+02:00',
290
- location: location,
291
- file: file,
292
- image: file,
293
- array: %w(PL USD XX),
294
- entry: entry_att,
295
- entries: [entry_att, entry_att],
296
- object_json: {'test' => {'@type' => 'Codequest'}}
297
- )
298
- expect(entry.name).to eq 'Test name'
299
- expect(entry.number).to eq 30
300
- expect(entry.float1).to eq 1.1
301
- expect(entry.boolean).to eq true
302
- expect(entry.date.to_s).to eq '2000-07-12T11:11:00+02:00'
303
- expect(entry.time.to_s).to eq '2000-07-12T11:11:00+02:00'
304
- expect(entry.file['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG'
305
- expect(entry.image['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG'
306
- expect(entry.array).to eq %w(PL USD XX)
307
- expect(entry.entry['sys']['id']).to eq entry_att.id
308
- expect(entry.entries.first['sys']['id']).to eq entry_att.id
309
- end
310
- end
311
- it 'with location' do
312
- vcr('entry/create_with_location') do
313
- location = Location.new
314
- location.lat = 22.44
315
- location.lon = 33.33
316
-
317
- entry = subject.create(content_type, name: 'Tom Handy', age: 30, city: location)
318
- expect(entry).to be_kind_of Contentful::Management::Entry
319
- expect(entry.name).to eq 'Tom Handy'
320
- expect(entry.age).to eq 30
321
- expect(entry.city.properties[:lat]).to eq location.lat
322
- expect(entry.city.properties[:lon]).to eq location.lon
323
- end
324
- end
324
+ it 'with entry' do
325
+ vcr('entry/create_with_entry') do
326
+ entry_att = client.entries(space_id, 'master').find('4o6ghKSmSko4i828YCYaEo')
327
+ entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
328
+ expect(entry.name).to eq 'EntryWithEntry'
329
+ expect(entry.age).to eq 20
330
+ expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
331
+ end
332
+ end
325
333
 
326
- it 'with entry' do
327
- vcr('entry/create_with_entry') do
328
- entry_att = client.entries(space_id, 'master').find('4o6ghKSmSko4i828YCYaEo')
329
- entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
330
- expect(entry.name).to eq 'EntryWithEntry'
331
- expect(entry.age).to eq 20
332
- expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
333
- end
334
- end
334
+ it 'with entries' do
335
+ vcr('entry/create_with_entries') do
336
+ entry_att = subject.find('1d1QDYzeiyWmgqQYysae8u')
337
+ new_entry = subject.create(content_type,
338
+ name: 'EntryWithEntries',
339
+ age: 20,
340
+ entries: [entry_att, entry_att, entry_att])
341
+ expect(new_entry.name).to eq 'EntryWithEntries'
342
+ expect(new_entry.age).to eq 20
343
+ end
344
+ end
335
345
 
336
- it 'with entries' do
337
- vcr('entry/create_with_entries') do
338
- entry_att = subject.find('1d1QDYzeiyWmgqQYysae8u')
339
- new_entry = subject.create(content_type,
340
- name: 'EntryWithEntries',
341
- age: 20,
342
- entries: [entry_att, entry_att, entry_att])
343
- expect(new_entry.name).to eq 'EntryWithEntries'
344
- expect(new_entry.age).to eq 20
345
- end
346
- end
346
+ # Only here because we want to keep the contentful.rb-dependency out
347
+ class Contentful::Entry
348
+ attr_accessor :sys, :fields
349
+ def initialize(management_entry)
350
+ @sys = management_entry.sys
351
+ @fields = management_entry.fields
352
+ end
347
353
 
348
- # Only here because we want to keep the contentful.rb-dependency out
349
- class Contentful::Entry
350
- attr_accessor :sys, :fields
351
- def initialize(management_entry)
352
- @sys = management_entry.sys
353
- @fields = management_entry.fields
354
- end
354
+ def id
355
+ @sys[:id]
356
+ end
357
+ end
355
358
 
356
- def id
357
- @sys[:id]
358
- end
359
- end
359
+ class Contentful::BaseEntry < Contentful::Entry
360
+ end
361
+ #/ Only here because we want to keep the contentful.rb-dependency out
362
+
363
+ it 'with entry inherited from Contentful::Entry' do
364
+ vcr('entry/create_with_entry') do
365
+ entry_att = Contentful::BaseEntry.new(client.entries(space_id, 'master').find('4o6ghKSmSko4i828YCYaEo'))
366
+ entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
367
+ expect(entry.name).to eq 'EntryWithEntry'
368
+ expect(entry.age).to eq 20
369
+ expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
370
+ end
371
+ end
360
372
 
361
- class Contentful::BaseEntry < Contentful::Entry
362
- end
363
- #/ Only here because we want to keep the contentful.rb-dependency out
364
-
365
- it 'with entry inherited from Contentful::Entry' do
366
- vcr('entry/create_with_entry') do
367
- entry_att = Contentful::BaseEntry.new(client.entries(space_id, 'master').find('4o6ghKSmSko4i828YCYaEo'))
368
- entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
369
- expect(entry.name).to eq 'EntryWithEntry'
370
- expect(entry.age).to eq 20
371
- expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
372
- end
373
- end
373
+ it 'with entries inherited from Contentful::Entry' do
374
+ vcr('entry/create_with_entries') do
375
+ entry_att = Contentful::BaseEntry.new(subject.find('1d1QDYzeiyWmgqQYysae8u'))
376
+ new_entry = subject.create(content_type,
377
+ name: 'EntryWithEntries',
378
+ age: 20,
379
+ entries: [entry_att, entry_att, entry_att])
380
+ expect(new_entry.name).to eq 'EntryWithEntries'
381
+ expect(new_entry.age).to eq 20
382
+ end
383
+ end
374
384
 
375
- it 'with entries inherited from Contentful::Entry' do
376
- vcr('entry/create_with_entries') do
377
- entry_att = Contentful::BaseEntry.new(subject.find('1d1QDYzeiyWmgqQYysae8u'))
378
- new_entry = subject.create(content_type,
379
- name: 'EntryWithEntries',
380
- age: 20,
381
- entries: [entry_att, entry_att, entry_att])
382
- expect(new_entry.name).to eq 'EntryWithEntries'
383
- expect(new_entry.age).to eq 20
384
- end
385
- end
385
+ it 'with asset' do
386
+ vcr('entry/create_with_asset') do
387
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom')
388
+ entry = subject.create(content_type, name: 'OneAsset', asset: asset)
389
+ expect(entry.name).to eq 'OneAsset'
390
+ end
391
+ end
392
+ it 'with assets' do
393
+ vcr('entry/create_with_assets') do
394
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom')
395
+ entry = subject.create(content_type, name: 'multiAssets', assets: [asset, asset, asset])
396
+ expect(entry.name).to eq 'multiAssets'
397
+ end
398
+ end
399
+ it 'with symbols' do
400
+ vcr('entry/create_with_symbols') do
401
+ entry = subject.create(content_type, name: 'SymbolTest', symbols: %w(PL USD XX))
402
+ expect(entry.name).to eq 'SymbolTest'
403
+ expect(entry.symbols).to eq %w(USD PL XX)
404
+ end
405
+ end
406
+ it 'with custom id' do
407
+ vcr('entry/create_with_custom_id') do
408
+ entry = subject.create(content_type, id: 'custom_id', name: 'Custom Id')
409
+ expect(entry.id).to eq 'custom_id'
410
+ end
411
+ end
412
+ it 'to specified locale' do
413
+ vcr('entry/create_with_specified_locale') do
414
+ space = client.spaces.find('s37a4pe35l1x')
415
+ ct = client.content_types(space.id, 'master').find('category_content_type')
416
+ entry = ct.entries.create(name: 'Create test', description: 'Test - create entry with specified locale.', locale: 'pl-PL')
417
+ expect(entry.name).to eq 'Create test'
418
+ end
419
+ end
386
420
 
387
- it 'with asset' do
388
- vcr('entry/create_with_asset') do
389
- asset = client.assets(space_id, 'master').find('codequest_id_test_custom')
390
- entry = subject.create(content_type, name: 'OneAsset', asset: asset)
391
- expect(entry.name).to eq 'OneAsset'
392
- end
393
- end
394
- it 'with assets' do
395
- vcr('entry/create_with_assets') do
396
- asset = client.assets(space_id, 'master').find('codequest_id_test_custom')
397
- entry = subject.create(content_type, name: 'multiAssets', assets: [asset, asset, asset])
398
- expect(entry.name).to eq 'multiAssets'
399
- end
400
- end
401
- it 'with symbols' do
402
- vcr('entry/create_with_symbols') do
403
- entry = subject.create(content_type, name: 'SymbolTest', symbols: %w(PL USD XX))
404
- expect(entry.name).to eq 'SymbolTest'
405
- expect(entry.symbols).to eq %w(USD PL XX)
406
- end
407
- end
408
- it 'with custom id' do
409
- vcr('entry/create_with_custom_id') do
410
- entry = subject.create(content_type, id: 'custom_id', name: 'Custom Id')
411
- expect(entry.id).to eq 'custom_id'
412
- end
413
- end
414
- it 'to specified locale' do
415
- vcr('entry/create_with_specified_locale') do
416
- space = client.spaces.find('s37a4pe35l1x')
417
- ct = client.content_types(space.id, 'master').find('category_content_type')
418
- entry = ct.entries.create(name: 'Create test', description: 'Test - create entry with specified locale.', locale: 'pl-PL')
419
- expect(entry.name).to eq 'Create test'
420
- end
421
- end
421
+ it 'too many requests' do
422
+ vcr('entry/too_many_requests') do
423
+ space = client.spaces.find('286arvy86ry9')
424
+ invalid_entry = client.entries(space.id, 'master').find('1YNepnMpXGiMWikaKC4GG0')
425
+ ct = client.content_types(space.id, 'master').find('5lIEiXrCIoKoIKaSW2C8aa')
426
+ entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
427
+ publish = entry.publish
428
+ expect(publish).to be_a Contentful::Management::RateLimitExceeded
429
+ expect(publish.error[:message]).to eq 'You have exceeded the rate limit of the Organization this Space belongs to by making too many API requests within a short timespan. Please wait a moment before trying the request again.'
430
+ end
431
+ end
422
432
 
423
- it 'too many requests' do
424
- vcr('entry/too_many_requests') do
425
- space = client.spaces.find('286arvy86ry9')
426
- invalid_entry = client.entries(space.id, 'master').find('1YNepnMpXGiMWikaKC4GG0')
427
- ct = client.content_types(space.id, 'master').find('5lIEiXrCIoKoIKaSW2C8aa')
428
- entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
429
- publish = entry.publish
430
- expect(publish).to be_a RateLimitExceeded
431
- expect(publish.error[:message]).to eq 'You have exceeded the rate limit of the Organization this Space belongs to by making too many API requests within a short timespan. Please wait a moment before trying the request again.'
432
- end
433
- end
433
+ it 'too many requests auto-retry' do
434
+ vcr('entry/too_many_requests_retry') do
435
+ logger = RetryLoggerMock.new(STDOUT)
436
+ space = Contentful::Management::Client.new(token, raise_errors: true, logger: logger).spaces.find('286arvy86ry9')
437
+ invalid_entry = client.entries(space.id, 'master').find('1YNepnMpXGiMWikaKC4GG0')
438
+ ct = client.content_types(space.id, 'master').find('5lIEiXrCIoKoIKaSW2C8aa')
439
+ entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
440
+ entry.publish
434
441
 
435
- it 'too many requests auto-retry' do
436
- vcr('entry/too_many_requests_retry') do
437
- logger = RetryLoggerMock.new(STDOUT)
438
- space = Client.new(token, raise_errors: true, logger: logger).spaces.find('286arvy86ry9')
439
- invalid_entry = client.entries(space.id, 'master').find('1YNepnMpXGiMWikaKC4GG0')
440
- ct = client.content_types(space.id, 'master').find('5lIEiXrCIoKoIKaSW2C8aa')
441
- entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
442
- entry.publish
442
+ expect(logger.retry_attempts).to eq 1
443
+ end
444
+ end
443
445
 
444
- expect(logger.retry_attempts).to eq 1
445
- end
446
- end
446
+ it 'with just an id' do
447
+ vcr('entry/create_with_just_id') do
448
+ space = client.spaces.find('bbukbffokvih')
449
+ entry = client.content_types(space.id, 'master').all.first.entries.create({'id' => 'yol'})
450
+ entry.save
451
+ expect(entry).to be_a Contentful::Management::Entry
452
+ end
453
+ end
454
+ end
447
455
 
448
- it 'with just an id' do
449
- vcr('entry/create_with_just_id') do
450
- space = client.spaces.find('bbukbffokvih')
451
- entry = client.content_types(space.id, 'master').all.first.entries.create({'id' => 'yol'})
452
- entry.save
453
- expect(entry).to be_a Contentful::Management::Entry
454
- end
455
- end
456
+ describe '#update' do
457
+ let(:entry_id) { '1I3qWOiP8k2WWYCogKy88S' }
458
+ it 'update entry' do
459
+ vcr('entry/update') do
460
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom_id')
461
+ entry_att = subject.find('1d1QDYzeiyWmgqQYysae8u')
462
+ entry = subject.find('4o6ghKSmSko4i828YCYaEo')
463
+
464
+ location = Contentful::Management::Location.new
465
+ location.lat = 22.44
466
+ location.lon = 33.33
467
+
468
+ result = entry.update(name: 'Tom Handy', age: 20, birthday: '2000-07-12T11:11:00+02:00',
469
+ city: location,
470
+ bool: false,
471
+ asset: asset,
472
+ assets: [asset, asset, asset],
473
+ entry: entry_att,
474
+ entries: [entry_att, entry_att, entry_att],
475
+ symbols: %w(PL USD XX))
476
+
477
+ expect(result).to be_kind_of Contentful::Management::Entry
478
+
479
+ expect(result.fields[:name]).to eq 'Tom Handy'
480
+ expect(result.fields[:age]).to eq 20
481
+ expect(result.fields[:bool]).to eq false
482
+ expect(result.fields[:asset]['sys']['id']).to eq asset.id
483
+ expect(result.fields[:entry]['sys']['id']).to eq entry_att.id
484
+ expect(result.fields[:entries].first['sys']['id']).to eq entry_att.id
456
485
  end
486
+ end
457
487
 
458
- describe '#update' do
459
- let(:entry_id) { '1I3qWOiP8k2WWYCogKy88S' }
460
- it 'update entry' do
461
- vcr('entry/update') do
462
- asset = client.assets(space_id, 'master').find('codequest_id_test_custom_id')
463
- entry_att = subject.find('1d1QDYzeiyWmgqQYysae8u')
464
- entry = subject.find('4o6ghKSmSko4i828YCYaEo')
465
-
466
- location = Location.new
467
- location.lat = 22.44
468
- location.lon = 33.33
469
-
470
- result = entry.update(name: 'Tom Handy', age: 20, birthday: '2000-07-12T11:11:00+02:00',
471
- city: location,
472
- bool: false,
473
- asset: asset,
474
- assets: [asset, asset, asset],
475
- entry: entry_att,
476
- entries: [entry_att, entry_att, entry_att],
477
- symbols: %w(PL USD XX))
478
-
479
- expect(result).to be_kind_of Contentful::Management::Entry
480
-
481
- expect(result.fields[:name]).to eq 'Tom Handy'
482
- expect(result.fields[:age]).to eq 20
483
- expect(result.fields[:bool]).to eq false
484
- expect(result.fields[:asset]['sys']['id']).to eq asset.id
485
- expect(result.fields[:entry]['sys']['id']).to eq entry_att.id
486
- expect(result.fields[:entries].first['sys']['id']).to eq entry_att.id
487
- end
488
- end
488
+ it 'update entry for custom locale' do
489
+ vcr('entry/update_with_custom_locale') do
490
+ entry = subject.find('3U7JqGuVzOWIimU40mKeem')
491
+ entry.locale = 'pl'
492
+ result = entry.update(name: 'testName', bool: true)
493
+ expect(result).to be_kind_of Contentful::Management::Entry
494
+ expect(result.fields[:name]).to eq 'testName'
495
+ expect(result.fields[:bool]).to eq true
496
+ end
497
+ end
489
498
 
490
- it 'update entry for custom locale' do
491
- vcr('entry/update_with_custom_locale') do
492
- entry = subject.find('3U7JqGuVzOWIimU40mKeem')
493
- entry.locale = 'pl'
494
- result = entry.update(name: 'testName', bool: true)
495
- expect(result).to be_kind_of Contentful::Management::Entry
496
- expect(result.fields[:name]).to eq 'testName'
497
- expect(result.fields[:bool]).to eq true
498
- end
499
- end
499
+ it 'return Error when update not localized field' do
500
+ vcr('entry/update_unlocalized_field') do
501
+ asset = client.assets(space_id, 'master').find('codequest_id_test_custom_id')
502
+
503
+ location = Contentful::Management::Location.new
504
+ location.lat = 22.44
505
+ location.lon = 33.33
506
+ entry = subject.find('3U7JqGuVzOWIimU40mKeem')
507
+ entry.locale = 'pl'
508
+ result = entry.update(name: 'DoestMatter', bool: false, city: location, asset: asset)
509
+ expect(result).to be_kind_of Contentful::Management::Error
510
+ end
511
+ end
500
512
 
501
- it 'return Error when update not localized field' do
502
- vcr('entry/update_unlocalized_field') do
503
- asset = client.assets(space_id, 'master').find('codequest_id_test_custom_id')
504
-
505
- location = Location.new
506
- location.lat = 22.44
507
- location.lon = 33.33
508
- entry = subject.find('3U7JqGuVzOWIimU40mKeem')
509
- entry.locale = 'pl'
510
- result = entry.update(name: 'DoestMatter', bool: false, city: location, asset: asset)
511
- expect(result).to be_kind_of Contentful::Management::Error
512
- end
513
- end
513
+ it 'can update boolean fields to `false`' do
514
+ vcr('entry/update_bool_field') do
515
+ space = client.spaces.find('fujuvqn6zcl1')
516
+ content_type = client.content_types(space.id, 'master').find('1kUEViTN4EmGiEaaeC6ouY')
514
517
 
515
- it 'can update boolean fields to `false`' do
516
- vcr('entry/update_bool_field') do
517
- space = client.spaces.find('fujuvqn6zcl1')
518
- content_type = client.content_types(space.id, 'master').find('1kUEViTN4EmGiEaaeC6ouY')
518
+ q = content_type.entries.new
519
+ q.name_with_locales = {'en-US' => 'Hello World'}
520
+ q.yolo_with_locales = {'en-US' => false}
521
+ expected = q.fields
522
+ q.save
519
523
 
520
- q = content_type.entries.new
521
- q.name_with_locales = {'en-US' => 'Hello World'}
522
- q.yolo_with_locales = {'en-US' => false}
523
- expected = q.fields
524
- q.save
524
+ p = client.entries(space.id, 'master').find(q.id)
525
+ expect(p.fields).to match(expected)
526
+ end
527
+ end
528
+ end
525
529
 
526
- p = client.entries(space.id, 'master').find(q.id)
527
- expect(p.fields).to match(expected)
528
- end
529
- end
530
+ describe '#save' do
531
+ it 'save updated' do
532
+ vcr('entry/save_update') do
533
+ entry = subject.find('664EPJ6zHqAeMO6O0mGggU')
534
+ entry.fields[:carMark] = 'Merc'
535
+ entry.save
536
+ expect(entry).to be_kind_of Contentful::Management::Entry
537
+ expect(entry.fields[:carMark]).to eq 'Merc'
530
538
  end
539
+ end
540
+ end
531
541
 
532
- describe '#save' do
533
- it 'save updated' do
534
- vcr('entry/save_update') do
535
- entry = subject.find('664EPJ6zHqAeMO6O0mGggU')
536
- entry.fields[:carMark] = 'Merc'
537
- entry.save
538
- expect(entry).to be_kind_of Contentful::Management::Entry
539
- expect(entry.fields[:carMark]).to eq 'Merc'
540
- end
541
- end
542
+ describe '#reload' do
543
+ let(:space_id) { 'bfsvtul0c41g' }
544
+ it 'update the current version of the object to the version on the system' do
545
+ vcr('entry/reload') do
546
+ space = client.spaces.find(space_id)
547
+ client.content_types(space.id, 'master').all # warm-up cache
548
+
549
+ entry = client.entries(space.id, 'master').find('2arjcjtY7ucC4AGeIOIkok')
550
+ entry.sys[:version] = 999
551
+ update_entry = entry.update(post_title: 'Updated title')
552
+ expect(update_entry).to be_kind_of Contentful::Management::Conflict
553
+ entry.reload
554
+ update_entry = entry.update(post_title: 'Updated title')
555
+ expect(update_entry).to be_kind_of Contentful::Management::Entry
556
+ expect(update_entry.post_title).to eq 'Updated title'
542
557
  end
558
+ end
559
+ end
543
560
 
544
- describe '#reload' do
545
- let(:space_id) { 'bfsvtul0c41g' }
546
- it 'update the current version of the object to the version on the system' do
547
- vcr('entry/reload') do
548
- space = client.spaces.find(space_id)
549
- client.content_types(space.id, 'master').all # warm-up cache
550
-
551
- entry = client.entries(space.id, 'master').find('2arjcjtY7ucC4AGeIOIkok')
552
- entry.sys[:version] = 999
553
- update_entry = entry.update(post_title: 'Updated title')
554
- expect(update_entry).to be_kind_of Contentful::Management::Conflict
555
- entry.reload
556
- update_entry = entry.update(post_title: 'Updated title')
557
- expect(update_entry).to be_kind_of Contentful::Management::Entry
558
- expect(update_entry.post_title).to eq 'Updated title'
559
- end
561
+ describe 'search filters' do
562
+ let(:space) do
563
+ client.spaces.find('bfsvtul0c41g')
564
+ end
565
+ context 'order' do
566
+ it 'returns ordered entries by createdAt' do
567
+ vcr('entry/search_filter/order_sys.createdAt') do
568
+ ordered_entries = client.entries(space.id, 'master').all(order: 'sys.createdAt')
569
+ expect(ordered_entries).to be_kind_of Contentful::Management::Array
570
+ expect(ordered_entries.first).to be_kind_of Contentful::Management::Entry
571
+ expect(ordered_entries.first.sys[:createdAt] < ordered_entries.to_a[4].sys[:createdAt]).to be_truthy
560
572
  end
561
573
  end
562
574
 
563
- describe 'search filters' do
564
- let(:space) do
565
- client.spaces.find('bfsvtul0c41g')
575
+ it 'returns ordered entries by updatedAt' do
576
+ vcr('entry/search_filter/order_sys.updatedAt') do
577
+ ordered_entries = client.entries(space.id, 'master').all(order: 'sys.updatedAt')
578
+ expect(ordered_entries).to be_kind_of Contentful::Management::Array
579
+ expect(ordered_entries.first).to be_kind_of Contentful::Management::Entry
580
+ expect(ordered_entries.first.sys[:updatedAt] < ordered_entries.to_a[4].sys[:updatedAt]).to be_truthy
566
581
  end
567
- context 'order' do
568
- it 'returns ordered entries by createdAt' do
569
- vcr('entry/search_filter/order_sys.createdAt') do
570
- ordered_entries = client.entries(space.id, 'master').all(order: 'sys.createdAt')
571
- expect(ordered_entries).to be_kind_of Contentful::Management::Array
572
- expect(ordered_entries.first).to be_kind_of Contentful::Management::Entry
573
- expect(ordered_entries.first.sys[:createdAt] < ordered_entries.to_a[4].sys[:createdAt]).to be_truthy
574
- end
575
- end
576
-
577
- it 'returns ordered entries by updatedAt' do
578
- vcr('entry/search_filter/order_sys.updatedAt') do
579
- ordered_entries = client.entries(space.id, 'master').all(order: 'sys.updatedAt')
580
- expect(ordered_entries).to be_kind_of Contentful::Management::Array
581
- expect(ordered_entries.first).to be_kind_of Contentful::Management::Entry
582
- expect(ordered_entries.first.sys[:updatedAt] < ordered_entries.to_a[4].sys[:updatedAt]).to be_truthy
583
- end
584
- end
585
- context 'reverse the sort-order' do
586
- it 'returns reverse sort of ordered entries by updatedAt' do
587
- vcr('entry/search_filter/reverse_order_sys.updatedAt') do
588
- reverse_ordered_entries = client.entries(space.id, 'master').all(order: '-sys.updatedAt')
589
- expect(reverse_ordered_entries).to be_kind_of Contentful::Management::Array
590
- expect(reverse_ordered_entries.first).to be_kind_of Contentful::Management::Entry
591
- expect(reverse_ordered_entries.first.sys[:updatedAt] > reverse_ordered_entries.to_a[4].sys[:updatedAt]).to be_truthy
592
- end
593
- end
582
+ end
583
+ context 'reverse the sort-order' do
584
+ it 'returns reverse sort of ordered entries by updatedAt' do
585
+ vcr('entry/search_filter/reverse_order_sys.updatedAt') do
586
+ reverse_ordered_entries = client.entries(space.id, 'master').all(order: '-sys.updatedAt')
587
+ expect(reverse_ordered_entries).to be_kind_of Contentful::Management::Array
588
+ expect(reverse_ordered_entries.first).to be_kind_of Contentful::Management::Entry
589
+ expect(reverse_ordered_entries.first.sys[:updatedAt] > reverse_ordered_entries.to_a[4].sys[:updatedAt]).to be_truthy
594
590
  end
595
591
  end
592
+ end
593
+ end
596
594
 
597
- context 'Including linked Entries in search results' do
598
- it 'returns content_type Entry and include 1 level of linked Entries' do
599
- vcr('entry/search_filter/including_linked_entries') do
600
- filtered_entries = client.entries(space.id, 'master').all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS', include: 2)
601
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
602
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
603
- end
604
- end
595
+ context 'Including linked Entries in search results' do
596
+ it 'returns content_type Entry and include 1 level of linked Entries' do
597
+ vcr('entry/search_filter/including_linked_entries') do
598
+ filtered_entries = client.entries(space.id, 'master').all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS', include: 2)
599
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
600
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
605
601
  end
602
+ end
603
+ end
606
604
 
607
- context 'Equality and Inequality' do
608
- context 'equality operator' do
609
- it 'returns all Entries with specified ID(IDs are unique and there can only be one)' do
610
- vcr('entry/search_filter/equality_operator') do
611
- filtered_entries = client.entries(space.id, 'master').all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS')
612
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
613
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
614
- expect(filtered_entries.first.sys[:id]).to eq '2Hs5BaU56oUmUIySMQQMUS'
615
- end
616
- end
617
- it 'returns all entries by matching fields.number equal 33' do
618
- vcr('entry/search_filter/matching_array_fields') do
619
- filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'fields.number' => 33)
620
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
621
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
622
- expect(filtered_entries.size).to eq 2
623
- end
624
- end
625
- end
626
- context 'inequality operator' do
627
- it 'returns all entries except entry with id = 2Hs5BaU56oUmUIySMQQMUS' do
628
- vcr('entry/search_filter/inequality_operator') do
629
- filtered_entries = client.entries(space.id, 'master').all('sys.id[ne]' => '2Hs5BaU56oUmUIySMQQMUS')
630
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
631
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
632
- expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_falsey
633
- end
634
- end
605
+ context 'Equality and Inequality' do
606
+ context 'equality operator' do
607
+ it 'returns all Entries with specified ID(IDs are unique and there can only be one)' do
608
+ vcr('entry/search_filter/equality_operator') do
609
+ filtered_entries = client.entries(space.id, 'master').all('sys.id' => '2Hs5BaU56oUmUIySMQQMUS')
610
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
611
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
612
+ expect(filtered_entries.first.sys[:id]).to eq '2Hs5BaU56oUmUIySMQQMUS'
635
613
  end
636
614
  end
637
- context 'Inclusion and Exclusion' do
638
- context 'inclusion operator' do
639
- it 'returns entries with specified IDs' do
640
- vcr('entry/search_filter/inclusion_operator') do
641
- filtered_entries = client.entries(space.id, 'master').all('sys.id[in]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
642
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
643
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
644
- expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_truthy
645
- expect(filtered_entries.map(&:id).include?('2X3X7RHVzqsKGAgIEewgaS')).to be_truthy
646
- expect(filtered_entries.size).to eq 2
647
- end
648
- end
649
- end
650
- context 'exclusion operator' do
651
- it 'returns all entries except with specified IDs' do
652
- vcr('entry/search_filter/exclusion_operator') do
653
- filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'sys.id[nin]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
654
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
655
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
656
- expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_falsy
657
- expect(filtered_entries.map(&:id).include?('2X3X7RHVzqsKGAgIEewgaS')).to be_falsy
658
- expect(filtered_entries.size).to eq 3
659
- end
660
- end
615
+ it 'returns all entries by matching fields.number equal 33' do
616
+ vcr('entry/search_filter/matching_array_fields') do
617
+ filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'fields.number' => 33)
618
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
619
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
620
+ expect(filtered_entries.size).to eq 2
661
621
  end
662
622
  end
663
- context 'Full-text Search' do
664
- it 'returns all entries except with specified IDs' do
665
- vcr('entry/search_filter/full_search') do
666
- filtered_entries = client.entries(space.id, 'master').all(query: 'find me')
667
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
668
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
669
- expect(filtered_entries.size).to eq 2
670
- end
671
- end
672
- it 'returns all entries except with specified IDs' do
673
- vcr('entry/search_filter/full_search_match_operator') do
674
- filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'fields.description[match]' => 'find')
675
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
676
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
677
- expect(filtered_entries.size).to eq 2
678
- end
623
+ end
624
+ context 'inequality operator' do
625
+ it 'returns all entries except entry with id = 2Hs5BaU56oUmUIySMQQMUS' do
626
+ vcr('entry/search_filter/inequality_operator') do
627
+ filtered_entries = client.entries(space.id, 'master').all('sys.id[ne]' => '2Hs5BaU56oUmUIySMQQMUS')
628
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
629
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
630
+ expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_falsey
679
631
  end
680
632
  end
681
- context 'Location-based search' do
682
- it 'returns entries closest to a specific map location and order the results by distance' do
683
- vcr('entry/search_filter/location_search_near_operator') do
684
- filtered_entries = client.entries(space.id, 'master').all('fields.location[near]' => '23.15758,53.1297098', content_type: '37TpyB8DcQkq0wkY8c4g2g')
685
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
686
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
687
- end
688
- end
689
-
690
- it 'returns entries with fields.location is inside of the circle' do
691
- vcr('entry/search_filter/location_search_within_operator') do
692
- filtered_entries = client.entries(space.id, 'master').all('fields.location[within]' => '52,23,300', content_type: '37TpyB8DcQkq0wkY8c4g2g')
693
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
694
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
695
- end
633
+ end
634
+ end
635
+ context 'Inclusion and Exclusion' do
636
+ context 'inclusion operator' do
637
+ it 'returns entries with specified IDs' do
638
+ vcr('entry/search_filter/inclusion_operator') do
639
+ filtered_entries = client.entries(space.id, 'master').all('sys.id[in]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
640
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
641
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
642
+ expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_truthy
643
+ expect(filtered_entries.map(&:id).include?('2X3X7RHVzqsKGAgIEewgaS')).to be_truthy
644
+ expect(filtered_entries.size).to eq 2
696
645
  end
697
646
  end
698
-
699
- context 'Number & Date Ranges' do
700
- context 'number' do
701
- it 'returns entries with fields.number less then 20' do
702
- vcr('entry/search_filter/range_operators_less') do
703
- filtered_entries = client.entries(space.id, 'master').all('fields.number[lte]' => '20', content_type: 'category_content_type')
704
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
705
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
706
- expect(filtered_entries.size).to eq 1
707
- end
708
- end
709
- end
710
- context 'date ranges' do
711
- it 'returns entries have been updated since midnight August 19th 2013' do
712
- vcr('entry/search_filter/range_operators_greater_than_or_equal') do
713
- filtered_entries = client.entries(space.id, 'master').all('sys.updatedAt[gte]' => '2014-08-19T00:00:00Z')
714
- expect(filtered_entries).to be_kind_of Contentful::Management::Array
715
- expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
716
- expect(filtered_entries.size).to eq 11
717
- end
718
- end
647
+ end
648
+ context 'exclusion operator' do
649
+ it 'returns all entries except with specified IDs' do
650
+ vcr('entry/search_filter/exclusion_operator') do
651
+ filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'sys.id[nin]' => '2Hs5BaU56oUmUIySMQQMUS,2X3X7RHVzqsKGAgIEewgaS')
652
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
653
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
654
+ expect(filtered_entries.map(&:id).include?('2Hs5BaU56oUmUIySMQQMUS')).to be_falsy
655
+ expect(filtered_entries.map(&:id).include?('2X3X7RHVzqsKGAgIEewgaS')).to be_falsy
656
+ expect(filtered_entries.size).to eq 3
719
657
  end
720
658
  end
721
659
  end
660
+ end
661
+ context 'Full-text Search' do
662
+ it 'returns all entries except with specified IDs' do
663
+ vcr('entry/search_filter/full_search') do
664
+ filtered_entries = client.entries(space.id, 'master').all(query: 'find me')
665
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
666
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
667
+ expect(filtered_entries.size).to eq 2
668
+ end
669
+ end
670
+ it 'returns all entries except with specified IDs' do
671
+ vcr('entry/search_filter/full_search_match_operator') do
672
+ filtered_entries = client.entries(space.id, 'master').all(content_type: 'category_content_type', 'fields.description[match]' => 'find')
673
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
674
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
675
+ expect(filtered_entries.size).to eq 2
676
+ end
677
+ end
678
+ end
679
+ context 'Location-based search' do
680
+ it 'returns entries closest to a specific map location and order the results by distance' do
681
+ vcr('entry/search_filter/location_search_near_operator') do
682
+ filtered_entries = client.entries(space.id, 'master').all('fields.location[near]' => '23.15758,53.1297098', content_type: '37TpyB8DcQkq0wkY8c4g2g')
683
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
684
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
685
+ end
686
+ end
722
687
 
723
- describe 'handling of localized values' do
724
- it 'retrieves localized value if it exists' do
725
- vcr('entry/locales/retrieve_localized') do
726
- space = client.spaces.find('0agypmo1waov')
727
- entry = client.entries(space.id, 'master').find('5cMXsmSd5So6iggWi268eG')
728
- entry.locale = 'de-DE'
688
+ it 'returns entries with fields.location is inside of the circle' do
689
+ vcr('entry/search_filter/location_search_within_operator') do
690
+ filtered_entries = client.entries(space.id, 'master').all('fields.location[within]' => '52,23,300', content_type: '37TpyB8DcQkq0wkY8c4g2g')
691
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
692
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
693
+ end
694
+ end
695
+ end
729
696
 
730
- expect(entry.fields.count).to eq 2
731
- expect(entry.fields[:yolo]).to eq 'etwas Text'
697
+ context 'Number & Date Ranges' do
698
+ context 'number' do
699
+ it 'returns entries with fields.number less then 20' do
700
+ vcr('entry/search_filter/range_operators_less') do
701
+ filtered_entries = client.entries(space.id, 'master').all('fields.number[lte]' => '20', content_type: 'category_content_type')
702
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
703
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
704
+ expect(filtered_entries.size).to eq 1
732
705
  end
733
706
  end
734
-
735
- it 'retrieves value of default locale if it has not been localized' do
736
- vcr('entry/locales/fallback_to_default_locale') do
737
- space = client.spaces.find('0agypmo1waov')
738
- entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
739
- entry.locale = 'de-DE'
740
-
741
- expect(entry.fields.count).to eq 2
742
- expect(entry.fields[:yolo]).to eq 'YOLO'
707
+ end
708
+ context 'date ranges' do
709
+ it 'returns entries have been updated since midnight August 19th 2013' do
710
+ vcr('entry/search_filter/range_operators_greater_than_or_equal') do
711
+ filtered_entries = client.entries(space.id, 'master').all('sys.updatedAt[gte]' => '2014-08-19T00:00:00Z')
712
+ expect(filtered_entries).to be_kind_of Contentful::Management::Array
713
+ expect(filtered_entries.first).to be_kind_of Contentful::Management::Entry
714
+ expect(filtered_entries.size).to eq 11
743
715
  end
744
716
  end
717
+ end
718
+ end
719
+ end
745
720
 
746
- it 'sets value for the default locale when using simple assignments' do
747
- vcr('entry/locales/simple_assignments_use_default_locale') do
748
- space = client.spaces.find('0agypmo1waov')
749
- client.content_types(space.id, 'master').all # warm-up cache
721
+ describe 'handling of localized values' do
722
+ it 'retrieves localized value if it exists' do
723
+ vcr('entry/locales/retrieve_localized') do
724
+ space = client.spaces.find('0agypmo1waov')
725
+ entry = client.entries(space.id, 'master').find('5cMXsmSd5So6iggWi268eG')
726
+ entry.locale = 'de-DE'
750
727
 
751
- entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
728
+ expect(entry.fields.count).to eq 2
729
+ expect(entry.fields[:yolo]).to eq 'etwas Text'
730
+ end
731
+ end
752
732
 
753
- entry.yolo = 'changed'
733
+ it 'retrieves value of default locale if it has not been localized' do
734
+ vcr('entry/locales/fallback_to_default_locale') do
735
+ space = client.spaces.find('0agypmo1waov')
736
+ entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
737
+ entry.locale = 'de-DE'
754
738
 
755
- expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
756
- end
757
- end
739
+ expect(entry.fields.count).to eq 2
740
+ expect(entry.fields[:yolo]).to eq 'YOLO'
741
+ end
742
+ end
758
743
 
759
- it 'sets value for the specified locales when using *_with_locales' do
760
- vcr('entry/locales/simple_assignments_use_specified_locale') do
761
- space = client.spaces.find('0agypmo1waov')
762
- client.content_types(space.id, 'master').all # warm-up cache
744
+ it 'sets value for the default locale when using simple assignments' do
745
+ vcr('entry/locales/simple_assignments_use_default_locale') do
746
+ space = client.spaces.find('0agypmo1waov')
747
+ client.content_types(space.id, 'master').all # warm-up cache
763
748
 
764
- entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
749
+ entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
765
750
 
766
- entry.yolo_with_locales = {'de-DE' => 'changed'}
767
- entry.locale = 'de-DE'
751
+ entry.yolo = 'changed'
768
752
 
769
- expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
770
- end
771
- end
753
+ expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
772
754
  end
755
+ end
773
756
 
774
- describe '#fields_from_attributes' do
757
+ it 'sets value for the specified locales when using *_with_locales' do
758
+ vcr('entry/locales/simple_assignments_use_specified_locale') do
759
+ space = client.spaces.find('0agypmo1waov')
760
+ client.content_types(space.id, 'master').all # warm-up cache
775
761
 
776
- it 'parses all kind of fields' do
762
+ entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
777
763
 
778
- location = Location.new.tap do |loc|
779
- loc.lat = 22.44
780
- loc.lon = 33.33
781
- end
764
+ entry.yolo_with_locales = {'de-DE' => 'changed'}
765
+ entry.locale = 'de-DE'
782
766
 
783
- attributes = {
784
- name: 'Test name',
785
- number: 30,
786
- float1: 1.1,
787
- boolean: true, date: '2000-07-12T11:11:00+02:00',
788
- time: '2000-07-12T11:11:00+02:00',
789
- location: location,
790
- image: Asset.new,
791
- images: [Asset.new, Asset.new],
792
- array: %w(PL USD XX),
793
- entry: Entry.new,
794
- entries: [Entry.new, Entry.new],
795
- object_json: {'test' => {'@type' => 'Codequest'}}
796
- }
767
+ expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
768
+ end
769
+ end
770
+ end
797
771
 
798
- parsed_attributes = Entry.new.fields_from_attributes(attributes)
799
-
800
- expect(parsed_attributes[:name]).to match('en-US' => 'Test name')
801
- expect(parsed_attributes[:number]).to match('en-US' => 30)
802
- expect(parsed_attributes[:float1]).to match('en-US' => 1.1)
803
- expect(parsed_attributes[:boolean]).to match('en-US' => true)
804
- expect(parsed_attributes[:date]).to match('en-US' => '2000-07-12T11:11:00+02:00')
805
- expect(parsed_attributes[:time]).to match('en-US' => '2000-07-12T11:11:00+02:00')
806
- expect(parsed_attributes[:location]).to match('en-US' => {lat: 22.44, lon: 33.33})
807
- expect(parsed_attributes[:array]).to match('en-US' => %w(PL USD XX))
808
- expect(parsed_attributes[:object_json]).to match('en-US' => {'test' => {'@type' => 'Codequest'}})
809
- expect(parsed_attributes[:image]).to match('en-US' => {sys: {type: 'Link', linkType: 'Asset', id: nil}})
810
- expect(parsed_attributes[:images]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Asset', id: nil}}, {sys: {type: 'Link', linkType: 'Asset', id: nil}}])
811
- expect(parsed_attributes[:entry]).to match('en-US' => {sys: {type: 'Link', linkType: 'Entry', id: nil}})
812
- expect(parsed_attributes[:entries]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}])
772
+ describe '#fields_from_attributes' do
773
+ it 'parses all kind of fields' do
774
+ location = Contentful::Management::Location.new.tap do |loc|
775
+ loc.lat = 22.44
776
+ loc.lon = 33.33
777
+ end
813
778
 
814
- end
779
+ attributes = {
780
+ name: 'Test name',
781
+ number: 30,
782
+ float1: 1.1,
783
+ boolean: true, date: '2000-07-12T11:11:00+02:00',
784
+ time: '2000-07-12T11:11:00+02:00',
785
+ location: location,
786
+ image: Contentful::Management::Asset.new,
787
+ images: [Contentful::Management::Asset.new, Contentful::Management::Asset.new],
788
+ array: %w(PL USD XX),
789
+ entry: Contentful::Management::Entry.new,
790
+ entries: [Contentful::Management::Entry.new, Contentful::Management::Entry.new],
791
+ object_json: {'test' => {'@type' => 'Codequest'}}
792
+ }
793
+
794
+ parsed_attributes = Contentful::Management::Entry.new.fields_from_attributes(attributes)
795
+
796
+ expect(parsed_attributes[:name]).to match('en-US' => 'Test name')
797
+ expect(parsed_attributes[:number]).to match('en-US' => 30)
798
+ expect(parsed_attributes[:float1]).to match('en-US' => 1.1)
799
+ expect(parsed_attributes[:boolean]).to match('en-US' => true)
800
+ expect(parsed_attributes[:date]).to match('en-US' => '2000-07-12T11:11:00+02:00')
801
+ expect(parsed_attributes[:time]).to match('en-US' => '2000-07-12T11:11:00+02:00')
802
+ expect(parsed_attributes[:location]).to match('en-US' => {lat: 22.44, lon: 33.33})
803
+ expect(parsed_attributes[:array]).to match('en-US' => %w(PL USD XX))
804
+ expect(parsed_attributes[:object_json]).to match('en-US' => {'test' => {'@type' => 'Codequest'}})
805
+ expect(parsed_attributes[:image]).to match('en-US' => {sys: {type: 'Link', linkType: 'Asset', id: nil}})
806
+ expect(parsed_attributes[:images]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Asset', id: nil}}, {sys: {type: 'Link', linkType: 'Asset', id: nil}}])
807
+ expect(parsed_attributes[:entry]).to match('en-US' => {sys: {type: 'Link', linkType: 'Entry', id: nil}})
808
+ expect(parsed_attributes[:entries]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}])
809
+ end
815
810
 
816
- it 'keepd hashes in attributes' do
817
- attributes = {
818
- entries: [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}]
819
- }
811
+ it 'keepd hashes in attributes' do
812
+ attributes = {
813
+ entries: [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}]
814
+ }
820
815
 
821
- parsed_attributes = Entry.new.fields_from_attributes(attributes)
816
+ parsed_attributes = Contentful::Management::Entry.new.fields_from_attributes(attributes)
822
817
 
823
- expect(parsed_attributes[:entries]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}])
824
- end
825
- end
818
+ expect(parsed_attributes[:entries]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}])
819
+ end
820
+ end
826
821
 
827
- describe 'fallback locales' do
828
- let(:space) { client.spaces.find('wqjq16zu9s8b') }
829
- it "if a property is nil, it's removed from the request to undefine it in the API" do
830
- vcr('entry/fallback_undefined') {
831
- client.content_types(space.id, 'master').all # warm-up cache
832
- entry = client.entries(space.id, 'master').find('6HSlhD1o3eqkyEWWuMQYyU')
822
+ describe 'fallback locales' do
823
+ let(:space) { client.spaces.find('wqjq16zu9s8b') }
824
+ it "if a property is nil, it's removed from the request to undefine it in the API" do
825
+ vcr('entry/fallback_undefined') {
826
+ client.content_types(space.id, 'master').all # warm-up cache
827
+ entry = client.entries(space.id, 'master').find('6HSlhD1o3eqkyEWWuMQYyU')
833
828
 
834
- expect(entry.name).to eq 'Foo'
835
- expect(entry.fields('es')[:name]).to eq 'Bar'
836
- expect(entry.fields('zh')[:name]).to eq 'Baz'
829
+ expect(entry.name).to eq 'Foo'
830
+ expect(entry.fields('es')[:name]).to eq 'Bar'
831
+ expect(entry.fields('zh')[:name]).to eq 'Baz'
837
832
 
838
- entry.locale ='zh'
839
- entry.name = nil
833
+ entry.locale ='zh'
834
+ entry.name = nil
840
835
 
841
- expect(entry.fields_for_query[:name].keys).not_to include 'zh'
836
+ expect(entry.fields_for_query[:name].keys).not_to include 'zh'
842
837
 
843
- entry.save
844
- }
845
- end
846
- end
838
+ entry.save
839
+ }
840
+ end
841
+ end
847
842
 
848
- describe 'issues' do
849
- describe 'handles multiple locales even when they are not all defined for the default locale - #70' do
850
- it 'merges all present locales' do
851
- vcr('entry/issue_70') {
852
- space = client.spaces.find('9sh5dtmfyzhj')
853
- client.content_types(space.id, 'master').all # warm-up cache
843
+ describe 'issues' do
844
+ describe 'handles multiple locales even when they are not all defined for the default locale - #70' do
845
+ it 'merges all present locales' do
846
+ vcr('entry/issue_70') {
847
+ space = client.spaces.find('9sh5dtmfyzhj')
848
+ client.content_types(space.id, 'master').all # warm-up cache
854
849
 
855
- entry_non_default_locale = client.entries(space.id, 'master').find('1PdCkb5maYgqsSUCOweseM')
850
+ entry_non_default_locale = client.entries(space.id, 'master').find('1PdCkb5maYgqsSUCOweseM')
856
851
 
857
- expect(entry_non_default_locale.name_with_locales).to match({"de-DE" => nil, "es" => "Futbolista"})
858
- expect(entry_non_default_locale.non_localized_with_locales).to match({"de-DE" => "baz", "es" => nil})
852
+ expect(entry_non_default_locale.name_with_locales).to match({"de-DE" => nil, "es" => "Futbolista"})
853
+ expect(entry_non_default_locale.non_localized_with_locales).to match({"de-DE" => "baz", "es" => nil})
859
854
 
860
- entry_with_all_locales = client.entries(space.id, 'master').find('1QKkNRf9AEW2wqwWowgscs')
855
+ entry_with_all_locales = client.entries(space.id, 'master').find('1QKkNRf9AEW2wqwWowgscs')
861
856
 
862
- expect(entry_with_all_locales.name_with_locales).to match({"de-DE" => "Junge", "en-US" => "Boy", "es" => "Chico"})
863
- expect(entry_with_all_locales.non_localized_with_locales).to match({"de-DE" => "foobar", "en-US" => nil, "es" => nil})
864
- }
865
- end
857
+ expect(entry_with_all_locales.name_with_locales).to match({"de-DE" => "Junge", "en-US" => "Boy", "es" => "Chico"})
858
+ expect(entry_with_all_locales.non_localized_with_locales).to match({"de-DE" => "foobar", "en-US" => nil, "es" => nil})
859
+ }
860
+ end
861
+ end
866
862
 
867
- it 'can save with multiple locales assigned - #73' do
868
- vcr('entry/issue_73') {
869
- begin
870
- client.configuration[:default_locale] = 'en-GB'
871
- content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
872
- new_entry = content_type.entries.create(id: 'hello-world')
863
+ it 'can save with multiple locales assigned - #73' do
864
+ vcr('entry/issue_73') {
865
+ begin
866
+ client.configuration[:default_locale] = 'en-GB'
867
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
868
+ new_entry = content_type.entries.create(id: 'hello-world')
873
869
 
874
- new_entry.name = 'Hello World!'
875
- new_entry.locale = 'en-GB'
876
- new_entry.value_with_locales = {'en-GB'=>'hello world', 'es-ES'=>'hola mundo'}
870
+ new_entry.name = 'Hello World!'
871
+ new_entry.locale = 'en-GB'
872
+ new_entry.value_with_locales = {'en-GB'=>'hello world', 'es-ES'=>'hola mundo'}
877
873
 
878
- res = new_entry.save
874
+ res = new_entry.save
879
875
 
880
- expect(res.respond_to?(:error)).to be_falsey
881
- expect(res.is_a?(Contentful::Management::DynamicEntry)).to be_truthy
882
- expect(res.value_with_locales).to match('en-GB' => 'hello world', 'es-ES' => 'hola mundo')
883
- ensure
884
- #new_entry.destroy
885
- end
886
- }
887
- end
876
+ expect(res.respond_to?(:error)).to be_falsey
877
+ expect(res.is_a?(Contentful::Management::DynamicEntry)).to be_truthy
878
+ expect(res.value_with_locales).to match('en-GB' => 'hello world', 'es-ES' => 'hola mundo')
879
+ ensure
880
+ #new_entry.destroy
881
+ end
882
+ }
883
+ end
888
884
 
889
- it 'fields_for_query get properly updated when setting a field using _with_locales - #91' do
890
- vcr('entry/issue_91') {
891
- entry = client.entries('iv4sic0eru9h', 'master').find('5GrMLWzfyMs0eKoi4sg2ug')
885
+ it 'fields_for_query get properly updated when setting a field using _with_locales - #91' do
886
+ vcr('entry/issue_91') {
887
+ entry = client.entries('iv4sic0eru9h', 'master').find('5GrMLWzfyMs0eKoi4sg2ug')
892
888
 
893
- expect(entry.test_with_locales).to eq('en-US' => 'foo', 'es' => 'bar')
889
+ expect(entry.test_with_locales).to eq('en-US' => 'foo', 'es' => 'bar')
894
890
 
895
- entry.test_with_locales = {'en-US' => 'baz', 'es' => 'foobar'}
891
+ entry.test_with_locales = {'en-US' => 'baz', 'es' => 'foobar'}
896
892
 
897
- expect(entry.test_with_locales).to eq('en-US' => 'baz', 'es' => 'foobar')
898
- expect(entry.fields_for_query).to eq(test: { 'en-US' => 'baz', 'es' => 'foobar' })
899
- }
900
- end
893
+ expect(entry.test_with_locales).to eq('en-US' => 'baz', 'es' => 'foobar')
894
+ expect(entry.fields_for_query).to eq(test: { 'en-US' => 'baz', 'es' => 'foobar' })
895
+ }
896
+ end
901
897
 
902
- describe 'it can properly assign, save and publish - #61' do
903
- describe 'on an entry created through the api' do
904
- describe 'before refetch' do
905
- it 'on an already populated field' do
906
- vcr('entry/issue_61.1') {
907
- begin
908
- client.configuration[:default_locale] = 'en-GB'
909
- content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
910
- new_entry = content_type.entries.create(id: 'issue61_1', value: 'hello')
898
+ describe 'properly fetches environment id' do
899
+ it 'fetches the environment id' do
900
+ vcr('entry/environment_id') {
901
+ entry = client.entries('9utsm1g0t7f5', 'staging').find('6yVdruR4GsKO2iKOqQS2CS')
902
+ expect(entry.environment_id).to eq 'staging'
903
+ expect(entry.sys[:environment].id).to eq 'staging'
904
+ }
905
+ end
906
+ end
911
907
 
912
- expect(new_entry.value).to eq 'hello'
908
+ describe 'it can properly assign, save and publish - #61' do
909
+ describe 'on an entry created through the api' do
910
+ describe 'before refetch' do
911
+ it 'on an already populated field' do
912
+ vcr('entry/issue_61.1') {
913
+ begin
914
+ client.configuration[:default_locale] = 'en-GB'
915
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
916
+ new_entry = content_type.entries.create(id: 'issue61_1', value: 'hello')
913
917
 
914
- new_entry.value = 'goodbye'
918
+ expect(new_entry.value).to eq 'hello'
915
919
 
916
- new_entry.save
917
- new_entry.publish
920
+ new_entry.value = 'goodbye'
918
921
 
919
- expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
922
+ new_entry.save
923
+ new_entry.publish
920
924
 
921
- expect(expected_entry.value).to eq 'goodbye'
922
- ensure
923
- new_entry.destroy
924
- end
925
- }
926
- end
925
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
927
926
 
928
- it 'on a previously empty field' do
929
- vcr('entry/issue_61.2') {
930
- begin
931
- client.configuration[:default_locale] = 'en-GB'
932
- content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
933
- new_entry = content_type.entries.create(id: 'issue61_2')
927
+ expect(expected_entry.value).to eq 'goodbye'
928
+ ensure
929
+ new_entry.destroy
930
+ end
931
+ }
932
+ end
934
933
 
935
- new_entry.value = 'goodbye'
934
+ it 'on a previously empty field' do
935
+ vcr('entry/issue_61.2') {
936
+ begin
937
+ client.configuration[:default_locale] = 'en-GB'
938
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
939
+ new_entry = content_type.entries.create(id: 'issue61_2')
940
+
941
+ new_entry.value = 'goodbye'
936
942
 
937
- new_entry.save
938
- new_entry.publish
943
+ new_entry.save
944
+ new_entry.publish
939
945
 
940
- expect(new_entry.value).to eq 'goodbye'
946
+ expect(new_entry.value).to eq 'goodbye'
941
947
 
942
- expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
948
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
943
949
 
944
- expect(expected_entry.value).to eq 'goodbye'
945
- ensure
946
- new_entry.destroy
947
- end
948
- }
949
- end
950
+ expect(expected_entry.value).to eq 'goodbye'
951
+ ensure
952
+ new_entry.destroy
950
953
  end
954
+ }
955
+ end
956
+ end
951
957
 
952
- describe 'after refetch' do
953
- it 'on an already populated field' do
954
- vcr('entry/issue_61.3') {
955
- begin
956
- client.configuration[:default_locale] = 'en-GB'
957
- content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
958
- new_entry = content_type.entries.create(id: 'issue61_3', value: 'hello')
958
+ describe 'after refetch' do
959
+ it 'on an already populated field' do
960
+ vcr('entry/issue_61.3') {
961
+ begin
962
+ client.configuration[:default_locale] = 'en-GB'
963
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
964
+ new_entry = content_type.entries.create(id: 'issue61_3', value: 'hello')
959
965
 
960
- expect(new_entry.value).to eq 'hello'
966
+ expect(new_entry.value).to eq 'hello'
961
967
 
962
- expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
968
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
963
969
 
964
- expected_entry.value = 'goodbye'
970
+ expected_entry.value = 'goodbye'
965
971
 
966
- expected_entry.save
967
- expected_entry.publish
972
+ expected_entry.save
973
+ expected_entry.publish
968
974
 
969
- expect(expected_entry.value).to eq 'goodbye'
970
- ensure
971
- new_entry.destroy
972
- end
973
- }
974
- end
975
+ expect(expected_entry.value).to eq 'goodbye'
976
+ ensure
977
+ new_entry.destroy
978
+ end
979
+ }
980
+ end
975
981
 
976
- it 'on a previously empty field' do
977
- vcr('entry/issue_61.4') {
978
- begin
979
- client.configuration[:default_locale] = 'en-GB'
980
- content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
981
- new_entry = content_type.entries.create(id: 'issue61_4')
982
+ it 'on a previously empty field' do
983
+ vcr('entry/issue_61.4') {
984
+ begin
985
+ client.configuration[:default_locale] = 'en-GB'
986
+ content_type = client.content_types('u2viwgfeal0o', 'master').find('someType')
987
+ new_entry = content_type.entries.create(id: 'issue61_4')
982
988
 
983
- expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
989
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
984
990
 
985
- expected_entry.value = 'goodbye'
991
+ expected_entry.value = 'goodbye'
986
992
 
987
- expected_entry.save
988
- expected_entry.publish
993
+ expected_entry.save
994
+ expected_entry.publish
989
995
 
990
- expect(expected_entry.value).to eq 'goodbye'
991
- ensure
992
- new_entry.destroy
993
- end
994
- }
995
- end
996
+ expect(expected_entry.value).to eq 'goodbye'
997
+ ensure
998
+ new_entry.destroy
996
999
  end
997
- end
1000
+ }
1001
+ end
1002
+ end
1003
+ end
998
1004
 
999
- describe 'on an entry created through the ui' do
1000
- describe 'with dynamic_entries' do
1001
- let!(:client) { vcr('entry/issue_61_spaces') { Client.new(token, dynamic_entries: {'u2viwgfeal0o' => 'master'}) } }
1002
- it 'on an already populated field' do
1003
- vcr('entry/issue_61.5') {
1004
- begin
1005
- client.configuration[:default_locale] = 'en-GB'
1005
+ describe 'on an entry created through the ui' do
1006
+ describe 'with dynamic_entries' do
1007
+ let!(:client) { vcr('entry/issue_61_spaces') { Contentful::Management::Client.new(token, dynamic_entries: {'u2viwgfeal0o' => 'master'}) } }
1008
+ it 'on an already populated field' do
1009
+ vcr('entry/issue_61.5') {
1010
+ begin
1011
+ client.configuration[:default_locale] = 'en-GB'
1006
1012
 
1007
- expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
1013
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
1008
1014
 
1009
- expect(expected_entry.value).to eq 'hello'
1015
+ expect(expected_entry.value).to eq 'hello'
1010
1016
 
1011
- expected_entry.value = 'goodbye'
1017
+ expected_entry.value = 'goodbye'
1012
1018
 
1013
- expected_entry.save
1014
- expected_entry.publish
1019
+ expected_entry.save
1020
+ expected_entry.publish
1015
1021
 
1016
- expect(expected_entry.value).to eq 'goodbye'
1017
- ensure
1018
- expected_entry.value = 'hello'
1022
+ expect(expected_entry.value).to eq 'goodbye'
1023
+ ensure
1024
+ expected_entry.value = 'hello'
1019
1025
 
1020
- expected_entry.save
1021
- expected_entry.publish
1022
- end
1023
- }
1024
- end
1026
+ expected_entry.save
1027
+ expected_entry.publish
1028
+ end
1029
+ }
1030
+ end
1025
1031
 
1026
- it 'on a previously empty field' do
1027
- vcr('entry/issue_61.6') {
1028
- begin
1029
- client.configuration[:default_locale] = 'en-GB'
1032
+ it 'on a previously empty field' do
1033
+ vcr('entry/issue_61.6') {
1034
+ begin
1035
+ client.configuration[:default_locale] = 'en-GB'
1030
1036
 
1031
- expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
1037
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
1032
1038
 
1033
- expect(expected_entry.value).to eq nil
1039
+ expect(expected_entry.value).to eq nil
1034
1040
 
1035
- expected_entry.value = 'goodbye'
1041
+ expected_entry.value = 'goodbye'
1036
1042
 
1037
- expected_entry.save
1038
- expected_entry.publish
1043
+ expected_entry.save
1044
+ expected_entry.publish
1039
1045
 
1040
- expect(expected_entry.value).to eq 'goodbye'
1041
- ensure
1042
- expected_entry.value = nil
1046
+ expect(expected_entry.value).to eq 'goodbye'
1047
+ ensure
1048
+ expected_entry.value = nil
1043
1049
 
1044
- expected_entry.save
1045
- expected_entry.publish
1046
- end
1047
- }
1048
- end
1050
+ expected_entry.save
1051
+ expected_entry.publish
1049
1052
  end
1050
- end
1053
+ }
1054
+ end
1055
+ end
1056
+ end
1051
1057
 
1052
- describe 'without dynamic entries' do
1053
- it 'on an already populated field' do
1054
- vcr('entry/issue_61.7') {
1055
- begin
1056
- client.configuration[:default_locale] = 'en-GB'
1058
+ describe 'without dynamic entries' do
1059
+ it 'on an already populated field' do
1060
+ vcr('entry/issue_61.7') {
1061
+ begin
1062
+ client.configuration[:default_locale] = 'en-GB'
1057
1063
 
1058
- expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
1064
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
1059
1065
 
1060
- expect(expected_entry.value).to eq 'hello'
1066
+ expect(expected_entry.value).to eq 'hello'
1061
1067
 
1062
- expected_entry.value = 'goodbye'
1068
+ expected_entry.value = 'goodbye'
1063
1069
 
1064
- expected_entry.save
1065
- expected_entry.publish
1070
+ expected_entry.save
1071
+ expected_entry.publish
1066
1072
 
1067
- expect(expected_entry.value).to eq 'goodbye'
1068
- ensure
1069
- expected_entry.value = 'hello'
1073
+ expect(expected_entry.value).to eq 'goodbye'
1074
+ ensure
1075
+ expected_entry.value = 'hello'
1070
1076
 
1071
- expected_entry.save
1072
- expected_entry.publish
1073
- end
1074
- }
1075
- end
1077
+ expected_entry.save
1078
+ expected_entry.publish
1079
+ end
1080
+ }
1081
+ end
1076
1082
 
1077
- it 'on a previously empty field' do
1078
- vcr('entry/issue_61.8') {
1079
- begin
1080
- client.configuration[:default_locale] = 'en-GB'
1083
+ it 'on a previously empty field' do
1084
+ vcr('entry/issue_61.8') {
1085
+ begin
1086
+ client.configuration[:default_locale] = 'en-GB'
1081
1087
 
1082
- expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
1088
+ expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
1083
1089
 
1084
- expect(expected_entry.value).to eq nil
1090
+ expect(expected_entry.value).to eq nil
1085
1091
 
1086
- expected_entry.value = 'goodbye'
1092
+ expected_entry.value = 'goodbye'
1087
1093
 
1088
- expected_entry.save
1089
- expected_entry.publish
1094
+ expected_entry.save
1095
+ expected_entry.publish
1090
1096
 
1091
- expect(expected_entry.value).to eq 'goodbye'
1092
- ensure
1093
- expected_entry.value = nil
1097
+ expect(expected_entry.value).to eq 'goodbye'
1098
+ ensure
1099
+ expected_entry.value = nil
1094
1100
 
1095
- expected_entry.save
1096
- expected_entry.publish
1097
- end
1098
- }
1099
- end
1101
+ expected_entry.save
1102
+ expected_entry.publish
1100
1103
  end
1101
- end
1104
+ }
1102
1105
  end
1103
1106
  end
1104
1107
  end