Reorganize WebDavRequest and Resource classes

This commit is contained in:
Brandon Robins
2017-12-23 15:53:50 -06:00
parent 9dff70a3c0
commit a8ac618519
15 changed files with 145 additions and 18 deletions

View File

@@ -10,17 +10,17 @@ require 'calligraphy/utils'
require 'calligraphy/resource/resource' require 'calligraphy/resource/resource'
require 'calligraphy/resource/file_resource' require 'calligraphy/resource/file_resource'
require 'calligraphy/web_dav_request' require 'calligraphy/web_dav_request/web_dav_request'
require 'calligraphy/copy' require 'calligraphy/web_dav_request/copy'
require 'calligraphy/delete' require 'calligraphy/web_dav_request/delete'
require 'calligraphy/get' require 'calligraphy/web_dav_request/get'
require 'calligraphy/lock' require 'calligraphy/web_dav_request/lock'
require 'calligraphy/mkcol' require 'calligraphy/web_dav_request/mkcol'
require 'calligraphy/move' require 'calligraphy/web_dav_request/move'
require 'calligraphy/propfind' require 'calligraphy/web_dav_request/propfind'
require 'calligraphy/proppatch' require 'calligraphy/web_dav_request/proppatch'
require 'calligraphy/put' require 'calligraphy/web_dav_request/put'
require 'calligraphy/unlock' require 'calligraphy/web_dav_request/unlock'
module Calligraphy module Calligraphy
# Constants used throughout Calligraphy. # Constants used throughout Calligraphy.

View File

@@ -421,17 +421,25 @@ module Calligraphy
def get_property(prop) def get_property(prop)
case prop.name case prop.name
when 'creationdate' when 'creationdate'
prop.content = @stats[:created_at] prop.content = creationdate
when 'displayname' when 'displayname'
prop.content = @name prop.content = displayname
when 'getcontentlanguage'
prop.content = getcontentlanguage
when 'getcontentlength' when 'getcontentlength'
prop.content = @stats[:size] prop.content = getcontentlength
when 'getcontenttype'
prop.content = getcontenttype
when 'getetag'
prop.content = getetag
when 'getlastmodified' when 'getlastmodified'
prop.content = @updated_at prop.content = getlastmodified
when 'resourcetype'
prop.content = 'collection'
when 'lockdiscovery' when 'lockdiscovery'
return get_lock_info return get_lock_info
when 'resourcetype'
prop.content = resourcetype
when 'supportedlock'
prop.content = supportedlock
else else
return get_custom_property prop.name return get_custom_property prop.name
end end
@@ -439,6 +447,46 @@ module Calligraphy
prop prop
end 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) def get_custom_property(prop)
@store_properties ||= @store.transaction(true) { @store[:properties] } @store_properties ||= @store.transaction(true) { @store[:properties] }
@store_properties[prop.to_sym] unless @store_properties.nil? || prop.nil? @store_properties[prop.to_sym] unless @store_properties.nil? || prop.nil?

View File

@@ -89,5 +89,51 @@ module Calligraphy
def write(contents=@request_body.to_s) def write(contents=@request_body.to_s)
raise NotImplementedError raise NotImplementedError
end 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 end

View 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