-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3830 from HeroicEric/tests-with-broken-filenames
Fix tests for non-dasherized lookups
- Loading branch information
Showing
2 changed files
with
196 additions
and
121 deletions.
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
121 changes: 0 additions & 121 deletions
121
packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js
This file was deleted.
Oops, something went wrong.