Skip to content

Commit 92b5cb9

Browse files
committed
fix(styles): Fixes AMS style definition, adds a ams-spec.
Fixes #151
1 parent cbde4f1 commit 92b5cb9

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/styles/ams.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ angular.module('restmod').factory('AMSApi', ['restmod', 'inflector', function(re
1111
jsonLinks: 'links'
1212
},
1313

14-
$methods: {
14+
$extend: {
1515
// special snakecase to camelcase renaming
16-
type: {
16+
Model: {
1717
decodeName: inflector.camelize,
1818
encodeName: function(_v) { return inflector.parameterize(_v, '_'); }
1919
}

test/styles/ams-spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
describe('Style: AMS', function() {
4+
5+
var bike;
6+
7+
beforeEach(module('restmod'));
8+
9+
beforeEach(module(function($provide, restmodProvider) {
10+
restmodProvider.rebase('AMSApi');
11+
$provide.factory('Bike', function(restmod) {
12+
return restmod.model('/api/bikes', {
13+
user: { belongsTo: restmod.model('/api/users') }
14+
});
15+
});
16+
}));
17+
18+
beforeEach(inject(function(Bike) {
19+
bike = Bike.$new();
20+
}));
21+
22+
it('should properly rename names on decode/encode', function() {
23+
bike.$decode({ 'rear_wheel': 'crossmax' });
24+
25+
expect(bike.rearWheel).toBeDefined();
26+
expect(bike['rear_wheel']).not.toBeDefined();
27+
expect(bike.$encode()['rear_wheel']).toBeDefined();
28+
expect(bike.$encode().rearWheel).not.toBeDefined();
29+
});
30+
31+
it('should use "id" as primary key', function() {
32+
bike.$decode({ id: 1 });
33+
expect(bike.$pk).toEqual(1);
34+
});
35+
36+
it('should extract metadata from "meta" property', function() {
37+
bike.$unwrap({ bike: { id: 1 }, meta: { date: '2014-05-01' } });
38+
expect(bike.$metadata).toBeDefined();
39+
expect(bike.$metadata.date).toBeDefined();
40+
});
41+
42+
it('should extract links from "links" property', function() {
43+
bike.$unwrap({ bike: { id: 1, 'user_id': 1 }, links: { users: [ { id: 1, name: 'Pancho' } ] } });
44+
expect(bike.user).toBeDefined();
45+
expect(bike.user.name).toEqual('Pancho');
46+
});
47+
});

0 commit comments

Comments
 (0)