Improve testing setup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
Rails.application.routes.draw do
|
||||
calligraphy_resource :test
|
||||
calligraphy_resource :webdav, resource_class: Calligraphy::FileResource, resource_root_path: File.expand_path('../../../../tmp/webdav', __FILE__)
|
||||
calligraphy_resource :webdav,
|
||||
resource_class: Calligraphy::FileResource,
|
||||
resource_root_path: File.expand_path('../../../../tmp/webdav', __FILE__)
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ require 'rspec/rails'
|
||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||
# require only the support files necessary.
|
||||
#
|
||||
Dir[Rails.root.join('../support/**/*.rb')].each { |f| require f }
|
||||
# Dir[Rails.root.join('../support/**/*.rb')].each { |f| require f }
|
||||
|
||||
# Checks for pending migrations and applies them before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove this line.
|
||||
@@ -57,3 +57,5 @@ RSpec.configure do |config|
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
end
|
||||
|
||||
require 'support/resource_helpers'
|
||||
|
||||
@@ -5,20 +5,19 @@ require 'support/request_helpers'
|
||||
require 'support/examples/ext_mkcol'
|
||||
|
||||
RSpec.describe 'mkcol', type: :request do
|
||||
before(:all) do
|
||||
tmp_dir = Rails.root.join('../../tmp').to_path
|
||||
Dir.mkdir tmp_dir unless File.exist? tmp_dir
|
||||
|
||||
webdav_dir = Rails.root.join('../../tmp/webdav').to_path
|
||||
FileUtils.rm_r webdav_dir if File.exist? webdav_dir
|
||||
Dir.mkdir webdav_dir
|
||||
before(:context) do
|
||||
Calligraphy::FileResource.setup
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Calligraphy).to receive(:enable_digest_authentication)
|
||||
.and_return(false)
|
||||
skip_authentication
|
||||
end
|
||||
|
||||
after(:context) do
|
||||
Calligraphy::FileResource.cleanup
|
||||
end
|
||||
|
||||
context "for #{Calligraphy::FileResource}" do
|
||||
it 'creates a collection with additional properties' do
|
||||
allow_any_instance_of(Calligraphy::FileResource).to receive(
|
||||
:valid_resourcetypes
|
||||
@@ -48,4 +47,5 @@ RSpec.describe 'mkcol', type: :request do
|
||||
expect(response.body).to include('valid-resourcetype')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,19 @@ require 'rails_helper'
|
||||
require 'support/request_helpers'
|
||||
|
||||
RSpec.describe 'OPTIONS', type: :request do
|
||||
before(:each) do
|
||||
allow(Calligraphy).to receive(:enable_digest_authentication)
|
||||
.and_return(false)
|
||||
before(:context) do
|
||||
Calligraphy::FileResource.setup
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
skip_authentication
|
||||
end
|
||||
|
||||
after(:context) do
|
||||
Calligraphy::FileResource.cleanup
|
||||
end
|
||||
|
||||
context "for #{Calligraphy::FileResource}" do
|
||||
context 'when not using extended MKCOL support' do
|
||||
before(:each) do
|
||||
allow_any_instance_of(Calligraphy::FileResource).to receive(
|
||||
@@ -48,4 +56,5 @@ RSpec.describe 'OPTIONS', type: :request do
|
||||
expect(response.headers['DAV']).to include('extended-mkcol')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,25 +6,22 @@ require 'support/examples/propfind'
|
||||
require 'support/examples/proppatch'
|
||||
|
||||
RSpec.describe 'PROPFIND', type: :request do
|
||||
before(:all) do
|
||||
tmp_dir = Rails.root.join('../../tmp').to_path
|
||||
Dir.mkdir tmp_dir unless File.exist? tmp_dir
|
||||
|
||||
webdav_dir = Rails.root.join('../../tmp/webdav').to_path
|
||||
FileUtils.rm_r webdav_dir if File.exist? webdav_dir
|
||||
Dir.mkdir webdav_dir
|
||||
before(:context) do
|
||||
Calligraphy::FileResource.setup
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Calligraphy).to receive(:enable_digest_authentication)
|
||||
.and_return(false)
|
||||
skip_authentication
|
||||
end
|
||||
|
||||
after(:context) do
|
||||
Calligraphy::FileResource.cleanup
|
||||
end
|
||||
|
||||
context 'with xml defintiion' do
|
||||
before(:each) do
|
||||
put '/webdav/bar.html', headers: {
|
||||
RAW_POST_DATA: 'hello world'
|
||||
}
|
||||
Calligraphy::FileResource.create resource: 'bar.html'
|
||||
|
||||
proppatch '/webdav/bar.html', headers: {
|
||||
RAW_POST_DATA: Support::Examples::Proppatch.rfc4918_9_2_2
|
||||
}
|
||||
|
||||
@@ -46,5 +46,19 @@ RSpec.describe 'Resource' do
|
||||
expect(resource.dav_compliance).to eq('1, 2, 3')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#enable_extended_mkcol?' do
|
||||
it 'is not enabled by default' do
|
||||
resource = Calligraphy::Resource.new
|
||||
expect(resource.enable_extended_mkcol?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#valid_resourcetypes' do
|
||||
it 'returns only a collection resourcetype by default' do
|
||||
resource = Calligraphy::Resource.new
|
||||
expect(resource.valid_resourcetypes).to match_array(['collection'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -113,5 +113,15 @@ RSpec.describe 'calligraphy_resource', type: :routing do
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'for HEAD requests' do
|
||||
it do
|
||||
expect(head: '/test/twelve').to route_to(
|
||||
controller: 'calligraphy/rails/web_dav_requests',
|
||||
action: 'invoke_method',
|
||||
resource: 'twelve'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,3 +15,7 @@ module ActionDispatch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def skip_authentication
|
||||
allow(Calligraphy).to receive(:enable_digest_authentication).and_return(false)
|
||||
end
|
||||
|
||||
49
spec/support/resource_helpers.rb
Normal file
49
spec/support/resource_helpers.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RESOURCES_TO_TEST_AGAINST = [
|
||||
Calligraphy::FileResource
|
||||
].freeze
|
||||
|
||||
module RSpecMethods
|
||||
def setup; end
|
||||
|
||||
def cleanup; end
|
||||
|
||||
def create(resource:, content: 'Hi hi!'); end
|
||||
end
|
||||
|
||||
module FileResourceHelpers
|
||||
def setup
|
||||
tmp_dir = Rails.root.join('../../tmp').to_path
|
||||
Dir.mkdir tmp_dir unless File.exist? tmp_dir
|
||||
|
||||
FileUtils.rm_r resource_root if File.exist? resource_root
|
||||
Dir.mkdir resource_root
|
||||
end
|
||||
|
||||
def cleanup
|
||||
FileUtils.rm_r resource_root if File.exist? resource_root
|
||||
end
|
||||
|
||||
def create(resource:, content: 'Hello world')
|
||||
resource = Calligraphy::FileResource.new(
|
||||
resource: resource,
|
||||
root_dir: resource_root
|
||||
)
|
||||
resource.write content
|
||||
end
|
||||
|
||||
def resource_root
|
||||
Rails.root.join('../../tmp/webdav').to_path
|
||||
end
|
||||
end
|
||||
|
||||
RESOURCES_TO_TEST_AGAINST.each do |resource_class|
|
||||
resource_class.send :extend, RSpecMethods
|
||||
end
|
||||
|
||||
module Calligraphy
|
||||
class FileResource
|
||||
extend FileResourceHelpers
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user