From a8ac6185190722cca4a68c5ea553b013b00270c0 Mon Sep 17 00:00:00 2001 From: Brandon Robins Date: Sat, 23 Dec 2017 15:53:50 -0600 Subject: [PATCH] Reorganize WebDavRequest and Resource classes --- lib/calligraphy.rb | 22 +++---- lib/calligraphy/resource/file_resource.rb | 60 +++++++++++++++++-- lib/calligraphy/resource/resource.rb | 48 ++++++++++++++- lib/calligraphy/{ => web_dav_request}/copy.rb | 0 .../{ => web_dav_request}/delete.rb | 0 lib/calligraphy/{ => web_dav_request}/get.rb | 0 lib/calligraphy/{ => web_dav_request}/lock.rb | 0 .../{ => web_dav_request}/mkcol.rb | 0 lib/calligraphy/{ => web_dav_request}/move.rb | 0 .../{ => web_dav_request}/propfind.rb | 0 .../{ => web_dav_request}/proppatch.rb | 0 lib/calligraphy/{ => web_dav_request}/put.rb | 0 .../{ => web_dav_request}/unlock.rb | 0 .../{ => web_dav_request}/web_dav_request.rb | 0 spec/resource/resource_spec.rb | 33 ++++++++++ 15 files changed, 145 insertions(+), 18 deletions(-) rename lib/calligraphy/{ => web_dav_request}/copy.rb (100%) rename lib/calligraphy/{ => web_dav_request}/delete.rb (100%) rename lib/calligraphy/{ => web_dav_request}/get.rb (100%) rename lib/calligraphy/{ => web_dav_request}/lock.rb (100%) rename lib/calligraphy/{ => web_dav_request}/mkcol.rb (100%) rename lib/calligraphy/{ => web_dav_request}/move.rb (100%) rename lib/calligraphy/{ => web_dav_request}/propfind.rb (100%) rename lib/calligraphy/{ => web_dav_request}/proppatch.rb (100%) rename lib/calligraphy/{ => web_dav_request}/put.rb (100%) rename lib/calligraphy/{ => web_dav_request}/unlock.rb (100%) rename lib/calligraphy/{ => web_dav_request}/web_dav_request.rb (100%) create mode 100644 spec/resource/resource_spec.rb diff --git a/lib/calligraphy.rb b/lib/calligraphy.rb index 846c0d3..1658590 100644 --- a/lib/calligraphy.rb +++ b/lib/calligraphy.rb @@ -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. diff --git a/lib/calligraphy/resource/file_resource.rb b/lib/calligraphy/resource/file_resource.rb index cf9b67a..996805f 100644 --- a/lib/calligraphy/resource/file_resource.rb +++ b/lib/calligraphy/resource/file_resource.rb @@ -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? diff --git a/lib/calligraphy/resource/resource.rb b/lib/calligraphy/resource/resource.rb index 17a4b24..59681c0 100644 --- a/lib/calligraphy/resource/resource.rb +++ b/lib/calligraphy/resource/resource.rb @@ -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 diff --git a/lib/calligraphy/copy.rb b/lib/calligraphy/web_dav_request/copy.rb similarity index 100% rename from lib/calligraphy/copy.rb rename to lib/calligraphy/web_dav_request/copy.rb diff --git a/lib/calligraphy/delete.rb b/lib/calligraphy/web_dav_request/delete.rb similarity index 100% rename from lib/calligraphy/delete.rb rename to lib/calligraphy/web_dav_request/delete.rb diff --git a/lib/calligraphy/get.rb b/lib/calligraphy/web_dav_request/get.rb similarity index 100% rename from lib/calligraphy/get.rb rename to lib/calligraphy/web_dav_request/get.rb diff --git a/lib/calligraphy/lock.rb b/lib/calligraphy/web_dav_request/lock.rb similarity index 100% rename from lib/calligraphy/lock.rb rename to lib/calligraphy/web_dav_request/lock.rb diff --git a/lib/calligraphy/mkcol.rb b/lib/calligraphy/web_dav_request/mkcol.rb similarity index 100% rename from lib/calligraphy/mkcol.rb rename to lib/calligraphy/web_dav_request/mkcol.rb diff --git a/lib/calligraphy/move.rb b/lib/calligraphy/web_dav_request/move.rb similarity index 100% rename from lib/calligraphy/move.rb rename to lib/calligraphy/web_dav_request/move.rb diff --git a/lib/calligraphy/propfind.rb b/lib/calligraphy/web_dav_request/propfind.rb similarity index 100% rename from lib/calligraphy/propfind.rb rename to lib/calligraphy/web_dav_request/propfind.rb diff --git a/lib/calligraphy/proppatch.rb b/lib/calligraphy/web_dav_request/proppatch.rb similarity index 100% rename from lib/calligraphy/proppatch.rb rename to lib/calligraphy/web_dav_request/proppatch.rb diff --git a/lib/calligraphy/put.rb b/lib/calligraphy/web_dav_request/put.rb similarity index 100% rename from lib/calligraphy/put.rb rename to lib/calligraphy/web_dav_request/put.rb diff --git a/lib/calligraphy/unlock.rb b/lib/calligraphy/web_dav_request/unlock.rb similarity index 100% rename from lib/calligraphy/unlock.rb rename to lib/calligraphy/web_dav_request/unlock.rb diff --git a/lib/calligraphy/web_dav_request.rb b/lib/calligraphy/web_dav_request/web_dav_request.rb similarity index 100% rename from lib/calligraphy/web_dav_request.rb rename to lib/calligraphy/web_dav_request/web_dav_request.rb diff --git a/spec/resource/resource_spec.rb b/spec/resource/resource_spec.rb new file mode 100644 index 0000000..84cc30e --- /dev/null +++ b/spec/resource/resource_spec.rb @@ -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