-
Notifications
You must be signed in to change notification settings - Fork 22
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 #34 from amiel/use-snapshots
Support DS.Snapshot
- Loading branch information
Showing
20 changed files
with
176 additions
and
20 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
|
||
moduleForAcceptance('Acceptance | basic url template'); | ||
|
||
test('it can use a simple custom url', function(assert) { | ||
server.createList('post', 5); | ||
|
||
visit('/posts'); | ||
|
||
andThen(() => { | ||
assert.equal(find('#posts .post').length, 5); | ||
}); | ||
}); | ||
|
||
test('it can use a specific template for one type of call (queryRecord)', function(assert) { | ||
server.create('post', { | ||
slug: 'my-first-post', | ||
title: 'This is my first post', | ||
}); | ||
|
||
visit('/posts/my-first-post'); | ||
|
||
andThen(() => { | ||
assert.equal(find('.post h2').text(), 'This is my first post'); | ||
}); | ||
}); | ||
|
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,23 @@ | ||
import Ember from 'ember'; | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
|
||
const { get } = Ember; | ||
|
||
moduleForAcceptance('Acceptance | simple relationships', { | ||
beforeEach() { | ||
this.post = server.create('post'); | ||
this.comment = server.create('comment', { | ||
post: this.post, | ||
}); | ||
|
||
visit(`/posts/${get(this.post, 'slug')}`); | ||
}, | ||
}); | ||
|
||
test('it can use a belongsTo id from the snapshot when generating a url', function(assert) { | ||
andThen(() => { | ||
assert.equal(find('#comments p').length, 1); | ||
}); | ||
}); | ||
|
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,21 @@ | ||
import Ember from 'ember'; | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
|
||
const { get } = Ember; | ||
|
||
moduleForAcceptance('Acceptance | using attributes', { | ||
beforeEach() { | ||
this.post = server.create('post'); | ||
}, | ||
}); | ||
|
||
test('it can use an attribute from the snapshot when generating a url', function(assert) { | ||
visit(`/posts/${get(this.post, 'slug')}`); | ||
click('#publish-post'); | ||
visit(`/posts/${get(this.post, 'slug')}`); | ||
|
||
andThen(() => { | ||
assert.equal(find('#publish-post').length, 0); | ||
}); | ||
}); |
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,6 @@ | ||
import ApplicationAdapter from './application'; | ||
|
||
export default ApplicationAdapter.extend({ | ||
namespace: 'api', | ||
urlTemplate: "{/namespace}/posts/{postId}/comments{/id}", | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import ApplicationAdapter from './application'; | ||
|
||
export default ApplicationAdapter.extend({ | ||
urlTemplate: "{+host}{/namespace}/my-posts{/id}", | ||
urlTemplate: "{+host}{/namespace}/my-posts", | ||
queryRecordUrlTemplate: "{+host}{/namespace}/my-posts/{slug}", | ||
updateRecordUrlTemplate: "{+host}{/namespace}/my-posts/{slug}", | ||
namespace: 'api', | ||
}); |
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,14 @@ | ||
import Ember from 'ember'; | ||
|
||
const { computed } = Ember; | ||
|
||
export default Ember.Controller.extend({ | ||
post: computed.readOnly('model'), | ||
|
||
actions: { | ||
publishPost(post) { | ||
post.set('isPublished', true); | ||
post.save(); | ||
}, | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import DS from 'ember-data'; | ||
|
||
const { attr, belongsTo } = DS; | ||
|
||
export default DS.Model.extend({ | ||
post: belongsTo(), | ||
message: attr('string'), | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import DS from 'ember-data'; | ||
|
||
const { attr } = DS; | ||
const { attr, hasMany } = DS; | ||
|
||
export default DS.Model.extend({ | ||
slug: attr('string'), | ||
title: attr('string'), | ||
isPublished: attr('boolean'), | ||
comments: hasMany(), | ||
}); |
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
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,7 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Route.extend({ | ||
model(params) { | ||
return this.store.queryRecord('post', { slug: params.slug }); | ||
}, | ||
}); |
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,15 @@ | ||
<div id="post-{{post.id}}" class="post"> | ||
<h2>{{post.title}}</h2> | ||
|
||
{{#unless post.isPublished}} | ||
<a id="publish-post" {{action 'publishPost' post}}>Publish Post</a> | ||
{{/unless}} | ||
|
||
<h3>Comments</h3> | ||
|
||
<div id="comments"> | ||
{{#each post.comments as |comment|}} | ||
<p>{{comment.message}}</p> | ||
{{/each}} | ||
</div> | ||
</div> |
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
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
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,7 @@ | ||
import { Factory, faker } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
message() { | ||
return faker.lorem.sentence(); | ||
}, | ||
}); |
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
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,5 @@ | ||
import { Model, belongsTo } from 'ember-cli-mirage'; | ||
|
||
export default Model.extend({ | ||
post: belongsTo(), | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Model } from 'ember-cli-mirage'; | ||
import { Model, hasMany } from 'ember-cli-mirage'; | ||
|
||
export default Model.extend({ | ||
comments: hasMany(), | ||
}); |