bcms_webdav 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GPL.txt +674 -0
- data/Gemfile +9 -0
- data/README.rdoc +18 -20
- data/app/assets/javascripts/application.js +15 -0
- data/app/assets/javascripts/bcms_webdav/application.js +15 -0
- data/app/assets/stylesheets/application.css +13 -0
- data/app/assets/stylesheets/bcms_webdav/application.css +13 -0
- data/app/controllers/bcms_webdav/application_controller.rb +4 -0
- data/app/helpers/bcms_webdav/application_helper.rb +4 -0
- data/config/routes.rb +2 -0
- data/lib/bcms_webdav.rb +5 -3
- data/lib/bcms_webdav/bcms_attachment_extensions.rb +25 -6
- data/lib/bcms_webdav/engine.rb +16 -0
- data/lib/bcms_webdav/file.rb +11 -16
- data/lib/bcms_webdav/resource.rb +67 -61
- data/lib/bcms_webdav/version.rb +3 -0
- data/lib/bcms_webdav/web_dav_middleware.rb +1 -1
- data/lib/generators/bcms_webdav/install/USAGE +3 -0
- data/lib/generators/bcms_webdav/install/install_generator.rb +20 -0
- data/lib/tasks/bcms_webdav_tasks.rake +4 -0
- metadata +77 -86
- data/Rakefile +0 -10
- data/VERSION +0 -1
- data/doc/README_FOR_APP +0 -2
- data/lib/bcms_webdav/routes.rb +0 -7
- data/lib/tasks/jeweler.rake +0 -34
- data/public/bcms/webdav/README +0 -1
- data/rails/init.rb +0 -4
- data/test/performance/browsing_test.rb +0 -9
- data/test/test_helper.rb +0 -46
- data/test/unit/attachment_test.rb +0 -17
- data/test/unit/web_dav_middleware_test.rb +0 -50
- data/test/unit/web_dav_resource_test.rb +0 -331
@@ -6,7 +6,7 @@ module Bcms
|
|
6
6
|
|
7
7
|
def initialize(app, options={})
|
8
8
|
@app = app
|
9
|
-
@dav4rack = DAV4Rack::Handler.new(:root => Rails.root.to_s, :root_uri_path => '/', :log_to => [
|
9
|
+
@dav4rack = DAV4Rack::Handler.new(:root => Rails.root.to_s, :root_uri_path => '/', :log_to => ["#{Rails.root}/log/webdav.log", Logger::DEBUG], :resource_class=>Bcms::WebDAV::Resource)
|
10
10
|
@options = options
|
11
11
|
|
12
12
|
unless @options[:subdomain]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'cms/module_installation'
|
2
|
+
|
3
|
+
class BcmsWebdav::InstallGenerator < Cms::ModuleInstallation
|
4
|
+
# add_migrations_directory_to_source_root __FILE__
|
5
|
+
|
6
|
+
# def copy_migrations
|
7
|
+
# rake 'bcms_webdav:install:migrations'
|
8
|
+
# end
|
9
|
+
|
10
|
+
# Uncomment to add module specific seed data to a project.
|
11
|
+
#def add_seed_data_to_project
|
12
|
+
# copy_file "../bcms_webdav.seeds.rb", "db/bcms_webdav.seeds.rb"
|
13
|
+
# append_to_file "db/seeds.rb", "load File.expand_path('../bcms_webdav.seeds.rb', __FILE__)\n"
|
14
|
+
#end
|
15
|
+
|
16
|
+
def add_routes
|
17
|
+
mount_engine(BcmsWebdav)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,121 +1,112 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcms_webdav
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 1.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- BrowserMedia
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: browsercms
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
version: "3.1"
|
18
|
+
requirements:
|
19
|
+
- - <
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.6.0
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.5.0
|
34
25
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: dav4rack
|
38
26
|
prerelease: false
|
39
|
-
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.6.0
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.5.0
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: dav4rack
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 21
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 2
|
48
|
-
- 1
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
49
43
|
version: 0.2.1
|
50
44
|
type: :runtime
|
51
|
-
|
52
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ~>
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 0.2.1
|
52
|
+
description: Turns a BrowserCMS site into a WebDAV server, allowing access for bulk
|
53
|
+
uploading files.
|
53
54
|
email: github@browsermedia.com
|
54
55
|
executables: []
|
55
|
-
|
56
56
|
extensions: []
|
57
|
-
|
58
|
-
extra_rdoc_files:
|
59
|
-
- LICENSE.txt
|
57
|
+
extra_rdoc_files:
|
60
58
|
- README.rdoc
|
61
|
-
files:
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
59
|
+
files:
|
60
|
+
- app/assets/javascripts/application.js
|
61
|
+
- app/assets/javascripts/bcms_webdav/application.js
|
62
|
+
- app/assets/stylesheets/application.css
|
63
|
+
- app/assets/stylesheets/bcms_webdav/application.css
|
64
|
+
- app/controllers/bcms_webdav/application_controller.rb
|
65
|
+
- app/helpers/bcms_webdav/application_helper.rb
|
66
|
+
- config/routes.rb
|
69
67
|
- lib/bcms_webdav/bcms_attachment_extensions.rb
|
68
|
+
- lib/bcms_webdav/engine.rb
|
70
69
|
- lib/bcms_webdav/file.rb
|
71
70
|
- lib/bcms_webdav/resource.rb
|
72
|
-
- lib/bcms_webdav/
|
71
|
+
- lib/bcms_webdav/version.rb
|
73
72
|
- lib/bcms_webdav/web_dav_middleware.rb
|
74
|
-
- lib/
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
|
73
|
+
- lib/bcms_webdav.rb
|
74
|
+
- lib/generators/bcms_webdav/install/install_generator.rb
|
75
|
+
- lib/generators/bcms_webdav/install/USAGE
|
76
|
+
- lib/tasks/bcms_webdav_tasks.rake
|
77
|
+
- README.rdoc
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- COPYRIGHT.txt
|
81
|
+
- GPL.txt
|
83
82
|
homepage: https://github.com/browsermedia/bcms_webdav
|
84
83
|
licenses: []
|
85
|
-
|
86
84
|
post_install_message:
|
87
85
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
86
|
+
require_paths:
|
90
87
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
89
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
segments:
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
98
95
|
- 0
|
99
|
-
|
100
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
hash: -1499320235108322808
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
98
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
segments:
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
107
104
|
- 0
|
108
|
-
|
105
|
+
hash: -1499320235108322808
|
109
106
|
requirements: []
|
110
|
-
|
111
107
|
rubyforge_project: browsercms
|
112
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.8.24
|
113
109
|
signing_key:
|
114
110
|
specification_version: 3
|
115
111
|
summary: A BrowserCMS module for WebDAV
|
116
|
-
test_files:
|
117
|
-
- test/performance/browsing_test.rb
|
118
|
-
- test/test_helper.rb
|
119
|
-
- test/unit/attachment_test.rb
|
120
|
-
- test/unit/web_dav_middleware_test.rb
|
121
|
-
- test/unit/web_dav_resource_test.rb
|
112
|
+
test_files: []
|
data/Rakefile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
-
|
4
|
-
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
-
|
6
|
-
require 'rake'
|
7
|
-
require 'rake/testtask'
|
8
|
-
require 'rake/rdoctask'
|
9
|
-
|
10
|
-
require 'tasks/rails'
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.4
|
data/doc/README_FOR_APP
DELETED
data/lib/bcms_webdav/routes.rb
DELETED
data/lib/tasks/jeweler.rake
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'jeweler'
|
3
|
-
Jeweler::Tasks.new do |gemspec|
|
4
|
-
gemspec.name = "bcms_webdav"
|
5
|
-
gemspec.rubyforge_project = "browsercms"
|
6
|
-
gemspec.summary = "A BrowserCMS module for WebDAV"
|
7
|
-
gemspec.email = "github@browsermedia.com"
|
8
|
-
gemspec.homepage = "https://github.com/browsermedia/bcms_webdav"
|
9
|
-
gemspec.description = "Turns a BrowserCMS site into a WebDAV server, allowing access for bulk uploading files."
|
10
|
-
gemspec.authors = ["BrowserMedia"]
|
11
|
-
gemspec.files = []
|
12
|
-
gemspec.files += Dir["app/**/*"]
|
13
|
-
gemspec.files -= Dir["app/views/layouts/templates/*"]
|
14
|
-
gemspec.files -= Dir["app/controllers/application_controller.rb"]
|
15
|
-
gemspec.files -= Dir["app/helpers/application_helper.rb"]
|
16
|
-
gemspec.files += Dir["doc/**/*"]
|
17
|
-
gemspec.files += Dir["db/migrate/[0-9]*.rb"].reject {|f| f =~ /_browsercms|_load_seed/ }
|
18
|
-
gemspec.files += Dir["lib/**/*"]
|
19
|
-
gemspec.files -= Dir["lib/task/jeweler.rake"]
|
20
|
-
gemspec.files += Dir["rails/init.rb"]
|
21
|
-
gemspec.files += Dir["public/bcms/webdav/**/*"]
|
22
|
-
gemspec.files += Dir["README.rdoc"]
|
23
|
-
gemspec.files += Dir["Rakefile"]
|
24
|
-
gemspec.files += Dir["LICENSE.txt"]
|
25
|
-
gemspec.files += Dir["COPYRIGHT.txt"]
|
26
|
-
gemspec.files += Dir["VERSION"]
|
27
|
-
gemspec.add_dependency('browsercms', '>=3.1')
|
28
|
-
gemspec.add_dependency('dav4rack', '>=0.2.1')
|
29
|
-
end
|
30
|
-
rescue LoadError
|
31
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
32
|
-
end
|
33
|
-
|
34
|
-
Jeweler::GemcutterTasks.new
|
data/public/bcms/webdav/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Use this directory to add public files that should copied from the gem into the project.
|
data/rails/init.rb
DELETED
data/test/test_helper.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
-
require 'test_help'
|
4
|
-
|
5
|
-
class ActiveSupport::TestCase
|
6
|
-
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
-
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
-
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
-
# between every test method. Fewer database queries means faster tests.
|
10
|
-
#
|
11
|
-
# Read Mike Clark's excellent walkthrough at
|
12
|
-
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
-
#
|
14
|
-
# Every Active Record database supports transactions except MyISAM tables
|
15
|
-
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
-
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
-
# is recommended.
|
18
|
-
#
|
19
|
-
# The only drawback to using transactional fixtures is when you actually
|
20
|
-
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
-
# any transactions started in your code will be automatically rolled back.
|
22
|
-
self.use_transactional_fixtures = true
|
23
|
-
|
24
|
-
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
-
# would need people(:david). If you don't want to migrate your existing
|
26
|
-
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
-
# instantiated fixtures translates to a database query per test method),
|
28
|
-
# then set this back to true.
|
29
|
-
self.use_instantiated_fixtures = false
|
30
|
-
|
31
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
-
#
|
33
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
-
# -- they do not yet inherit this setting
|
35
|
-
fixtures :all
|
36
|
-
|
37
|
-
# Add more helper methods to be used by all tests here...
|
38
|
-
end
|
39
|
-
|
40
|
-
def file_upload_object(options)
|
41
|
-
file = ActionController::UploadedTempfile.new(options[:original_filename])
|
42
|
-
open(file.path, 'w') { |f| f << options[:read] }
|
43
|
-
file.original_path = options[:original_filename]
|
44
|
-
file.content_type = options[:content_type]
|
45
|
-
file
|
46
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class AttachmentTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
test "Attachment should respond to 'path' just like pages and sections." do
|
14
|
-
a = Attachment.new(:file_path=>"/test.jpg")
|
15
|
-
assert_equal "/test.jpg", a.path
|
16
|
-
end
|
17
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class WebDavMiddlewareTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@webdav = Bcms::WebDavMiddleware.new(nil)
|
9
|
-
@request = mock()
|
10
|
-
@path = '/public'
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
test "subdomain is_webdav too" do
|
18
|
-
@request.expects(:host).returns("webdav.example.com")
|
19
|
-
assert_equal true, @webdav.send(:is_webdav?, @request)
|
20
|
-
|
21
|
-
@request.expects(:host).returns("webdav.localhost")
|
22
|
-
assert_equal true, @webdav.send(:is_webdav?, @request)
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
test "non-subdomain is_webdav too" do
|
27
|
-
@request.expects(:host).returns("localhost")
|
28
|
-
assert_equal false, @webdav.send(:is_webdav?, @request)
|
29
|
-
|
30
|
-
@request.expects(:host).returns("www.webdav.example.com")
|
31
|
-
assert_equal false, @webdav.send(:is_webdav?, @request)
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
test "can configure different subdomain for webdav" do
|
36
|
-
webdav = Bcms::WebDavMiddleware.new(nil, {:subdomain=>"dav"})
|
37
|
-
|
38
|
-
@request.expects(:host).returns("dav.example.com")
|
39
|
-
assert_equal true, webdav.send(:is_webdav?, @request)
|
40
|
-
|
41
|
-
@request.expects(:host).returns("webdav.example.com")
|
42
|
-
assert_equal false, webdav.send(:is_webdav?, @request)
|
43
|
-
end
|
44
|
-
|
45
|
-
test "Setting up to use a port for detection for webdav requests" do
|
46
|
-
webdav = Bcms::WebDavMiddleware.new(nil, {:port=>3000})
|
47
|
-
@request.expects(:port).returns(3000)
|
48
|
-
assert_equal true, webdav.send(:is_webdav?, @request)
|
49
|
-
end
|
50
|
-
end
|
@@ -1,331 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class WebDavSectionResourceTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@request = stub()
|
8
|
-
@request.expects(:ip).returns('').at_least_once
|
9
|
-
@about_us = Section.create!(:name=>"About Us", :path=>"/about-us", :parent=>Section.root.first)
|
10
|
-
@resource = resource_for("/about-us")
|
11
|
-
@resource.exist?
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
test 'users with administrate permissions can access resources' do
|
20
|
-
mock_user = mock()
|
21
|
-
User.expects(:authenticate).with("abc", "123").returns(mock_user)
|
22
|
-
mock_user.expects(:able_to?).with(:administrate).returns(true)
|
23
|
-
|
24
|
-
assert_equal true, @resource.authenticate("abc", "123")
|
25
|
-
end
|
26
|
-
|
27
|
-
test "users without administrate can't access resources" do
|
28
|
-
mock_user = mock()
|
29
|
-
User.expects(:authenticate).with("abc", "123").returns(mock_user)
|
30
|
-
mock_user.expects(:able_to?).with(:administrate).returns(false)
|
31
|
-
|
32
|
-
assert_equal false, @resource.authenticate("abc", "123")
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
test "need a user account to access resource" do
|
37
|
-
mock_user = mock()
|
38
|
-
User.expects(:authenticate).with("abc", "123").returns(nil)
|
39
|
-
|
40
|
-
assert_equal false, @resource.authenticate("abc", "123")
|
41
|
-
end
|
42
|
-
|
43
|
-
test "convert webdav paths to cms paths" do
|
44
|
-
assert_equal "/", Bcms::WebDAV::Resource.normalize_path("/")
|
45
|
-
assert_equal "/", Bcms::WebDAV::Resource.normalize_path("")
|
46
|
-
assert_equal "/about-us", Bcms::WebDAV::Resource.normalize_path("/about-us/"), "Remove trailing slashes, which CMS paths don't have"
|
47
|
-
assert_equal "/about-us", Bcms::WebDAV::Resource.normalize_path("about-us/"), "Add starting slashes, which all CMS paths do have."
|
48
|
-
end
|
49
|
-
|
50
|
-
test "root path exists" do
|
51
|
-
root_section = Section.create!(:name=>"My Site", :path=>"/", :root=>true)
|
52
|
-
|
53
|
-
assert_not_nil Section.root.first, "Ensure the root section exists in the database"
|
54
|
-
assert_equal true, resource_for("/").exist?
|
55
|
-
assert_equal true, resource_for("").exist?, "WebDAV treats paths of '/' and '' as the root"
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
test "find subsection" do
|
60
|
-
contact_us = Section.create!(:name=>"Contact us", :path=>"/about-us/contact-us", :parent=>@about_us)
|
61
|
-
cu = resource_for("/about-us/contact-us")
|
62
|
-
assert_equal true, cu.exist?
|
63
|
-
end
|
64
|
-
|
65
|
-
test "find section with no leading slash" do
|
66
|
-
assert_equal true, resource_for("about-us/").exist?, "WebDAV seems to request subpaths (to collections) with no leading slash, plus a trailing slash"
|
67
|
-
end
|
68
|
-
|
69
|
-
test "exist?" do
|
70
|
-
resource = resource_for("/about-us")
|
71
|
-
assert_equal true, resource.exist?
|
72
|
-
end
|
73
|
-
|
74
|
-
test "exist? fails if section is missing" do
|
75
|
-
resource = resource_for("/not-about-us")
|
76
|
-
assert_equal false, resource.exist?
|
77
|
-
end
|
78
|
-
|
79
|
-
test "children returns all sections and pages" do
|
80
|
-
child_section = Section.create!(:name=>"Child 1", :path=>"/about-us/child1", :parent=>@about_us)
|
81
|
-
child_page = Page.create!(:name=>"Child 2", :path=>"/about-us/child2", :section=>@about_us)
|
82
|
-
resource = resource_for("/about-us")
|
83
|
-
children = resource.children
|
84
|
-
assert_equal 2, children.size
|
85
|
-
assert_equal "/about-us/child1", children[0].public_path
|
86
|
-
assert_equal "/about-us/child2", children[1].public_path
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
test "propfind ensures all resources are initialized when getting properties" do
|
91
|
-
child_section = Section.create!(:name=>"Child 1", :path=>"/about-us/child1", :parent=>@about_us)
|
92
|
-
child_page = Page.create!(:name=>"Child 2", :path=>"/about-us/child2", :section=>@about_us)
|
93
|
-
resource = resource_for("/about-us")
|
94
|
-
children = resource.children
|
95
|
-
|
96
|
-
assert_about_same_time child_section.created_at, children[0].creation_date
|
97
|
-
assert_about_same_time child_page.created_at, children[1].creation_date
|
98
|
-
end
|
99
|
-
|
100
|
-
def assert_about_same_time(expected, actual)
|
101
|
-
assert expected - actual <= 100, "Ensure the times are close"
|
102
|
-
end
|
103
|
-
test "creation_date" do
|
104
|
-
resource = resource_for("/about-us")
|
105
|
-
resource.exist?
|
106
|
-
assert @about_us.created_at - resource.creation_date <= 100, "Ensure the times are close"
|
107
|
-
end
|
108
|
-
|
109
|
-
test "last_modified" do
|
110
|
-
resource = resource_for("/about-us")
|
111
|
-
assert @about_us.updated_at - resource.last_modified <= 100, "Ensure the times are close"
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
test "etag is implemented in some vaguely terrible way" do
|
116
|
-
|
117
|
-
# Note: There is no particular logic to this etag, just trying to make it unique
|
118
|
-
assert_not_nil @resource.etag
|
119
|
-
end
|
120
|
-
|
121
|
-
test "sections are collections" do
|
122
|
-
assert(@resource.collection?)
|
123
|
-
end
|
124
|
-
|
125
|
-
test "sections are text/html" do
|
126
|
-
assert_equal "text/html", @resource.content_type
|
127
|
-
end
|
128
|
-
|
129
|
-
test "sections have 0 content_length" do
|
130
|
-
assert_equal 0, @resource.content_length
|
131
|
-
end
|
132
|
-
|
133
|
-
test "links should not appear in the list, and should not be considered as resources" do
|
134
|
-
|
135
|
-
link = Link.new(:name=>'A', :url=>"www.google.com")
|
136
|
-
link.section = @about_us
|
137
|
-
|
138
|
-
|
139
|
-
assert_equal @about_us.id, link.section_id
|
140
|
-
assert_equal @about_us, link.section_node.section
|
141
|
-
assert_equal @about_us.id, link.section_node.section_id
|
142
|
-
link.save!
|
143
|
-
|
144
|
-
@resource = resource_for("/about-us")
|
145
|
-
assert_equal true, @resource.exist?
|
146
|
-
assert_equal 0, @resource.children.size
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
test "Section_nodes will nil values shouldn't throw errors" do
|
151
|
-
|
152
|
-
assert_equal nil, @resource.send(:child_node, SectionNode.new(:section=>@about_us, :node=>nil))
|
153
|
-
end
|
154
|
-
|
155
|
-
private
|
156
|
-
|
157
|
-
def resource_for(path)
|
158
|
-
Bcms::WebDAV::Resource.new(path, path, @request, Rack::MockResponse.new(200, {}, []), {})
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
class PageResourceTest < ActiveSupport::TestCase
|
165
|
-
def setup
|
166
|
-
@request = stub()
|
167
|
-
@request.expects(:ip).returns('').at_least_once
|
168
|
-
@about_us = Section.create!(:name=>"About Us", :path=>"/about-us", :parent=>Section.root.first)
|
169
|
-
@contact_us = Page.create!(:name=>"Contact Us", :path=>"/about-us/contact_us", :section=>@about_us)
|
170
|
-
@resource = resource_for("/about-us/contact_us")
|
171
|
-
@resource.exist?
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
test "exists" do
|
176
|
-
assert_equal true, @resource.exist?
|
177
|
-
end
|
178
|
-
|
179
|
-
test "creation_date" do
|
180
|
-
assert @contact_us.created_at - @resource.creation_date <= 100, "Ensure the times are close"
|
181
|
-
end
|
182
|
-
|
183
|
-
test "last_modified" do
|
184
|
-
assert @contact_us.updated_at - @resource.last_modified <= 100, "Ensure the times are close"
|
185
|
-
end
|
186
|
-
|
187
|
-
test "pages are not collections" do
|
188
|
-
assert_equal false, @resource.collection?
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
private
|
193
|
-
def resource_for(path)
|
194
|
-
Bcms::WebDAV::Resource.new(path, path, @request, Rack::MockResponse.new(200, {}, []), {})
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
class FileResourceTest < ActiveSupport::TestCase
|
199
|
-
def setup
|
200
|
-
@request = stub()
|
201
|
-
@request.expects(:ip).returns('').at_least_once
|
202
|
-
|
203
|
-
@response = Rack::MockResponse.new(200, {}, [])
|
204
|
-
@about_us = Section.create!(:name=>"About Us", :path=>"/about-us", :parent=>Section.root.first)
|
205
|
-
|
206
|
-
@file = file_upload_object(:original_filename => "test.jpg",
|
207
|
-
:content_type => "image/jpeg", :rewind => true,
|
208
|
-
:size => "99", :read => "01010010101010101")
|
209
|
-
@file_block = FileBlock.create!(:name=>"Testing", :attachment_file => @file, :attachment_section => @about_us, :attachment_file_path => "/about-us/test.jpg", :publish_on_save => true)
|
210
|
-
|
211
|
-
@resource = resource_for("/about-us/test.jpg")
|
212
|
-
@resource.exist?
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
test "exists" do
|
217
|
-
assert_equal true, @resource.exist?
|
218
|
-
end
|
219
|
-
|
220
|
-
test "creation_date" do
|
221
|
-
assert @file_block.created_at - @resource.creation_date <= 100, "Ensure the times are close"
|
222
|
-
end
|
223
|
-
|
224
|
-
test "last_modified" do
|
225
|
-
assert @file_block.updated_at - @resource.last_modified <= 100, "Ensure the times are close"
|
226
|
-
end
|
227
|
-
|
228
|
-
test "pages are not collections" do
|
229
|
-
assert_equal false, @resource.collection?
|
230
|
-
end
|
231
|
-
|
232
|
-
test "file size is correct" do
|
233
|
-
assert_equal @file.size, @resource.content_length
|
234
|
-
end
|
235
|
-
|
236
|
-
test "content_type matches underlying file type" do
|
237
|
-
assert_equal @file.content_type, @resource.content_type
|
238
|
-
end
|
239
|
-
|
240
|
-
test "Getting a file" do
|
241
|
-
mock_rack_file = mock()
|
242
|
-
mock_rack_file.expects(:path).returns("").at_least_once
|
243
|
-
Bcms::WebDAV::File.expects(:new).with(@file_block.attachment.full_file_location).returns(mock_rack_file)
|
244
|
-
|
245
|
-
@request.expects(:path).returns("/about-us/test.jpg").at_least_once
|
246
|
-
@response.expects(:body=).with(mock_rack_file)
|
247
|
-
|
248
|
-
@resource.get(@request, @response)
|
249
|
-
|
250
|
-
end
|
251
|
-
|
252
|
-
test "Finding a section includes child files as resources" do
|
253
|
-
@section = resource_for("/about-us")
|
254
|
-
assert_equal 1, @section.children.size
|
255
|
-
assert_equal "/about-us/test.jpg", @section.children.first.path
|
256
|
-
end
|
257
|
-
|
258
|
-
|
259
|
-
test "determine target_section" do
|
260
|
-
path = Bcms::WebDAV::Path.new('/about-us/test.jpg')
|
261
|
-
assert_equal "test.jpg", path.file_name
|
262
|
-
assert_equal '/about-us/', path.path_without_filename
|
263
|
-
|
264
|
-
assert_equal @about_us, @resource.find_section_for("/about-us/test.jpg")
|
265
|
-
end
|
266
|
-
|
267
|
-
test "Uploading files with spaces or special characters" do
|
268
|
-
path = Bcms::WebDAV::Path.new('/about-us/test with spaces.jpg')
|
269
|
-
assert_equal "test_with_spaces.jpg", path.file_name
|
270
|
-
assert_equal '/about-us/', path.path_without_filename
|
271
|
-
|
272
|
-
assert_equal @about_us, @resource.find_section_for("/about-us/test with spaces.jpg")
|
273
|
-
end
|
274
|
-
test "Uploading files with encoded spaces" do
|
275
|
-
path = Bcms::WebDAV::Path.new('/about-us/test%20with%20spaces.jpg')
|
276
|
-
assert_equal "test_with_spaces.jpg", path.file_name
|
277
|
-
assert_equal '/about-us/', path.path_without_filename
|
278
|
-
|
279
|
-
assert_equal @about_us, @resource.find_section_for("/about-us/test with spaces.jpg")
|
280
|
-
end
|
281
|
-
|
282
|
-
test "uploading files to root section" do
|
283
|
-
assert_equal Section.root.first, @resource.find_section_for("/test.jpg")
|
284
|
-
end
|
285
|
-
|
286
|
-
test "parse empty section" do
|
287
|
-
path = Bcms::WebDAV::Path.new('/test.jpg')
|
288
|
-
assert_equal "test.jpg", path.file_name
|
289
|
-
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
test "parse missing slash section" do
|
294
|
-
path = Bcms::WebDAV::Path.new('test.jpg')
|
295
|
-
assert_equal "test.jpg", path.file_name
|
296
|
-
end
|
297
|
-
|
298
|
-
test "extract tempfile from mongrel style requests" do
|
299
|
-
tempfile = Tempfile.new("testing")
|
300
|
-
@request.expects(:body).returns(tempfile)
|
301
|
-
|
302
|
-
assert_equal tempfile, @resource.send(:extract_tempfile, @request)
|
303
|
-
|
304
|
-
end
|
305
|
-
|
306
|
-
test "extract tempfile from passenger style requests" do
|
307
|
-
class FakeRewindable
|
308
|
-
def size
|
309
|
-
@rewindable_io = 'EXPECTED'
|
310
|
-
end
|
311
|
-
private
|
312
|
-
|
313
|
-
# Matches passengers rewindable input signature
|
314
|
-
def make_rewindable
|
315
|
-
'do nothing'
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
rewindable_input = FakeRewindable.new
|
320
|
-
@request.expects(:body).returns(rewindable_input)
|
321
|
-
|
322
|
-
assert_equal 'EXPECTED', @resource.send(:extract_tempfile, @request)
|
323
|
-
end
|
324
|
-
|
325
|
-
private
|
326
|
-
def resource_for(path)
|
327
|
-
Bcms::WebDAV::Resource.new(path, path, @request, @response, {})
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
|