Skip to content

Commit c116044

Browse files
authored
Merge pull request #25 from willsoto/enumberable-properties
[Proposal] Make attributes enumerable
2 parents b9e7b33 + d794e27 commit c116044

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/attribute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export default class Attribute {
5151
}
5252

5353
// This returns the getters/setters for use on the *model*
54-
descriptor() {
54+
descriptor(): PropertyDescriptor {
5555
let attr = this;
5656

5757
return {
58-
writeable: true,
58+
enumerable: true,
5959
get() : any {
6060
return attr.getter(this);
6161
},

test/unit/attributes-test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ describe('Model attributes', function() {
4747
expect(author.relationships['books']).to.deep.eq([])
4848
});
4949

50+
it('has enumerable properties', function() {
51+
let person = new Person();
52+
let keys = Object.keys(person);
53+
54+
expect(keys).to.include('firstName');
55+
expect(keys).to.include('lastName');
56+
});
57+
58+
it('has enumerable properties even when subclassing', function() {
59+
class BadPerson extends Person {}
60+
61+
let badPerson = new BadPerson();
62+
let keys = Object.keys(badPerson);
63+
64+
expect(keys).to.include('firstName');
65+
expect(keys).to.include('lastName');
66+
});
67+
5068
// Without this behavior, the API could add a backwards-compatible field,
5169
// and this object might blow up.
5270
describe('when passed an invalid attribute in constructor', function() {

test/unit/relationships-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ describe('Model relationships', function() {
3333
let genre = new Genre();
3434
expect(genre.authors.length).to.eql(0);
3535
});
36+
37+
it('has enumerable properties', function() {
38+
let genre = new Genre({ name: 'Horror' });
39+
let author = new Author({ genre: genre });
40+
let keys = Object.keys(author);
41+
42+
expect(keys).to.include('genre');
43+
});
3644
});

0 commit comments

Comments
 (0)