diff options
author | Christopher Speller <crspeller@gmail.com> | 2015-10-02 08:50:23 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2015-10-02 08:50:23 -0400 |
commit | 92404d6452758941ec96a559f7d8eee794fb1001 (patch) | |
tree | 37cd1c713f5b4934693cd76e1d8f621364180840 /model | |
parent | 08d390953a822371380b4264c3fb4cf891440995 (diff) | |
parent | fc82f57102ae4b8f89d8ad65ae3097aba9891272 (diff) | |
download | chat-92404d6452758941ec96a559f7d8eee794fb1001.tar.gz chat-92404d6452758941ec96a559f7d8eee794fb1001.tar.bz2 chat-92404d6452758941ec96a559f7d8eee794fb1001.zip |
Merge pull request #906 from teviot/teviot-patch-2
Pass-through post creation time when importing posts
Diffstat (limited to 'model')
-rw-r--r-- | model/post.go | 5 | ||||
-rw-r--r-- | model/post_test.go | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/model/post.go b/model/post.go index e78469940..1fc5963c3 100644 --- a/model/post.go +++ b/model/post.go @@ -120,7 +120,10 @@ func (o *Post) PreSave() { o.OriginalId = "" - o.CreateAt = GetMillis() + if o.CreateAt == 0 { + o.CreateAt = GetMillis() + } + o.UpdateAt = o.CreateAt if o.Props == nil { diff --git a/model/post_test.go b/model/post_test.go index 38f4b4c98..a6b880fa0 100644 --- a/model/post_test.go +++ b/model/post_test.go @@ -83,5 +83,18 @@ func TestPostIsValid(t *testing.T) { func TestPostPreSave(t *testing.T) { o := Post{Message: "test"} o.PreSave() + + if o.CreateAt == 0 { + t.Fatal("should be set") + } + + past := GetMillis() - 1 + o = Post{Message: "test", CreateAt: past} + o.PreSave() + + if o.CreateAt > past { + t.Fatal("should not be updated") + } + o.Etag() } |