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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/contentful/management/resource/environment_aware.rb +9 -1
- data/lib/contentful/management/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/entry/environment_id.yml +299 -0
- data/spec/lib/contentful/management/entry_spec.rb +920 -917
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af6595494f26b3a85d5394e675069faa4518cfbb51b0fd7856da47a94a5e1d1d
|
4
|
+
data.tar.gz: b7da54f816b90d302c91995ac77beb1c383b3b385872cccadb07dfde301fc0c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f04b5c262ee9182ad6562008968711b7df6627b03be6fc9b8a980594205560a0868c3de151c55a2c53c33e3da18805b8cdcb0b5ac4e1d8cd065bf721d0a09f2
|
7
|
+
data.tar.gz: e7e855348fba05bcd88da84a4645d221203a4de67a3dd346866fc8423f41a877297306ca2b30585147c1915754a5a7ac3c2c872d175a9cb10102e6d161b55597
|
data/CHANGELOG.md
CHANGED
@@ -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, {})
|
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
|
@@ -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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
23
|
+
let!(:client) { Contentful::Management::Client.new(token) }
|
26
24
|
|
27
|
-
|
25
|
+
subject { client.entries(space_id, 'master') }
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
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
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
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
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
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
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
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
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
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
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
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
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
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
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
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
|
-
|
436
|
-
|
437
|
-
|
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
|
-
|
445
|
-
|
446
|
-
|
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
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
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
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
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
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
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
|
-
|
502
|
-
|
503
|
-
|
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
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
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
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
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
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
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
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
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
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
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
|
-
|
564
|
-
|
565
|
-
client.
|
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
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
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
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
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
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
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
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
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
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
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
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
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
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
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
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
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
|
-
|
731
|
-
|
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
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
expect(
|
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
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
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
|
-
|
728
|
+
expect(entry.fields.count).to eq 2
|
729
|
+
expect(entry.fields[:yolo]).to eq 'etwas Text'
|
730
|
+
end
|
731
|
+
end
|
752
732
|
|
753
|
-
|
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
|
-
|
756
|
-
|
757
|
-
|
739
|
+
expect(entry.fields.count).to eq 2
|
740
|
+
expect(entry.fields[:yolo]).to eq 'YOLO'
|
741
|
+
end
|
742
|
+
end
|
758
743
|
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
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
|
-
|
749
|
+
entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
|
765
750
|
|
766
|
-
|
767
|
-
entry.locale = 'de-DE'
|
751
|
+
entry.yolo = 'changed'
|
768
752
|
|
769
|
-
|
770
|
-
end
|
771
|
-
end
|
753
|
+
expect(entry.fields).to match({:name => 'test2', :yolo => 'changed'})
|
772
754
|
end
|
755
|
+
end
|
773
756
|
|
774
|
-
|
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
|
-
|
762
|
+
entry = client.entries(space.id, 'master').find('4epXENbO8wsaOukgqquYcI')
|
777
763
|
|
778
|
-
|
779
|
-
|
780
|
-
loc.lon = 33.33
|
781
|
-
end
|
764
|
+
entry.yolo_with_locales = {'de-DE' => 'changed'}
|
765
|
+
entry.locale = 'de-DE'
|
782
766
|
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
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
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
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
|
-
|
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
|
-
|
817
|
-
|
818
|
-
|
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
|
-
|
816
|
+
parsed_attributes = Contentful::Management::Entry.new.fields_from_attributes(attributes)
|
822
817
|
|
823
|
-
|
824
|
-
|
825
|
-
|
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
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
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
|
-
|
835
|
-
|
836
|
-
|
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
|
-
|
839
|
-
|
833
|
+
entry.locale ='zh'
|
834
|
+
entry.name = nil
|
840
835
|
|
841
|
-
|
836
|
+
expect(entry.fields_for_query[:name].keys).not_to include 'zh'
|
842
837
|
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
838
|
+
entry.save
|
839
|
+
}
|
840
|
+
end
|
841
|
+
end
|
847
842
|
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
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
|
-
|
850
|
+
entry_non_default_locale = client.entries(space.id, 'master').find('1PdCkb5maYgqsSUCOweseM')
|
856
851
|
|
857
|
-
|
858
|
-
|
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
|
-
|
855
|
+
entry_with_all_locales = client.entries(space.id, 'master').find('1QKkNRf9AEW2wqwWowgscs')
|
861
856
|
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
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
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
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
|
-
|
875
|
-
|
876
|
-
|
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
|
-
|
874
|
+
res = new_entry.save
|
879
875
|
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
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
|
-
|
890
|
-
|
891
|
-
|
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
|
-
|
889
|
+
expect(entry.test_with_locales).to eq('en-US' => 'foo', 'es' => 'bar')
|
894
890
|
|
895
|
-
|
891
|
+
entry.test_with_locales = {'en-US' => 'baz', 'es' => 'foobar'}
|
896
892
|
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
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
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
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
|
-
|
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
|
-
|
918
|
+
expect(new_entry.value).to eq 'hello'
|
915
919
|
|
916
|
-
|
917
|
-
new_entry.publish
|
920
|
+
new_entry.value = 'goodbye'
|
918
921
|
|
919
|
-
|
922
|
+
new_entry.save
|
923
|
+
new_entry.publish
|
920
924
|
|
921
|
-
|
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
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
927
|
+
expect(expected_entry.value).to eq 'goodbye'
|
928
|
+
ensure
|
929
|
+
new_entry.destroy
|
930
|
+
end
|
931
|
+
}
|
932
|
+
end
|
934
933
|
|
935
|
-
|
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
|
-
|
938
|
-
|
943
|
+
new_entry.save
|
944
|
+
new_entry.publish
|
939
945
|
|
940
|
-
|
946
|
+
expect(new_entry.value).to eq 'goodbye'
|
941
947
|
|
942
|
-
|
948
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
|
943
949
|
|
944
|
-
|
945
|
-
|
946
|
-
|
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
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
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
|
-
|
966
|
+
expect(new_entry.value).to eq 'hello'
|
961
967
|
|
962
|
-
|
968
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
|
963
969
|
|
964
|
-
|
970
|
+
expected_entry.value = 'goodbye'
|
965
971
|
|
966
|
-
|
967
|
-
|
972
|
+
expected_entry.save
|
973
|
+
expected_entry.publish
|
968
974
|
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
+
expect(expected_entry.value).to eq 'goodbye'
|
976
|
+
ensure
|
977
|
+
new_entry.destroy
|
978
|
+
end
|
979
|
+
}
|
980
|
+
end
|
975
981
|
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
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
|
-
|
989
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find(new_entry.id)
|
984
990
|
|
985
|
-
|
991
|
+
expected_entry.value = 'goodbye'
|
986
992
|
|
987
|
-
|
988
|
-
|
993
|
+
expected_entry.save
|
994
|
+
expected_entry.publish
|
989
995
|
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
end
|
994
|
-
}
|
995
|
-
end
|
996
|
+
expect(expected_entry.value).to eq 'goodbye'
|
997
|
+
ensure
|
998
|
+
new_entry.destroy
|
996
999
|
end
|
997
|
-
|
1000
|
+
}
|
1001
|
+
end
|
1002
|
+
end
|
1003
|
+
end
|
998
1004
|
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
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
|
-
|
1013
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
|
1008
1014
|
|
1009
|
-
|
1015
|
+
expect(expected_entry.value).to eq 'hello'
|
1010
1016
|
|
1011
|
-
|
1017
|
+
expected_entry.value = 'goodbye'
|
1012
1018
|
|
1013
|
-
|
1014
|
-
|
1019
|
+
expected_entry.save
|
1020
|
+
expected_entry.publish
|
1015
1021
|
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1022
|
+
expect(expected_entry.value).to eq 'goodbye'
|
1023
|
+
ensure
|
1024
|
+
expected_entry.value = 'hello'
|
1019
1025
|
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1026
|
+
expected_entry.save
|
1027
|
+
expected_entry.publish
|
1028
|
+
end
|
1029
|
+
}
|
1030
|
+
end
|
1025
1031
|
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
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
|
-
|
1037
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
|
1032
1038
|
|
1033
|
-
|
1039
|
+
expect(expected_entry.value).to eq nil
|
1034
1040
|
|
1035
|
-
|
1041
|
+
expected_entry.value = 'goodbye'
|
1036
1042
|
|
1037
|
-
|
1038
|
-
|
1043
|
+
expected_entry.save
|
1044
|
+
expected_entry.publish
|
1039
1045
|
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1046
|
+
expect(expected_entry.value).to eq 'goodbye'
|
1047
|
+
ensure
|
1048
|
+
expected_entry.value = nil
|
1043
1049
|
|
1044
|
-
|
1045
|
-
|
1046
|
-
end
|
1047
|
-
}
|
1048
|
-
end
|
1050
|
+
expected_entry.save
|
1051
|
+
expected_entry.publish
|
1049
1052
|
end
|
1050
|
-
|
1053
|
+
}
|
1054
|
+
end
|
1055
|
+
end
|
1056
|
+
end
|
1051
1057
|
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
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
|
-
|
1064
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find('fIpsfQSOd22IsqMQCiG0K')
|
1059
1065
|
|
1060
|
-
|
1066
|
+
expect(expected_entry.value).to eq 'hello'
|
1061
1067
|
|
1062
|
-
|
1068
|
+
expected_entry.value = 'goodbye'
|
1063
1069
|
|
1064
|
-
|
1065
|
-
|
1070
|
+
expected_entry.save
|
1071
|
+
expected_entry.publish
|
1066
1072
|
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1073
|
+
expect(expected_entry.value).to eq 'goodbye'
|
1074
|
+
ensure
|
1075
|
+
expected_entry.value = 'hello'
|
1070
1076
|
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1077
|
+
expected_entry.save
|
1078
|
+
expected_entry.publish
|
1079
|
+
end
|
1080
|
+
}
|
1081
|
+
end
|
1076
1082
|
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
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
|
-
|
1088
|
+
expected_entry = client.entries('u2viwgfeal0o', 'master').find('2GmtCwDBcIu4giMgQGIIcq')
|
1083
1089
|
|
1084
|
-
|
1090
|
+
expect(expected_entry.value).to eq nil
|
1085
1091
|
|
1086
|
-
|
1092
|
+
expected_entry.value = 'goodbye'
|
1087
1093
|
|
1088
|
-
|
1089
|
-
|
1094
|
+
expected_entry.save
|
1095
|
+
expected_entry.publish
|
1090
1096
|
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1097
|
+
expect(expected_entry.value).to eq 'goodbye'
|
1098
|
+
ensure
|
1099
|
+
expected_entry.value = nil
|
1094
1100
|
|
1095
|
-
|
1096
|
-
|
1097
|
-
end
|
1098
|
-
}
|
1099
|
-
end
|
1101
|
+
expected_entry.save
|
1102
|
+
expected_entry.publish
|
1100
1103
|
end
|
1101
|
-
|
1104
|
+
}
|
1102
1105
|
end
|
1103
1106
|
end
|
1104
1107
|
end
|