Skip to content

Commit 8cec74f

Browse files
committed
mirage/crate: Replace keywords property with relationship
1 parent 169e9ba commit 8cec74f

File tree

7 files changed

+104
-23
lines changed

7 files changed

+104
-23
lines changed

mirage/factories/crate.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export default Factory.extend({
2323
updated_at: '2017-02-24T12:34:56Z',
2424

2525
badges: () => [],
26-
keywords: () => [],
2726
versions: () => [],
2827
_extra_downloads: () => [],
2928
_owner_teams: () => [],

mirage/fixtures/crates.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default [
1515
recent_downloads: 125,
1616
homepage: 'https://icorderi.github.io/icorderi/kinetic-rust',
1717
id: 'kinetic-rust',
18-
keywords: ['Protocol', 'Kinetic', 'Storage'],
18+
keywordIds: [],
1919
max_version: '0.0.16',
2020
newest_version: '0.0.16',
2121
name: 'kinetic-rust',
@@ -40,7 +40,7 @@ export default [
4040
recent_downloads: 800,
4141
homepage: 'https://github.com/thehydroimpulse/nanomsg.rs',
4242
id: 'nanomsg',
43-
keywords: ['network'],
43+
keywordIds: ['network'],
4444
max_version: '0.7.0-alpha',
4545
newest_version: '0.6.1',
4646
name: 'nanomsg',
@@ -70,7 +70,7 @@ export default [
7070
exact_match: true,
7171
homepage: 'https://github.com/huonw/external_mixin',
7272
id: 'rust_mixin',
73-
keywords: ['rust', 'plugin', 'code-generation'],
73+
keywordIds: ['rust', 'plugin', 'code-generation'],
7474
max_version: '0.0.1',
7575
newest_version: '0.0.1',
7676
name: 'rust_mixin',
@@ -143,7 +143,7 @@ export default [
143143
recent_downloads: 497,
144144
homepage: 'https://github.com/huonw/external_mixin',
145145
id: 'external_mixin',
146-
keywords: ['python', 'ruby', 'shell', 'plugin', 'code-generation'],
146+
keywordIds: ['python', 'ruby', 'shell', 'plugin', 'code-generation'],
147147
max_version: '0.0.1',
148148
newest_version: '0.0.1',
149149
name: 'external_mixin',
@@ -159,7 +159,7 @@ export default [
159159
recent_downloads: 0,
160160
homepage: 'https://github.com/huonw/external_mixin',
161161
id: 'external_mixin_umbrella',
162-
keywords: ['plugin', 'code-generation'],
162+
keywordIds: ['plugin', 'code-generation'],
163163
max_version: '0.0.2',
164164
newest_version: '0.0.2',
165165
name: 'external_mixin_umbrella',
@@ -176,7 +176,7 @@ export default [
176176
recent_downloads: 1,
177177
homepage: 'https://github.com/whatisinternet/inflector',
178178
id: 'Inflector',
179-
keywords: ['string', 'case', 'camel', 'snake', 'inflection'],
179+
keywordIds: ['string', 'case', 'camel', 'snake', 'inflection'],
180180
max_version: '0.1.6',
181181
newest_version: '0.1.6',
182182
name: 'Inflector',
@@ -192,7 +192,7 @@ export default [
192192
recent_downloads: 21,
193193
homepage: null,
194194
id: 'rs-es',
195-
keywords: ['elasticsearch', 'elastic'],
195+
keywordIds: ['elasticsearch', 'elastic'],
196196
max_version: '0.1.17',
197197
newest_version: '0.1.17',
198198
name: 'rs-es',
@@ -208,7 +208,7 @@ export default [
208208
recent_downloads: 2000,
209209
homepage: 'https://github.com/DaGenix/rust-crypto/',
210210
id: 'rust-crypto',
211-
keywords: ['Crypto', 'MD5', 'Sha1', 'Sha2', 'AES'],
211+
keywordIds: [],
212212
max_version: '0.2.34',
213213
newest_version: '0.2.34',
214214
name: 'rust-crypto',
@@ -224,7 +224,7 @@ export default [
224224
recent_downloads: 85,
225225
homepage: null,
226226
id: 'rust-htslib',
227-
keywords: ['htslib', 'bam', 'bioinformatics', 'pileup', 'sequencing'],
227+
keywordIds: [],
228228
max_version: '0.5.2',
229229
newest_version: '0.5.2',
230230
name: 'rust-htslib',
@@ -240,7 +240,7 @@ export default [
240240
recent_downloads: 500,
241241
homepage: 'https://github.com/rustless/rustless',
242242
id: 'rustless',
243-
keywords: ['api', 'web', 'hyper', 'iron', 'rest'],
243+
keywordIds: [],
244244
max_version: '0.8.0',
245245
newest_version: '0.8.0',
246246
name: 'rustless',
@@ -256,7 +256,7 @@ export default [
256256
recent_downloads: 854,
257257
homepage: null,
258258
id: 'serde',
259-
keywords: ['serde', 'serialization'],
259+
keywordIds: [],
260260
max_version: '0.6.1',
261261
newest_version: '0.6.1',
262262
name: 'serde',
@@ -272,7 +272,7 @@ export default [
272272
recent_downloads: 54,
273273
homepage: 'https://github.com/livioribeiro/rusted-cypher',
274274
id: 'rusted_cypher',
275-
keywords: ['neo4j', 'database', 'query', 'cypher', 'graph'],
275+
keywordIds: [],
276276
max_version: '0.7.1',
277277
newest_version: '0.7.1',
278278
name: 'rusted_cypher',
@@ -289,7 +289,7 @@ export default [
289289
recent_downloads: 23,
290290
homepage: null,
291291
id: 'zlib',
292-
keywords: [],
292+
keywordIds: [],
293293
max_version: '0.0.1',
294294
newest_version: '0.0.1',
295295
name: 'zlib',
@@ -306,7 +306,7 @@ export default [
306306
recent_downloads: 76,
307307
homepage: null,
308308
id: 'rustful',
309-
keywords: ['web', 'rest', 'framework', 'http', 'routing'],
309+
keywordIds: [],
310310
max_version: '0.5.0',
311311
newest_version: '0.5.0',
312312
name: 'rustful',
@@ -322,7 +322,7 @@ export default [
322322
recent_downloads: 13,
323323
homepage: null,
324324
id: 'postgres',
325-
keywords: ['database', 'sql'],
325+
keywordIds: [],
326326
max_version: '0.10.1',
327327
newest_version: '0.10.1',
328328
name: 'postgres',
@@ -338,7 +338,7 @@ export default [
338338
recent_downloads: 143,
339339
homepage: 'https://github.com/BurntSushi/quickcheck',
340340
id: 'quickcheck',
341-
keywords: ['testing', 'quickcheck', 'property', 'shrinking', 'fuzz'],
341+
keywordIds: [],
342342
max_version: '0.2.24',
343343
newest_version: '0.2.24',
344344
name: 'quickcheck',
@@ -354,7 +354,7 @@ export default [
354354
recent_downloads: 768,
355355
homepage: 'https://github.com/BurntSushi/quickcheck',
356356
id: 'quickcheck_macros',
357-
keywords: ['testing', 'quickcheck', 'property', 'shrinking', 'fuzz'],
357+
keywordIds: [],
358358
max_version: '0.2.24',
359359
newest_version: '0.2.24',
360360
name: 'quickcheck_macros',
@@ -371,7 +371,7 @@ export default [
371371
recent_downloads: 0,
372372
homepage: 'https://github.com/nicolas-cherel/rustlex',
373373
id: 'unicorn-rpc',
374-
keywords: ['lexer', 'lexical', 'analyser', 'generator'],
374+
keywordIds: [],
375375
max_version: '0.3.1',
376376
newest_version: '0.3.1',
377377
name: 'unicorn-rpc',
@@ -387,7 +387,7 @@ export default [
387387
recent_downloads: 69,
388388
homepage: null,
389389
id: 'nom',
390-
keywords: ['parser', 'parser-combinators', 'parsing', 'streaming', 'bit'],
390+
keywordIds: [],
391391
max_version: '1.0.1',
392392
newest_version: '1.0.1',
393393
name: 'nom',

mirage/fixtures/keywords.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,82 @@ export default [
55
id: 'network',
66
keyword: 'network',
77
},
8+
{
9+
crates_cnt: 1,
10+
created_at: '2014-11-23T06:47:40Z',
11+
id: 'rust',
12+
keyword: 'rust',
13+
},
14+
{
15+
crates_cnt: 1,
16+
created_at: '2014-11-23T06:47:40Z',
17+
id: 'plugin',
18+
keyword: 'plugin',
19+
},
20+
{
21+
crates_cnt: 1,
22+
created_at: '2014-11-23T06:47:40Z',
23+
id: 'code-generation',
24+
keyword: 'code-generation',
25+
},
26+
{
27+
crates_cnt: 1,
28+
created_at: '2014-11-23T06:47:40Z',
29+
id: 'python',
30+
keyword: 'python',
31+
},
32+
{
33+
crates_cnt: 1,
34+
created_at: '2014-11-23T06:47:40Z',
35+
id: 'ruby',
36+
keyword: 'ruby',
37+
},
38+
{
39+
crates_cnt: 1,
40+
created_at: '2014-11-23T06:47:40Z',
41+
id: 'shell',
42+
keyword: 'shell',
43+
},
44+
{
45+
crates_cnt: 1,
46+
created_at: '2014-11-23T06:47:40Z',
47+
id: 'string',
48+
keyword: 'string',
49+
},
50+
{
51+
crates_cnt: 1,
52+
created_at: '2014-11-23T06:47:40Z',
53+
id: 'case',
54+
keyword: 'case',
55+
},
56+
{
57+
crates_cnt: 1,
58+
created_at: '2014-11-23T06:47:40Z',
59+
id: 'camel',
60+
keyword: 'camel',
61+
},
62+
{
63+
crates_cnt: 1,
64+
created_at: '2014-11-23T06:47:40Z',
65+
id: 'snake',
66+
keyword: 'snake',
67+
},
68+
{
69+
crates_cnt: 1,
70+
created_at: '2014-11-23T06:47:40Z',
71+
id: 'inflection',
72+
keyword: 'inflection',
73+
},
74+
{
75+
crates_cnt: 1,
76+
created_at: '2014-11-23T06:47:40Z',
77+
id: 'elastic',
78+
keyword: 'elastic',
79+
},
80+
{
81+
crates_cnt: 1,
82+
created_at: '2014-11-23T06:47:40Z',
83+
id: 'elasticsearch',
84+
keyword: 'elasticsearch',
85+
},
886
];

mirage/models/crate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import { Model, hasMany } from 'ember-cli-mirage';
22

33
export default Model.extend({
44
categories: hasMany(),
5+
keywords: hasMany(),
56
});

mirage/route-handlers/crates.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ export function register(server) {
3838
let crate = schema.crates.find(crateId);
3939
if (!crate) return notFound();
4040

41-
let keywords = schema.keywords.all().filter(keyword => (crate.keywords || []).indexOf(keyword.id) !== -1);
4241
let versions = schema.versions
4342
.all()
4443
.filter(version => (crate.versions || []).indexOf(parseInt(version.id, 10)) !== -1);
4544

4645
return {
4746
...this.serialize(crate),
4847
...this.serialize(crate.categories),
49-
...this.serialize(keywords),
48+
...this.serialize(crate.keywords),
5049
...this.serialize(versions),
5150
};
5251
});

mirage/serializers/crate.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@ export default BaseSerializer.extend({
4848
_adjust(hash) {
4949
hash.categories = hash.category_ids;
5050
delete hash.category_ids;
51+
52+
hash.keywords = hash.keyword_ids;
53+
delete hash.keyword_ids;
5154
},
5255
});

tests/mirage/crates-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,13 @@ module('Mirage | Keywords', function(hooks) {
304304
test('includes related keywords', async function(assert) {
305305
this.server.create('keyword', { keyword: 'no-std' });
306306
this.server.create('keyword', { keyword: 'cli' });
307-
this.server.create('crate', { name: 'rand', keywords: ['no-std'] });
307+
this.server.create('crate', { name: 'rand', keywordIds: ['no-std'] });
308308

309309
let response = await fetch('/api/v1/crates/rand');
310310
assert.equal(response.status, 200);
311311

312312
let responsePayload = await response.json();
313+
assert.deepEqual(responsePayload.crate.keywords, ['no-std']);
313314
assert.deepEqual(responsePayload.keywords, [
314315
{
315316
crates_cnt: 0,

0 commit comments

Comments
 (0)