From 9627ae9b0ce20fea7ab7f1c2c79ccdee873618ea Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 28 Sep 2016 11:42:18 -0700 Subject: [PATCH] =?UTF-8?q?fix(db):=20Messages=20with=20empty=20bodies=20a?= =?UTF-8?q?lways=20showing=20loading=20spinner=20due=20to=20=E2=80=98?= =?UTF-8?q?=E2=80=99=20=3D=3D=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/models/model-spec.coffee | 19 +++++++++++++++++++ src/flux/attributes/attribute-joined-data.es6 | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/spec/models/model-spec.coffee b/spec/models/model-spec.coffee index a15ea81b7..459d76168 100644 --- a/spec/models/model-spec.coffee +++ b/spec/models/model-spec.coffee @@ -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'}]) diff --git a/src/flux/attributes/attribute-joined-data.es6 b/src/flux/attributes/attribute-joined-data.es6 index 4d2607900..0eff63a5e 100644 --- a/src/flux/attributes/attribute-joined-data.es6 +++ b/src/flux/attributes/attribute-joined-data.es6 @@ -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