Skip to content

Instantly share code, notes, and snippets.

@he9qi
Created March 29, 2016 04:12
Show Gist options
  • Save he9qi/b6354a81a0672dc63294 to your computer and use it in GitHub Desktop.
Save he9qi/b6354a81a0672dc63294 to your computer and use it in GitHub Desktop.
Emberjs Model Relationship Test Helpers
import { test } from 'ember-qunit';
import Ember from 'ember';
export function testForHasMany(name, many) {
test('should have many ' + many, function(assert) {
const Model = this.store().modelFor(name);
const relationship = Ember.get(Model, 'relationshipsByName').get(many);
assert.equal(relationship.key, many, 'has relationship with ' + many);
assert.equal(relationship.kind, 'hasMany', 'kind of relationship is hasMany');
});
}
export function testForBelongsTo(name, belongsTo) {
test('should belong to ' + belongsTo, function(assert) {
const Model = this.store().modelFor(name);
const relationship = Ember.get(Model, 'relationshipsByName').get(belongsTo);
assert.equal(relationship.key, belongsTo, 'has relationship with ' + belongsTo);
assert.equal(relationship.kind, 'belongsTo', 'kind of relationship is belongsTo');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment