Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for non-dasherized lookups #3830

Merged
merged 1 commit into from
Oct 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.