Reorganize WebDavRequest and Resource classes
This commit is contained in:
@@ -10,17 +10,17 @@ require 'calligraphy/utils'
|
||||
require 'calligraphy/resource/resource'
|
||||
require 'calligraphy/resource/file_resource'
|
||||
|
||||
require 'calligraphy/web_dav_request'
|
||||
require 'calligraphy/copy'
|
||||
require 'calligraphy/delete'
|
||||
require 'calligraphy/get'
|
||||
require 'calligraphy/lock'
|
||||
require 'calligraphy/mkcol'
|
||||
require 'calligraphy/move'
|
||||
require 'calligraphy/propfind'
|
||||
require 'calligraphy/proppatch'
|
||||
require 'calligraphy/put'
|
||||
require 'calligraphy/unlock'
|
||||
require 'calligraphy/web_dav_request/web_dav_request'
|
||||
require 'calligraphy/web_dav_request/copy'
|
||||
require 'calligraphy/web_dav_request/delete'
|
||||
require 'calligraphy/web_dav_request/get'
|
||||
require 'calligraphy/web_dav_request/lock'
|
||||
require 'calligraphy/web_dav_request/mkcol'
|
||||
require 'calligraphy/web_dav_request/move'
|
||||
require 'calligraphy/web_dav_request/propfind'
|
||||
require 'calligraphy/web_dav_request/proppatch'
|
||||
require 'calligraphy/web_dav_request/put'
|
||||
require 'calligraphy/web_dav_request/unlock'
|
||||
|
||||
module Calligraphy
|
||||
# Constants used throughout Calligraphy.
|
||||
|
||||
@@ -421,17 +421,25 @@ module Calligraphy
|
||||
def get_property(prop)
|
||||
case prop.name
|
||||
when 'creationdate'
|
||||
prop.content = @stats[:created_at]
|
||||
prop.content = creationdate
|
||||
when 'displayname'
|
||||
prop.content = @name
|
||||
prop.content = displayname
|
||||
when 'getcontentlanguage'
|
||||
prop.content = getcontentlanguage
|
||||
when 'getcontentlength'
|
||||
prop.content = @stats[:size]
|
||||
prop.content = getcontentlength
|
||||
when 'getcontenttype'
|
||||
prop.content = getcontenttype
|
||||
when 'getetag'
|
||||
prop.content = getetag
|
||||
when 'getlastmodified'
|
||||
prop.content = @updated_at
|
||||
when 'resourcetype'
|
||||
prop.content = 'collection'
|
||||
prop.content = getlastmodified
|
||||
when 'lockdiscovery'
|
||||
return get_lock_info
|
||||
when 'resourcetype'
|
||||
prop.content = resourcetype
|
||||
when 'supportedlock'
|
||||
prop.content = supportedlock
|
||||
else
|
||||
return get_custom_property prop.name
|
||||
end
|
||||
@@ -439,6 +447,46 @@ module Calligraphy
|
||||
prop
|
||||
end
|
||||
|
||||
def creationdate
|
||||
@stats[:created_at]
|
||||
end
|
||||
|
||||
def displayname
|
||||
@name
|
||||
end
|
||||
|
||||
def getcontentlanguage
|
||||
nil
|
||||
end
|
||||
|
||||
def getcontentlength
|
||||
@stats[:size]
|
||||
end
|
||||
|
||||
def getcontenttype
|
||||
nil
|
||||
end
|
||||
|
||||
def getetag
|
||||
nil
|
||||
end
|
||||
|
||||
def getlastmodified
|
||||
@updated_at
|
||||
end
|
||||
|
||||
def lockdiscovery
|
||||
get_lock_info
|
||||
end
|
||||
|
||||
def resourcetype
|
||||
'collection'
|
||||
end
|
||||
|
||||
def supportedlock
|
||||
nil
|
||||
end
|
||||
|
||||
def get_custom_property(prop)
|
||||
@store_properties ||= @store.transaction(true) { @store[:properties] }
|
||||
@store_properties[prop.to_sym] unless @store_properties.nil? || prop.nil?
|
||||
|
||||
@@ -89,5 +89,51 @@ module Calligraphy
|
||||
def write(contents=@request_body.to_s)
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def creationdate
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def displayname
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def getcontentlanguage
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def getcontentlength
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def getcontenttype
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def getetag
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def getlastmodified
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def lockdiscovery
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def resourcetype
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def supportedlock
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def get_custom_property(prop)
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
33
spec/resource/resource_spec.rb
Normal file
33
spec/resource/resource_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Resource' do
|
||||
context 'base method' do
|
||||
resource_methods_without_inputs = %w(
|
||||
ancestor_exist? collection? create_collection delete_collection etag
|
||||
exists? lock_is_exclusive? lock_tokens locked? read readable? refresh_lock
|
||||
creationdate displayname getcontentlanguage getcontentlength getcontenttype
|
||||
getetag getlastmodified lockdiscovery resourcetype supportedlock
|
||||
)
|
||||
resource_methods_with_inputs = %w(
|
||||
can_copy? copy lock locked_to_user? propfind proppatch unlock write get_custom_property
|
||||
)
|
||||
|
||||
resource_methods_without_inputs.each do |method|
|
||||
describe "##{method}" do
|
||||
it 'raises NotImplementedError' do
|
||||
resource = Calligraphy::Resource.new
|
||||
expect{resource.send(method)}.to raise_exception(NotImplementedError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resource_methods_with_inputs.each do |method|
|
||||
describe "##{method}" do
|
||||
it 'raises NotImplementedError' do
|
||||
resource = Calligraphy::Resource.new
|
||||
expect{resource.send(method, nil)}.to raise_exception(NotImplementedError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user