File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export default class Version extends Model {
19
19
20
20
@belongsTo ( 'crate' , { async : false } ) crate ;
21
21
22
+ @belongsTo ( 'user' , { async : false } ) published_by ;
22
23
@hasMany ( 'users' , { async : true } ) authors ;
23
24
@hasMany ( 'dependency' , { async : true } ) dependencies ;
24
25
@hasMany ( 'version-download' , { async : true } ) version_downloads ;
Original file line number Diff line number Diff line change
1
+ import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest' ;
2
+
3
+ import ApplicationSerializer from './application' ;
4
+
5
+ export default ApplicationSerializer . extend ( EmbeddedRecordsMixin , {
6
+ attrs : {
7
+ published_by : { embedded : 'always' } ,
8
+ } ,
9
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { setupTest } from 'ember-qunit' ;
2
+ import { module , test } from 'qunit' ;
3
+
4
+ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage' ;
5
+
6
+ module ( 'Model | Version' , function ( hooks ) {
7
+ setupTest ( hooks ) ;
8
+ setupMirage ( hooks ) ;
9
+
10
+ hooks . beforeEach ( function ( ) {
11
+ this . store = this . owner . lookup ( 'service:store' ) ;
12
+ } ) ;
13
+
14
+ test ( '`published_by` relationship is assigned correctly' , async function ( assert ) {
15
+ let user = this . server . create ( 'user' , { name : 'JD' } ) ;
16
+
17
+ let crate = this . server . create ( 'crate' ) ;
18
+ this . server . create ( 'version' , { crate, publishedBy : user } ) ;
19
+
20
+ let crateRecord = await this . store . findRecord ( 'crate' , crate . id ) ;
21
+ assert . ok ( crateRecord ) ;
22
+ let versions = ( await crateRecord . versions ) . toArray ( ) ;
23
+ assert . equal ( versions . length , 1 ) ;
24
+ let version = versions [ 0 ] ;
25
+ assert . ok ( version . published_by ) ;
26
+ assert . equal ( version . published_by . name , 'JD' ) ;
27
+ } ) ;
28
+ } ) ;
You can’t perform that action at this time.
0 commit comments