Commit 4264663f authored by Robert Knight's avatar Robert Knight

Merge pull request #2754 from hypothesis/dont-save-null-data-to-draft-store

Don't save null permissions/tags/text to drafts store
parents eeace932 40e2b6f3
...@@ -241,11 +241,14 @@ AnnotationController = [ ...@@ -241,11 +241,14 @@ AnnotationController = [
# Drafts only preserve the text, tags and permissions of the annotation # Drafts only preserve the text, tags and permissions of the annotation
# (i.e. only the bits that the user can edit), changes to other # (i.e. only the bits that the user can edit), changes to other
# properties are not preserved. # properties are not preserved.
drafts.update(model, { changes = {}
text: draft.text if draft.text?
tags: draft.tags changes.text = draft.text
permissions: draft.permissions if draft.tags?
}) changes.tags = draft.tags
if draft.permissions?
changes.permissions = draft.permissions
drafts.update(model, changes)
###* ###*
# @ngdoc method # @ngdoc method
......
...@@ -540,11 +540,21 @@ describe 'annotation', -> ...@@ -540,11 +540,21 @@ describe 'annotation', ->
it "creates a draft when editing an annotation", -> it "creates a draft when editing an annotation", ->
createDirective() createDirective()
controller.edit() controller.edit()
assert.calledWith(fakeDrafts.update, annotation, { assert.calledWith(fakeDrafts.update, annotation)
text: annotation.text,
tags: annotation.tags, it "creates a draft with only editable fields which are non-null", ->
permissions: annotation.permissions # When a draft is saved, we shouldn't save any fields to the draft
}) # "changes" object that aren't actually set on the annotation. In this
# case, both permissions and tags are null so shouldn't be saved in the
# draft.
createDirective()
annotation.permissions = null
annotation.text = 'Hello!'
annotation.tags = null
controller.edit()
assert.calledWith(fakeDrafts.update, annotation, {text: 'Hello!'})
it "starts editing immediately if there is a draft", -> it "starts editing immediately if there is a draft", ->
fakeDrafts.get.returns({ fakeDrafts.get.returns({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment