Skip to content

Commit

Permalink
fix(styles): Fixes AMS style definition, adds a ams-spec.
Browse files Browse the repository at this point in the history
Fixes #151
  • Loading branch information
iobaixas committed Sep 23, 2014
1 parent cbde4f1 commit 92b5cb9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/styles/ams.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ angular.module('restmod').factory('AMSApi', ['restmod', 'inflector', function(re
jsonLinks: 'links'
},

$methods: {
$extend: {
// special snakecase to camelcase renaming
type: {
Model: {
decodeName: inflector.camelize,
encodeName: function(_v) { return inflector.parameterize(_v, '_'); }
}
Expand Down
47 changes: 47 additions & 0 deletions test/styles/ams-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

describe('Style: AMS', function() {

var bike;

beforeEach(module('restmod'));

beforeEach(module(function($provide, restmodProvider) {
restmodProvider.rebase('AMSApi');
$provide.factory('Bike', function(restmod) {
return restmod.model('/api/bikes', {
user: { belongsTo: restmod.model('/api/users') }
});
});
}));

beforeEach(inject(function(Bike) {
bike = Bike.$new();
}));

it('should properly rename names on decode/encode', function() {
bike.$decode({ 'rear_wheel': 'crossmax' });

expect(bike.rearWheel).toBeDefined();
expect(bike['rear_wheel']).not.toBeDefined();
expect(bike.$encode()['rear_wheel']).toBeDefined();
expect(bike.$encode().rearWheel).not.toBeDefined();
});

it('should use "id" as primary key', function() {
bike.$decode({ id: 1 });
expect(bike.$pk).toEqual(1);
});

it('should extract metadata from "meta" property', function() {
bike.$unwrap({ bike: { id: 1 }, meta: { date: '2014-05-01' } });
expect(bike.$metadata).toBeDefined();
expect(bike.$metadata.date).toBeDefined();
});

it('should extract links from "links" property', function() {
bike.$unwrap({ bike: { id: 1, 'user_id': 1 }, links: { users: [ { id: 1, name: 'Pancho' } ] } });
expect(bike.user).toBeDefined();
expect(bike.user.name).toEqual('Pancho');
});
});

0 comments on commit 92b5cb9

Please sign in to comment.