wordpress_client 0.0.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +30 -0
- data/.codeclimate.yml +23 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +147 -90
- data/.yardopts +1 -0
- data/Changelog.md +16 -0
- data/Gemfile +6 -1
- data/README.md +48 -14
- data/Rakefile +37 -0
- data/lib/wordpress_client/category.rb +2 -0
- data/lib/wordpress_client/client.rb +235 -79
- data/lib/wordpress_client/connection.rb +10 -10
- data/lib/wordpress_client/errors.rb +41 -6
- data/lib/wordpress_client/media.rb +49 -1
- data/lib/wordpress_client/media_parser.rb +3 -0
- data/lib/wordpress_client/paginated_collection.rb +61 -4
- data/lib/wordpress_client/post.rb +63 -16
- data/lib/wordpress_client/post_parser.rb +12 -39
- data/lib/wordpress_client/rest_parser.rb +4 -0
- data/lib/wordpress_client/tag.rb +2 -0
- data/lib/wordpress_client/term.rb +30 -0
- data/lib/wordpress_client/version.rb +5 -1
- data/lib/wordpress_client.rb +21 -5
- data/spec/client_spec.rb +17 -181
- data/spec/connection_spec.rb +15 -14
- data/spec/docker/Dockerfile +35 -10
- data/spec/docker/README.md +53 -16
- data/spec/docker/dbdump.sql.gz +0 -0
- data/spec/docker/restore-dbdump.sh +2 -2
- data/spec/docker/yum.repos.d/CentOS-Base.repo +25 -0
- data/spec/fixtures/image-media.json +1 -1
- data/spec/fixtures/post-with-metadata.json +99 -1
- data/spec/fixtures/simple-post.json +324 -1
- data/spec/integration/attachments_crud_spec.rb +1 -1
- data/spec/integration/posts_crud_spec.rb +1 -1
- data/spec/integration/posts_finding_spec.rb +0 -69
- data/spec/integration/posts_metadata_spec.rb +11 -11
- data/spec/integration/posts_with_attachments_spec.rb +20 -6
- data/spec/media_spec.rb +14 -0
- data/spec/post_spec.rb +5 -31
- data/spec/spec_helper.rb +1 -0
- data/spec/support/docker_runner.rb +33 -13
- data/spec/support/wordpress_server.rb +112 -74
- data/wordpress_client.gemspec +17 -17
- metadata +43 -31
- data/.hound.yml +0 -2
- data/.ruby-version +0 -1
- data/circle.yml +0 -3
- data/lib/wordpress_client/replace_metadata.rb +0 -81
- data/lib/wordpress_client/replace_terms.rb +0 -62
- data/spec/fixtures/post-with-forbidden-metadata.json +0 -1
- data/spec/integration/category_assignment_spec.rb +0 -29
- data/spec/integration/tag_assignment_spec.rb +0 -29
- data/spec/replace_metadata_spec.rb +0 -56
- data/spec/replace_terms_spec.rb +0 -51
@@ -1 +1,99 @@
|
|
1
|
-
{
|
1
|
+
{
|
2
|
+
"id": 1,
|
3
|
+
"date": "2015-11-03T07:47:41",
|
4
|
+
"date_gmt": "2015-11-03T07:47:41",
|
5
|
+
"guid": {
|
6
|
+
"rendered": "http://localhost:8080/?p=1"
|
7
|
+
},
|
8
|
+
"modified": "2017-07-25T15:07:30",
|
9
|
+
"modified_gmt": "2017-07-25T15:07:30",
|
10
|
+
"slug": "hello-world",
|
11
|
+
"status": "publish",
|
12
|
+
"type": "post",
|
13
|
+
"link": "http://localhost:8080/2015/11/03/hello-world/",
|
14
|
+
"title": {
|
15
|
+
"rendered": "Hello world!"
|
16
|
+
},
|
17
|
+
"content": {
|
18
|
+
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
|
19
|
+
"protected": false
|
20
|
+
},
|
21
|
+
"excerpt": {
|
22
|
+
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
|
23
|
+
"protected": false
|
24
|
+
},
|
25
|
+
"author": 1,
|
26
|
+
"featured_media": 0,
|
27
|
+
"comment_status": "open",
|
28
|
+
"ping_status": "open",
|
29
|
+
"sticky": false,
|
30
|
+
"template": "",
|
31
|
+
"format": "standard",
|
32
|
+
"meta": {
|
33
|
+
"foo": 1,
|
34
|
+
"bar": true,
|
35
|
+
"baz": "wohoo"
|
36
|
+
},
|
37
|
+
"categories": [
|
38
|
+
1
|
39
|
+
],
|
40
|
+
"tags": [],
|
41
|
+
"_links": {
|
42
|
+
"self": [
|
43
|
+
{
|
44
|
+
"href": "http://localhost:8080/wp-json/wp/v2/posts/1"
|
45
|
+
}
|
46
|
+
],
|
47
|
+
"collection": [
|
48
|
+
{
|
49
|
+
"href": "http://localhost:8080/wp-json/wp/v2/posts"
|
50
|
+
}
|
51
|
+
],
|
52
|
+
"about": [
|
53
|
+
{
|
54
|
+
"href": "http://localhost:8080/wp-json/wp/v2/types/post"
|
55
|
+
}
|
56
|
+
],
|
57
|
+
"author": [
|
58
|
+
{
|
59
|
+
"embeddable": true,
|
60
|
+
"href": "http://localhost:8080/wp-json/wp/v2/users/1"
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"replies": [
|
64
|
+
{
|
65
|
+
"embeddable": true,
|
66
|
+
"href": "http://localhost:8080/wp-json/wp/v2/comments?post=1"
|
67
|
+
}
|
68
|
+
],
|
69
|
+
"version-history": [
|
70
|
+
{
|
71
|
+
"href": "http://localhost:8080/wp-json/wp/v2/posts/1/revisions"
|
72
|
+
}
|
73
|
+
],
|
74
|
+
"wp:attachment": [
|
75
|
+
{
|
76
|
+
"href": "http://localhost:8080/wp-json/wp/v2/media?parent=1"
|
77
|
+
}
|
78
|
+
],
|
79
|
+
"wp:term": [
|
80
|
+
{
|
81
|
+
"taxonomy": "category",
|
82
|
+
"embeddable": true,
|
83
|
+
"href": "http://localhost:8080/wp-json/wp/v2/categories?post=1"
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"taxonomy": "post_tag",
|
87
|
+
"embeddable": true,
|
88
|
+
"href": "http://localhost:8080/wp-json/wp/v2/tags?post=1"
|
89
|
+
}
|
90
|
+
],
|
91
|
+
"curies": [
|
92
|
+
{
|
93
|
+
"name": "wp",
|
94
|
+
"href": "https://api.w.org/{rel}",
|
95
|
+
"templated": true
|
96
|
+
}
|
97
|
+
]
|
98
|
+
}
|
99
|
+
}
|
@@ -1 +1,324 @@
|
|
1
|
-
{
|
1
|
+
{
|
2
|
+
"id": 1,
|
3
|
+
"date": "2015-11-03T07:47:41",
|
4
|
+
"date_gmt": "2015-11-03T07:47:41",
|
5
|
+
"guid": {
|
6
|
+
"rendered": "http://example.com/?p=1"
|
7
|
+
},
|
8
|
+
"modified": "2017-07-31T13:26:39",
|
9
|
+
"modified_gmt": "2017-07-31T13:26:39",
|
10
|
+
"slug": "hello-world",
|
11
|
+
"status": "publish",
|
12
|
+
"type": "post",
|
13
|
+
"link": "http://example.com/2015/11/03/hello-world/",
|
14
|
+
"title": {
|
15
|
+
"rendered": "Hello world!"
|
16
|
+
},
|
17
|
+
"content": {
|
18
|
+
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
|
19
|
+
"protected": false
|
20
|
+
},
|
21
|
+
"excerpt": {
|
22
|
+
"rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
|
23
|
+
"protected": false
|
24
|
+
},
|
25
|
+
"author": 1,
|
26
|
+
"featured_media": 5,
|
27
|
+
"comment_status": "open",
|
28
|
+
"ping_status": "open",
|
29
|
+
"sticky": false,
|
30
|
+
"template": "",
|
31
|
+
"format": "standard",
|
32
|
+
"meta": {
|
33
|
+
"foo": 0,
|
34
|
+
"bar": false,
|
35
|
+
"baz": "helo world!"
|
36
|
+
},
|
37
|
+
"categories": [
|
38
|
+
1
|
39
|
+
],
|
40
|
+
"tags": [
|
41
|
+
2
|
42
|
+
],
|
43
|
+
"_links": {
|
44
|
+
"self": [
|
45
|
+
{
|
46
|
+
"href": "http://example.com/wp-json/wp/v2/posts/1"
|
47
|
+
}
|
48
|
+
],
|
49
|
+
"collection": [
|
50
|
+
{
|
51
|
+
"href": "http://example.com/wp-json/wp/v2/posts"
|
52
|
+
}
|
53
|
+
],
|
54
|
+
"about": [
|
55
|
+
{
|
56
|
+
"href": "http://example.com/wp-json/wp/v2/types/post"
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"author": [
|
60
|
+
{
|
61
|
+
"embeddable": true,
|
62
|
+
"href": "http://example.com/wp-json/wp/v2/users/1"
|
63
|
+
}
|
64
|
+
],
|
65
|
+
"replies": [
|
66
|
+
{
|
67
|
+
"embeddable": true,
|
68
|
+
"href": "http://example.com/wp-json/wp/v2/comments?post=1"
|
69
|
+
}
|
70
|
+
],
|
71
|
+
"version-history": [
|
72
|
+
{
|
73
|
+
"href": "http://example.com/wp-json/wp/v2/posts/1/revisions"
|
74
|
+
}
|
75
|
+
],
|
76
|
+
"wp:featuredmedia": [
|
77
|
+
{
|
78
|
+
"embeddable": true,
|
79
|
+
"href": "http://example.com/wp-json/wp/v2/media/5"
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"wp:attachment": [
|
83
|
+
{
|
84
|
+
"href": "http://example.com/wp-json/wp/v2/media?parent=1"
|
85
|
+
}
|
86
|
+
],
|
87
|
+
"wp:term": [
|
88
|
+
{
|
89
|
+
"taxonomy": "category",
|
90
|
+
"embeddable": true,
|
91
|
+
"href": "http://example.com/wp-json/wp/v2/categories?post=1"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"taxonomy": "post_tag",
|
95
|
+
"embeddable": true,
|
96
|
+
"href": "http://example.com/wp-json/wp/v2/tags?post=1"
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"curies": [
|
100
|
+
{
|
101
|
+
"name": "wp",
|
102
|
+
"href": "https://api.w.org/{rel}",
|
103
|
+
"templated": true
|
104
|
+
}
|
105
|
+
]
|
106
|
+
},
|
107
|
+
"_embedded": {
|
108
|
+
"author": [
|
109
|
+
{
|
110
|
+
"id": 1,
|
111
|
+
"name": "test",
|
112
|
+
"url": "",
|
113
|
+
"description": "",
|
114
|
+
"link": "http://example.com/author/test/",
|
115
|
+
"slug": "test",
|
116
|
+
"avatar_urls": {
|
117
|
+
"24": "http://2.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=24&d=mm&r=g",
|
118
|
+
"48": "http://2.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=48&d=mm&r=g",
|
119
|
+
"96": "http://2.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=96&d=mm&r=g"
|
120
|
+
},
|
121
|
+
"_links": {
|
122
|
+
"self": [
|
123
|
+
{
|
124
|
+
"href": "http://example.com/wp-json/wp/v2/users/1"
|
125
|
+
}
|
126
|
+
],
|
127
|
+
"collection": [
|
128
|
+
{
|
129
|
+
"href": "http://example.com/wp-json/wp/v2/users"
|
130
|
+
}
|
131
|
+
]
|
132
|
+
}
|
133
|
+
}
|
134
|
+
],
|
135
|
+
"replies": [
|
136
|
+
[
|
137
|
+
{
|
138
|
+
"id": 1,
|
139
|
+
"parent": 0,
|
140
|
+
"author": 0,
|
141
|
+
"author_name": "Mr WordPress",
|
142
|
+
"author_url": "https://wordpress.org/",
|
143
|
+
"date": "2015-11-03T07:47:41",
|
144
|
+
"content": {
|
145
|
+
"rendered": "<p>Hi, this is a comment.<br />\nTo delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.</p>\n"
|
146
|
+
},
|
147
|
+
"link": "http://example.com/2015/11/03/hello-world/#comment-1",
|
148
|
+
"type": "comment",
|
149
|
+
"author_avatar_urls": {
|
150
|
+
"24": "http://0.gravatar.com/avatar/?s=24&d=mm&r=g",
|
151
|
+
"48": "http://1.gravatar.com/avatar/?s=48&d=mm&r=g",
|
152
|
+
"96": "http://2.gravatar.com/avatar/?s=96&d=mm&r=g"
|
153
|
+
},
|
154
|
+
"_links": {
|
155
|
+
"self": [
|
156
|
+
{
|
157
|
+
"href": "http://example.com/wp-json/wp/v2/comments/1"
|
158
|
+
}
|
159
|
+
],
|
160
|
+
"collection": [
|
161
|
+
{
|
162
|
+
"href": "http://example.com/wp-json/wp/v2/comments"
|
163
|
+
}
|
164
|
+
],
|
165
|
+
"up": [
|
166
|
+
{
|
167
|
+
"embeddable": true,
|
168
|
+
"post_type": "post",
|
169
|
+
"href": "http://example.com/wp-json/wp/v2/posts/1"
|
170
|
+
}
|
171
|
+
]
|
172
|
+
}
|
173
|
+
}
|
174
|
+
]
|
175
|
+
],
|
176
|
+
"wp:featuredmedia": [
|
177
|
+
{
|
178
|
+
"id": 5,
|
179
|
+
"date": "2017-07-31T13:23:01",
|
180
|
+
"slug": "food-waffles-e1430873095640",
|
181
|
+
"type": "attachment",
|
182
|
+
"link": "http://example.com/2015/11/03/hello-world/food-waffles-e1430873095640/",
|
183
|
+
"title": {
|
184
|
+
"rendered": "food-waffles-e1430873095640"
|
185
|
+
},
|
186
|
+
"author": 1,
|
187
|
+
"caption": {
|
188
|
+
"rendered": ""
|
189
|
+
},
|
190
|
+
"alt_text": "",
|
191
|
+
"media_type": "image",
|
192
|
+
"mime_type": "image/png",
|
193
|
+
"media_details": {
|
194
|
+
"width": 128,
|
195
|
+
"height": 89,
|
196
|
+
"file": "2015/11/food-waffles-e1430873095640.png",
|
197
|
+
"image_meta": {
|
198
|
+
"aperture": "0",
|
199
|
+
"credit": "",
|
200
|
+
"camera": "",
|
201
|
+
"caption": "",
|
202
|
+
"created_timestamp": "0",
|
203
|
+
"copyright": "",
|
204
|
+
"focal_length": "0",
|
205
|
+
"iso": "0",
|
206
|
+
"shutter_speed": "0",
|
207
|
+
"title": "",
|
208
|
+
"orientation": "0",
|
209
|
+
"keywords": []
|
210
|
+
},
|
211
|
+
"sizes": {}
|
212
|
+
},
|
213
|
+
"source_url": "http://example.com/wp-content/uploads/2015/11/food-waffles-e1430873095640.png",
|
214
|
+
"_links": {
|
215
|
+
"self": [
|
216
|
+
{
|
217
|
+
"href": "http://example.com/wp-json/wp/v2/media/5"
|
218
|
+
}
|
219
|
+
],
|
220
|
+
"collection": [
|
221
|
+
{
|
222
|
+
"href": "http://example.com/wp-json/wp/v2/media"
|
223
|
+
}
|
224
|
+
],
|
225
|
+
"about": [
|
226
|
+
{
|
227
|
+
"href": "http://example.com/wp-json/wp/v2/types/attachment"
|
228
|
+
}
|
229
|
+
],
|
230
|
+
"author": [
|
231
|
+
{
|
232
|
+
"embeddable": true,
|
233
|
+
"href": "http://example.com/wp-json/wp/v2/users/1"
|
234
|
+
}
|
235
|
+
],
|
236
|
+
"replies": [
|
237
|
+
{
|
238
|
+
"embeddable": true,
|
239
|
+
"href": "http://example.com/wp-json/wp/v2/comments?post=5"
|
240
|
+
}
|
241
|
+
]
|
242
|
+
}
|
243
|
+
}
|
244
|
+
],
|
245
|
+
"wp:term": [
|
246
|
+
[
|
247
|
+
{
|
248
|
+
"id": 1,
|
249
|
+
"link": "http://example.com/category/uncategorized/",
|
250
|
+
"name": "Uncategorized",
|
251
|
+
"slug": "uncategorized",
|
252
|
+
"taxonomy": "category",
|
253
|
+
"_links": {
|
254
|
+
"self": [
|
255
|
+
{
|
256
|
+
"href": "http://example.com/wp-json/wp/v2/categories/1"
|
257
|
+
}
|
258
|
+
],
|
259
|
+
"collection": [
|
260
|
+
{
|
261
|
+
"href": "http://example.com/wp-json/wp/v2/categories"
|
262
|
+
}
|
263
|
+
],
|
264
|
+
"about": [
|
265
|
+
{
|
266
|
+
"href": "http://example.com/wp-json/wp/v2/taxonomies/category"
|
267
|
+
}
|
268
|
+
],
|
269
|
+
"wp:post_type": [
|
270
|
+
{
|
271
|
+
"href": "http://example.com/wp-json/wp/v2/posts?categories=1"
|
272
|
+
}
|
273
|
+
],
|
274
|
+
"curies": [
|
275
|
+
{
|
276
|
+
"name": "wp",
|
277
|
+
"href": "https://api.w.org/{rel}",
|
278
|
+
"templated": true
|
279
|
+
}
|
280
|
+
]
|
281
|
+
}
|
282
|
+
}
|
283
|
+
],
|
284
|
+
[
|
285
|
+
{
|
286
|
+
"id": 2,
|
287
|
+
"link": "http://example.com/tag/winamp/",
|
288
|
+
"name": "winamp",
|
289
|
+
"slug": "winamp",
|
290
|
+
"taxonomy": "post_tag",
|
291
|
+
"_links": {
|
292
|
+
"self": [
|
293
|
+
{
|
294
|
+
"href": "http://example.com/wp-json/wp/v2/tags/2"
|
295
|
+
}
|
296
|
+
],
|
297
|
+
"collection": [
|
298
|
+
{
|
299
|
+
"href": "http://example.com/wp-json/wp/v2/tags"
|
300
|
+
}
|
301
|
+
],
|
302
|
+
"about": [
|
303
|
+
{
|
304
|
+
"href": "http://example.com/wp-json/wp/v2/taxonomies/post_tag"
|
305
|
+
}
|
306
|
+
],
|
307
|
+
"wp:post_type": [
|
308
|
+
{
|
309
|
+
"href": "http://example.com/wp-json/wp/v2/posts?tags=2"
|
310
|
+
}
|
311
|
+
],
|
312
|
+
"curies": [
|
313
|
+
{
|
314
|
+
"name": "wp",
|
315
|
+
"href": "https://api.w.org/{rel}",
|
316
|
+
"templated": true
|
317
|
+
}
|
318
|
+
]
|
319
|
+
}
|
320
|
+
}
|
321
|
+
]
|
322
|
+
]
|
323
|
+
}
|
324
|
+
}
|
@@ -40,7 +40,7 @@ describe "Attachments" do
|
|
40
40
|
it "uses HTML for the title" do
|
41
41
|
media = find_or_create_attachment
|
42
42
|
updated = client.update_media(media.id, title: "Images & paint")
|
43
|
-
expect(updated.title_html).to eq "Images
|
43
|
+
expect(updated.title_html).to eq "Images & paint"
|
44
44
|
end
|
45
45
|
|
46
46
|
def find_or_create_attachment
|
@@ -71,7 +71,7 @@ describe "Posts (CRUD)" do
|
|
71
71
|
)
|
72
72
|
|
73
73
|
expect(post.content_html.strip).to eq '<p class="hello-world">Hello world</p>'
|
74
|
-
expect(post.title_html.strip).to eq 'HTML test
|
74
|
+
expect(post.title_html.strip).to eq 'HTML test & verify'
|
75
75
|
end
|
76
76
|
|
77
77
|
it "can move a post to the trash can" do
|
@@ -14,73 +14,4 @@ describe "Posts (finding)" do
|
|
14
14
|
expect(posts.map(&:id)).to eq posts.sort_by(&:date).reverse.map(&:id)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "can list articles in a specific category" do
|
18
|
-
category = client.create_category(name: "Filtering time", slug: "filtering")
|
19
|
-
post = client.create_post(
|
20
|
-
category_ids: [category.id],
|
21
|
-
status: "publish",
|
22
|
-
title: "Some title",
|
23
|
-
)
|
24
|
-
|
25
|
-
expect(client.posts(category_slug: "filtering").map(&:id)).to eq [post.id]
|
26
|
-
end
|
27
|
-
|
28
|
-
it "can list articles in a specific tag" do
|
29
|
-
tag = client.create_tag(name: "Taggged", slug: "tagged")
|
30
|
-
post = client.create_post(
|
31
|
-
tag_ids: [tag.id],
|
32
|
-
status: "publish",
|
33
|
-
title: "Some title",
|
34
|
-
)
|
35
|
-
|
36
|
-
expect(client.posts(tag_slug: "tagged").map(&:id)).to eq [post.id]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can list articles in a specific tag and category" do
|
40
|
-
category = client.create_category(name: "Fishing", slug: "fish")
|
41
|
-
tag = client.create_tag(name: "Soup", slug: "soup")
|
42
|
-
post = client.create_post(
|
43
|
-
category_ids: [category.id],
|
44
|
-
tag_ids: [tag.id],
|
45
|
-
status: "publish",
|
46
|
-
title: "Some title",
|
47
|
-
)
|
48
|
-
|
49
|
-
_post_without_tag = client.create_post(
|
50
|
-
category_ids: [category.id],
|
51
|
-
status: "publish",
|
52
|
-
title: "Some title",
|
53
|
-
)
|
54
|
-
|
55
|
-
_post_without_category = client.create_post(
|
56
|
-
tag_ids: [tag.id],
|
57
|
-
status: "publish",
|
58
|
-
title: "Some title",
|
59
|
-
)
|
60
|
-
|
61
|
-
expect(client.posts(category_slug: "fish", tag_slug: "soup").map(&:id)).to eq [post.id]
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "finding by slug" do
|
65
|
-
it "finds the matching post" do
|
66
|
-
post = client.create_post(title: "Oh hai", slug: "oh-hai")
|
67
|
-
found = client.find_by_slug("oh-hai")
|
68
|
-
expect(found.id).to eq post.id
|
69
|
-
end
|
70
|
-
|
71
|
-
it "raises NotFoundError when no post can be found" do
|
72
|
-
expect {
|
73
|
-
client.find_by_slug("clearly-does-not-exist-anywhere")
|
74
|
-
}.to raise_error(WordpressClient::NotFoundError, /clearly/)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "finds on the slug even if the title is wildly different" do
|
78
|
-
post = client.create_post(
|
79
|
-
title: "Updated title that doesn't match slug",
|
80
|
-
slug: "original-concise-title",
|
81
|
-
)
|
82
|
-
found = client.find_by_slug("original-concise-title")
|
83
|
-
expect(found.id).to eq post.id
|
84
|
-
end
|
85
|
-
end
|
86
17
|
end
|
@@ -4,24 +4,24 @@ describe "Post meta" do
|
|
4
4
|
setup_integration_client
|
5
5
|
|
6
6
|
it "can be set on a post" do
|
7
|
-
post = client.create_post(title: "Metadata creation", meta: {foo
|
8
|
-
expect(post.meta).to
|
7
|
+
post = client.create_post(title: "Metadata creation", meta: {"foo" => 7})
|
8
|
+
expect(post.meta).to include("foo" => 7)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "can be updated on a post" do
|
12
|
-
post = client.create_post(title: "Metadata creation", meta: {
|
13
|
-
post = client.update_post(post.id, meta: {"
|
14
|
-
expect(post.meta).to
|
12
|
+
post = client.create_post(title: "Metadata creation", meta: {"foo" => 1})
|
13
|
+
post = client.update_post(post.id, meta: {"foo" => 2, "bar" => true})
|
14
|
+
expect(post.meta).to include("foo" => 2, "bar" => true)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "can remove metadata for a post" do
|
18
|
-
post = client.create_post(title: "Metadata creation", meta: {
|
19
|
-
post = client.update_post(post.id, meta: {
|
20
|
-
expect(post.meta).to eq("
|
18
|
+
post = client.create_post(title: "Metadata creation", meta: {foo: 1, bar: true, baz: "foobar"})
|
19
|
+
post = client.update_post(post.id, meta: {foo: 5, baz: nil})
|
20
|
+
expect(post.meta).to eq("foo" => 5, "bar" => true, "baz" => "")
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
24
|
-
post = client.create_post(title: "Metadata HTML", meta: {
|
25
|
-
expect(post.meta).to eq("foo" => "bar
|
23
|
+
it "returns unescaped HTML" do
|
24
|
+
post = client.create_post(title: "Metadata HTML", meta: {baz: "larry&curly<moe>"})
|
25
|
+
expect(post.meta).to eq("baz" => "larry&curly<moe>", "foo" => 0, "bar" => false)
|
26
26
|
end
|
27
27
|
end
|
@@ -3,19 +3,33 @@ require "spec_helper"
|
|
3
3
|
describe "Posts with attachments" do
|
4
4
|
setup_integration_client
|
5
5
|
|
6
|
-
it "exposes featured
|
7
|
-
media =
|
8
|
-
post = client.create_post(title: "With
|
6
|
+
it "exposes featured media as a Media instance" do
|
7
|
+
media = find_or_upload_image
|
8
|
+
post = client.create_post(title: "With image", featured_media: media.id)
|
9
|
+
expect(post.featured_media).to be_instance_of(WordpressClient::Media)
|
10
|
+
expect(post.featured_media.id).to eq media.id
|
11
|
+
expect(post.featured_media.slug).to eq media.slug
|
12
|
+
expect(post.featured_media.guid).to eq media.guid
|
13
|
+
expect(post.featured_media.source_url).to eq media.source_url
|
14
|
+
expect(post.featured_media_id).to eq media.id
|
15
|
+
end
|
9
16
|
|
17
|
+
it "exposes featured media as featured image if Media is an image" do
|
18
|
+
media = find_or_upload_image
|
19
|
+
post = client.create_post(title: "With image", featured_media: media.id)
|
10
20
|
expect(post.featured_image).to be_instance_of(WordpressClient::Media)
|
21
|
+
expect(post.featured_image.id).to eq media.id
|
11
22
|
expect(post.featured_image.slug).to eq media.slug
|
12
23
|
expect(post.featured_image.guid).to eq media.guid
|
13
24
|
expect(post.featured_image.source_url).to eq media.source_url
|
14
|
-
expect(post.featured_image_id).to eq media.id
|
15
25
|
end
|
16
26
|
|
17
|
-
def
|
18
|
-
|
27
|
+
def find_or_upload_image
|
28
|
+
find_media_of_type("image") ||
|
19
29
|
client.upload_file(fixture_path("thoughtful.jpg"), mime_type: "image/jpeg")
|
20
30
|
end
|
31
|
+
|
32
|
+
def find_media_of_type(type)
|
33
|
+
client.media(per_page: 10).detect { |media| media.media_type == type }
|
34
|
+
end
|
21
35
|
end
|
data/spec/media_spec.rb
CHANGED
@@ -8,8 +8,10 @@ module WordpressClient
|
|
8
8
|
media = Media.parse(fixture)
|
9
9
|
|
10
10
|
expect(media.id).to eq 5
|
11
|
+
expect(media.media_type).to eq "image"
|
11
12
|
expect(media.title_html).to eq "thoughtful"
|
12
13
|
expect(media.slug).to eq "thoughtful"
|
14
|
+
expect(media.alt_text).to eq "accessibility is cool"
|
13
15
|
expect(media.description).to eq ""
|
14
16
|
|
15
17
|
expect(media.guid).to eq "http://example.com/wp-content/uploads/2015/11/thoughtful.jpg"
|
@@ -59,5 +61,17 @@ module WordpressClient
|
|
59
61
|
expect(media.updated_at).to eq Time.local(2001, 1, 1, 12, 0, 0)
|
60
62
|
end
|
61
63
|
end
|
64
|
+
|
65
|
+
describe "#as_image" do
|
66
|
+
it "returns self if media_type is image" do
|
67
|
+
media = Media.parse(fixture)
|
68
|
+
expect(media.as_image).to eq(media)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns nil when media_type is not image" do
|
72
|
+
media = Media.parse(fixture.merge("media_type" => "video"))
|
73
|
+
expect(media.as_image).to be_nil
|
74
|
+
end
|
75
|
+
end
|
62
76
|
end
|
63
77
|
end
|