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 = [
# Drafts only preserve the text, tags and permissions of the annotation
# (i.e. only the bits that the user can edit), changes to other
# properties are not preserved.
drafts.update(model, {
text: draft.text
tags: draft.tags
permissions: draft.permissions
})
changes = {}
if draft.text?
changes.text = draft.text
if draft.tags?
changes.tags = draft.tags
if draft.permissions?
changes.permissions = draft.permissions
drafts.update(model, changes)
###*
# @ngdoc method
......
......@@ -540,11 +540,21 @@ describe 'annotation', ->
it "creates a draft when editing an annotation", ->
createDirective()
controller.edit()
assert.calledWith(fakeDrafts.update, annotation, {
text: annotation.text,
tags: annotation.tags,
permissions: annotation.permissions
})
assert.calledWith(fakeDrafts.update, annotation)
it "creates a draft with only editable fields which are non-null", ->
# 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", ->
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