Skip to content

Instantly share code, notes, and snippets.

@mzniko
Created April 14, 2014 23:07
Show Gist options
  • Save mzniko/10689027 to your computer and use it in GitHub Desktop.
Save mzniko/10689027 to your computer and use it in GitHub Desktop.
<h3 class="customers_heading">Now in the Customers Index</h3>
<ul class="contacts_list">
{{#each customer in controller}}
<li>Name: {{name}}</li>
<li>Email: {{email}}</li>
{{/each}}
</ul>
DeluciaEmber.Customer = DS.Model.extend({
name: DS.attr('string'),
email: DS.attr('string')
});
class Api::V1::CustomersController < ApplicationController
def index
@customers = Customer.all
render json: @customers
end
def show
@customer = Customer.find(params[:id])
render json: @customer
end
end
module('Customers integration', {
setup: function () {
DeluciaEmber.ApplicationAdapter = DS.FixtureAdapter;
DeluciaEmber.Customer.FIXTURES = [
{
id: 1,
name: 'Newguy McSouthEast',
email: 'McSouthEast@email.com'
},
{
id: 2,
name: 'Newgirl MacPearlDistrict',
email: 'MacPearlDistrict@email.com'
}
]
},
teardown: function () {
DeluciaEmber.reset();
}
});
test('Customers index page', function () {
visit('/customers');
andThen(function () {
var header_text = find('.customers_heading').text();
equal(header_text, "Now in the Customers Index",
'Expected "Now in the Customers Index", got: ' + header_text );
});
});
test('Renders customers', function () {
visit('/customers');
andThen(function () {
var contacts_length = find('.contacts_list li').length;
equal(contacts_length, 2,
"Expected customers to contain 2 items, got: " + contacts_length);
});
});
DeluciaEmber.CustomersRoute = Ember.Route.Extend({
model: function () {
return this.store.find('customer');
}
});
DeluciaEmber.Router.map ->
@resource 'customers'
DeluciaEmber.Store = DS.Store.extend
# Override the default adapter with the `DS.ActiveModelAdapter` which
# is built to work nicely with the ActiveModel::Serializers gem.
adapter: '-active-model'
DS.RESTAdapter.reopen({ namespace: "api/v1"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment