Skip to content

Commit

Permalink
Merge pull request #3830 from HeroicEric/tests-with-broken-filenames
Browse files Browse the repository at this point in the history
Fix tests for non-dasherized lookups
  • Loading branch information
bmac committed Oct 11, 2015
2 parents 54489d6 + 8419aec commit 1192a6c
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
const get = Ember.get;
const { run } = Ember;

const {
JSONAPIAdapter,
JSONAPISerializer,
Model,
attr,
belongsTo,
hasMany
} = DS;

let store;

module('integration/backwards-compat/non-dasherized-lookups - non dasherized lookups in application code finders', {
setup: function() {
const PostNote = Model.extend({
name: attr('string')
});

const env = setupStore({ postNote: PostNote });

const ApplicationAdapter = JSONAPIAdapter.extend({
shouldBackgroundReloadRecord() {
return false;
}
});

env.registry.register('adapter:application', ApplicationAdapter);
env.registry.register('serializer:application', JSONAPISerializer);

store = env.store;
},

teardown: function() {
run(store, 'destroy');
}
});

test('can lookup records using camelCase strings', function() {
expect(1);

run(() => {
store.pushPayload('post-note', {
data: {
type: 'post-notes',
id: '1',
attributes: {
name: 'Ember Data'
}
}
});
});

run(() => {
store.findRecord('postNote', 1).then((postNote) => {
equal(get(postNote, 'name'), 'Ember Data', 'record found');
});
});
});

test('can lookup records using under_scored strings', function() {
expect(1);

run(() => {
store.pushPayload('post-note', {
data: {
type: 'post-notes',
id: '1',
attributes: {
name: 'Ember Data'
}
}
});
});

run(() => {
store.findRecord('post_note', 1).then((postNote) => {
equal(get(postNote, 'name'), 'Ember Data', 'record found');
});
});
});

module('integration/backwards-compat/non-dasherized-lookups - non dasherized lookups in application code relationship macros', {
setup: function() {
const PostNote = Model.extend({
notePost: belongsTo('note-post', { async: false }),

name: attr('string')
});

const NotePost = Model.extend({
name: attr('string')
});

const LongModelName = Model.extend({
postNotes: hasMany('post_note')
});

const env = setupStore({
longModelName: LongModelName,
notePost: NotePost,
postNote: PostNote
});

const ApplicationAdapter = JSONAPIAdapter.extend({
shouldBackgroundReloadRecord() {
return false;
}
});

env.registry.register('adapter:application', ApplicationAdapter);
env.registry.register('serializer:application', JSONAPISerializer);

store = env.store;
},

teardown: function() {
run(store, 'destroy');
}
});

test('looks up belongsTo using camelCase strings', function() {
expect(1);

run(() => {
store.pushPayload('post-note', {
data: {
type: 'post-notes',
id: '1',
attributes: {
name: 'Ember Data'
},
relationships: {
'note-post': {
data: { type: 'note-post', id: '1' }
}
}
}
});
store.pushPayload('notePost', {
data: {
type: 'note-posts',
id: '1',
attributes: {
name: 'Inverse'
}
}
});
});

run(() => {
store.findRecord('post-note', 1).then((postNote) => {
equal(get(postNote, 'notePost.name'), 'Inverse', 'inverse record found');
});
});
});

test('looks up belongsTo using under_scored strings', function() {
expect(1);

run(() => {
store.pushPayload('long_model_name', {
data: {
type: 'long-model-names',
id: '1',
attributes: {
},
relationships: {
'post-notes': {
data: [{ type: 'post-note', id: '1' }]
}
}
}
});

store.pushPayload('post-note', {
data: {
type: 'post-notes',
id: '1',
attributes: {
name: 'Ember Data'
}
}
});
});

run(() => {
store.findRecord('long_model_name', 1).then((longModelName) => {
const postNotes = get(longModelName, 'postNotes').toArray();

deepEqual(postNotes, [store.peekRecord('postNote', 1)],
'inverse records found');
});
});
});

This file was deleted.

0 comments on commit 1192a6c

Please sign in to comment.