From cd14a01490fe49d718156b92e79fba3406e20471 Mon Sep 17 00:00:00 2001 From: "COLA@Redmine.local" Date: Fri, 10 Feb 2017 21:29:37 +0100 Subject: [PATCH] Updated tests --- .../webdav/dmsf_webdav_move_test.rb | 43 ++++++++++++++++--- .../webdav/dmsf_webdav_put_test.rb | 5 +++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/test/integration/webdav/dmsf_webdav_move_test.rb b/test/integration/webdav/dmsf_webdav_move_test.rb index cb0c78d1..2aa781ae 100644 --- a/test/integration/webdav/dmsf_webdav_move_test.rb +++ b/test/integration/webdav/dmsf_webdav_move_test.rb @@ -233,7 +233,7 @@ class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest assert_response 201 # Created end - # Move twice + # Move twice, make sure that the MsOffice store sequence is not disrupting normal move new_name2 = "#{new_name}.m2" assert_difference 'file.dmsf_file_revisions.count', +1 do xml_http_request :move, "/dmsf/webdav/#{@project1.identifier}/#{new_name}", nil, @@ -242,7 +242,7 @@ class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest end end - def test_move_msoffice_save_file + def test_move_msoffice_save_locked_file # When some versions of MsOffice saves a file it use the following sequence: # 1. Save changes to a new temporary document, XXX.tmp # 2. Rename (MOVE) document to YYY.tmp. History is lost here if original document is moved. @@ -251,13 +251,19 @@ class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest # Verify that steps 2 and 3 works. original_file = DmsfFile.find_by_id 1 - temp_file_name = "ABCDEF.tmp" + + log_user 'jsmith', 'jsmith' # login as jsmith + assert !User.current.anonymous?, 'Current user is anonymous' + assert original_file.lock!, "File failed to be locked by #{User.current.name}" + # First save while file is locked, should create new revision + temp_file_name = "AAAAAAAA.tmp" + # Make sure that the temp-file does not exist. temp_file = DmsfFile.find_file_by_name @project1, nil, "#{temp_file_name}" assert !temp_file, "File '#{temp_file_name}' should not exist yet." - # Move the original file to ABCDEF.tmp. The original file should not change but a new file should be created. + # Move the original file to AAAAAAAA.tmp. The original file should not change but a new file should be created. assert_no_difference 'original_file.dmsf_file_revisions.count' do xml_http_request :move, "/dmsf/webdav/#{@project1.identifier}/#{original_file.name}", nil, @jsmith.merge!({:destination => "http://www.example.com/dmsf/webdav/#{@project1.identifier}/#{temp_file_name}"}) @@ -270,12 +276,39 @@ class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest assert_equal temp_file.dmsf_file_revisions.count,1 assert_not_equal temp_file.id, original_file.id - # Move a temporary file (use ABCDEF.tmp) to the original file. + # Move a temporary file (use AAAAAAAA.tmp) to the original file. assert_difference 'original_file.dmsf_file_revisions.count', +1 do xml_http_request :move, "/dmsf/webdav/#{@project1.identifier}/#{temp_file_name}", nil, @jsmith.merge!({:destination => "http://www.example.com/dmsf/webdav/#{@project1.identifier}/#{original_file.name}"}) assert_response 201 # Created end + + # Second save while file is locked, should NOT create new revision + temp_file_name = "BBBBBBBB.tmp" + + # Make sure that the temp-file does not exist. + temp_file = DmsfFile.find_file_by_name @project1, nil, "#{temp_file_name}" + assert !temp_file, "File '#{temp_file_name}' should not exist yet." + + # Move the original file to BBBBBBBB.tmp. The original file should not change but a new file should be created. + assert_no_difference 'original_file.dmsf_file_revisions.count' do + xml_http_request :move, "/dmsf/webdav/#{@project1.identifier}/#{original_file.name}", nil, + @jsmith.merge!({:destination => "http://www.example.com/dmsf/webdav/#{@project1.identifier}/#{temp_file_name}"}) + assert_response 201 # Created + end + + # Verify that a new file acutally has been created + temp_file = DmsfFile.find_file_by_name @project1, nil, "#{temp_file_name}" + assert temp_file, "File '#{temp_file_name}' not found, move failed." + assert_equal temp_file.dmsf_file_revisions.count,1 + assert_not_equal temp_file.id, original_file.id + + # Move a temporary file (use BBBBBBBB.tmp) to the original file. + assert_no_difference 'original_file.dmsf_file_revisions.count' do + xml_http_request :move, "/dmsf/webdav/#{@project1.identifier}/#{temp_file_name}", nil, + @jsmith.merge!({:destination => "http://www.example.com/dmsf/webdav/#{@project1.identifier}/#{original_file.name}"}) + assert_response 201 # Created + end end end \ No newline at end of file diff --git a/test/integration/webdav/dmsf_webdav_put_test.rb b/test/integration/webdav/dmsf_webdav_put_test.rb index 20073b86..f3eb8206 100644 --- a/test/integration/webdav/dmsf_webdav_put_test.rb +++ b/test/integration/webdav/dmsf_webdav_put_test.rb @@ -204,6 +204,11 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text}) assert_response :success # 201 - Created end + # Second PUT on a locked file should only update the revision that were created on the first PUT + assert_no_difference 'file.dmsf_file_revisions.count' do + put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text}) + assert_response :success # 201 - Created + end end end