From 28835e58505ef26402d7fdfae13b15e9c03e0a22 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 22 Oct 2007 21:20:20 +0000 Subject: [PATCH] Strip newlines before comparing contents of a note to see if it's been altered. --- controller/Notebooks.py | 2 +- controller/test/Test_notebooks.py | 46 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/controller/Notebooks.py b/controller/Notebooks.py index c5e957b..5eba18b 100644 --- a/controller/Notebooks.py +++ b/controller/Notebooks.py @@ -360,7 +360,7 @@ class Notebooks( object ): # check whether the provided note contents have been changed since the previous revision def update_note( current_notebook, old_note, startup ): # the note hasn't been changed, so bail without updating it - if contents == old_note.contents and startup == old_note.startup: + if contents.replace( u"\n", u"" ) == old_note.contents.replace( u"\n", "" ) and startup == old_note.startup: new_revision = None # the note has changed, so update it else: diff --git a/controller/test/Test_notebooks.py b/controller/test/Test_notebooks.py index f1b3c15..e8adf4d 100644 --- a/controller/test/Test_notebooks.py +++ b/controller/test/Test_notebooks.py @@ -768,6 +768,52 @@ class Test_notebooks( Test_controller ): else: assert note.rank is None + def test_save_unchanged_note_with_extra_newline( self, startup = False ): + self.login() + + # save over an existing note, supplying new contents and a new title + previous_revision = self.note.revision + new_note_contents = u"

new title

new blah" + result = self.http_post( "/notebooks/save_note/", dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + contents = new_note_contents, + startup = startup, + previous_revision = previous_revision, + ), session_id = self.session_id ) + + # now attempt to save over that note again without changing the contents, + # except for adding a newline + user = self.database.load( User, self.user.object_id ) + previous_storage_bytes = user.storage_bytes + previous_revision = result[ "new_revision" ] + result = self.http_post( "/notebooks/save_note/", dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + contents = new_note_contents + u"\n", + startup = startup, + previous_revision = previous_revision, + ), session_id = self.session_id ) + + # assert that the note wasn't actually updated the second time + assert result[ "new_revision" ] == None + assert result[ "previous_revision" ] == previous_revision + user = self.database.load( User, self.user.object_id ) + assert user.storage_bytes == previous_storage_bytes + assert result[ "storage_bytes" ] == 0 + + result = self.http_post( "/notebooks/load_note_by_title/", dict( + notebook_id = self.notebook.object_id, + note_title = "new title", + ), session_id = self.session_id ) + + note = result[ "note" ] + assert note + assert note.object_id == self.note.object_id + assert note.title == "new title" + assert note.contents == new_note_contents + assert note.revision == previous_revision + def test_save_note_from_an_older_revision( self ): self.login()