redmine_dmsf/test/unit/dmsf_lock_test.rb
Daniel Munn 6237e09581 New: Support for lockdiscover and supported lock PROPFIND requests
Update: file_revision visible scope now is joined with parent item and checked for both revision and file visibility
New: Projects now store into their own folder within configured path
Fix: db upgrade script does a one-time re-sort of existing physical data to ensure it can be read in new world
Fix: webdav controller (from Gem) did not flag output as utf-8 with correct header, overloaded in dmsf controller instance to fix
Update: Testsuites updated to support a few more conditions for lock processing
2012-06-28 14:29:13 +01:00

129 lines
3.6 KiB
Ruby

require File.expand_path('../../test_helper.rb', __FILE__)
class DmsfFileTest < RedmineDmsf::Test::UnitTest
attr_reader :lock
fixtures :projects, :users, :dmsf_folders, :dmsf_files, :dmsf_file_revisions,
:roles, :members, :member_roles, :enabled_modules, :enumerations,
:dmsf_locks
def setup
@lock = dmsf_locks(:dmsf_locks_001)
end
test "lock data is created" do
assert_not_nil(lock)
end
test "lock_type is enumerable" do
assert DmsfLock.respond_to?(:lock_types) #lock_types is a method created by as_enum
assert DmsfLock.lock_types.is_a?(Hash)
end
test "lock_scope is enumerable" do
assert DmsfLock.respond_to?(:lock_scopes) #lock_types is a method created by as_enum
assert DmsfLock.lock_scopes.is_a?(Hash)
end
test "lock_type does not accept invalid values" do
assert lock.lock_type = :type_write
assert_raise ArgumentError do
assert lock.lock_type = :write
end
end
test "lock_type accepts a valid answer" do
assert_nothing_raised ArgumentError do
lock.lock_type = :type_write
assert lock.lock_type == :type_write
end
end
test "lock_scope does not accept invalid values" do
assert lock.lock_scope = :scope_exclusive
assert_raise ArgumentError do
assert lock.lock_scope = :write
end
end
test "lock_scope accepts a valid answer" do
assert_nothing_raised ArgumentError do
lock.lock_scope = :scope_shared
assert lock.lock_scope == :scope_shared
end
end
test "linked to either file or folder" do
assert !(lock.file.nil? && lock.folder.nil?)
assert !lock.file.nil? || !lock.folder.nil?
if !lock.file.nil?
assert lock.file.is_a?(DmsfFile)
else
assert lock.file.is_a?(DmsfFolder)
end
end
test "locked folder reports un-locked child file as locked" do
#folder id 2 is locked by fixture
#files 4 and 5 are file resources within locked folder (declared by fixture)
folder = dmsf_folders(:dmsf_folders_002)
file = dmsf_files(:dmsf_files_004)
assert folder.locked?, "Folder (2) should be locked by fixture"
assert_equal 1, folder.lock.count #Check the folder lists 1 lock
assert file.locked?, "File (4) sits within Folder(2) and should be locked"
assert_equal 1, file.lock.count #Check the file lists 1 lock
assert_equal 0, file.lock(false).count #Check the file does not list any entries for itself
end
test "locked folder cannot be unlocked by someone without rights (or anon)" do
folder = dmsf_folders(:dmsf_folders_002)
assert_no_difference ('folder.lock.count') do
assert_raise DmsfLockError do
folder.unlock!
end
end
User.current = users(:users_002)
assert_no_difference ('folder.lock.count') do
assert_raise DmsfLockError do
folder.unlock!
end
end
end
test "locked folder can be unlocked by permission :force_file_unlock" do
User.current = users(:users_001)
folder = dmsf_folders(:dmsf_folders_002)
assert_difference('folder.lock.count', -1) do
assert_nothing_raised do
folder.unlock!
end
end
User.current = users(:users_002)
assert_difference('folder.lock.count') do
assert_nothing_raised do
folder.lock!
end
end
User.current = users(:users_001)
assert_difference('folder.lock.count', -1) do
assert_nothing_raised do
folder.unlock!
end
end
#We need to re-establish locks for other test
folder.lock!
User.current = nil
end
end