fix(db): Messages with empty bodies always showing loading spinner due to ‘’ == null

This commit is contained in:
Ben Gotow 2016-09-28 11:42:18 -07:00
parent 2739cc822e
commit 1e7dfea7d7
2 changed files with 27 additions and 0 deletions

View file

@ -98,6 +98,9 @@ describe "Model", ->
modelKey: 'testCollection'
jsonKey: 'test_collection'
itemClass: SubmodelItem
'testJoinedData': Attributes.JoinedData
modelKey: 'testJoinedData'
jsonKey: 'test_joined_data'
@json =
'id': '1234'
@ -126,6 +129,11 @@ describe "Model", ->
@m.fromJSON(@json)
expect(@m.daysOld).toBe(undefined)
it "should maintain empty string as empty strings", ->
expect(@m.accountId).toBe(undefined)
@m.fromJSON({account_id: ''})
expect(@m.accountId).toBe('')
describe "Attributes.Number", ->
it "should read number attributes and coerce them to numeric values", ->
@m.fromJSON('test_number': 4)
@ -140,6 +148,17 @@ describe "Model", ->
@m.fromJSON('test_number': 0)
expect(@m.testNumber).toBe(0)
describe "Attributes.JoinedData", ->
it "should read joined data attributes and coerce them to string values", ->
@m.fromJSON('test_joined_data': null)
expect(@m.testJoinedData).toBe(null)
@m.fromJSON('test_joined_data': '')
expect(@m.testJoinedData).toBe('')
@m.fromJSON('test_joined_data': 'lolz')
expect(@m.testJoinedData).toBe('lolz')
describe "Attributes.Collection", ->
it "should parse and inflate items", ->
@m.fromJSON('test_collection': [{id: '123'}])

View file

@ -38,6 +38,14 @@ export default class AttributeJoinedData extends Attribute {
this.modelTable = modelTable;
}
toJSON(val) {
return val;
}
fromJSON(val) {
return (val === null || val === undefined || val === false) ? null : `${val}`;
}
selectSQL() {
// NullPlaceholder is necessary because if the LEFT JOIN returns nothing, it leaves the field
// blank, and it comes through in the result row as "" rather than NULL