cm-carrierwave_dav 0.1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/cm-carrierwave_dav.gemspec +91 -0
- data/lib/carrierwave_dav.rb +16 -0
- data/lib/carrierwave_dav/file.rb +105 -0
- data/lib/carrierwave_dav/storage.rb +24 -0
- data/spec/carrierwave_dav/file_spec.rb +146 -0
- data/spec/carrierwave_dav/storage_spec.rb +24 -0
- data/spec/spec_helper.rb +19 -0
- metadata +242 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6066e21f7244d43db26084c5dada6d8dd78e385c
|
4
|
+
data.tar.gz: f065d044783eebfbc047703eaea44278454948cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 213d4d5ceba8c9323e19cfda28dbdb4134343a96ae642491c4e170d029deb771b719f44ee3a86b6240ba32c7a126b3704bea4c2632d8b83554ced4961e3f186f
|
7
|
+
data.tar.gz: 60dd117bdcc39e52f6d5ff70459f56ef62d00a3625c2bf319c19fab3287789f8ebe118a75cc51288d3ca7dc275e97e42c8b4fe07048f36f610109334d9145eed
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color -fd
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.8.7@carrierwave_dav --create
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "i18n" #required by activesupport
|
7
|
+
gem "activesupport"
|
8
|
+
gem "carrierwave"
|
9
|
+
gem "net_dav"
|
10
|
+
|
11
|
+
# Add dependencies to develop your gem here.
|
12
|
+
# Include everything needed to run rake, tests, features, etc.
|
13
|
+
group :development do
|
14
|
+
gem "rspec-core", "~> 2.6.3"
|
15
|
+
gem "rspec", "~> 2.6.0"
|
16
|
+
gem "yard"
|
17
|
+
gem "bundler"
|
18
|
+
gem "jeweler"
|
19
|
+
gem "addressable", "2.2.4"
|
20
|
+
gem "webmock"
|
21
|
+
gem "awesome_print"
|
22
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 miros
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= carrierwave_dav
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to carrierwave_dav
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 miros. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "carrierwave_dav"
|
18
|
+
gem.homepage = "http://github.com/miros/carrierwave_dav"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Web Dav adapter for carrierwave}
|
21
|
+
gem.description = %Q{Web Dav adapter for carrierwave}
|
22
|
+
gem.email = "mirosm@mirosm.ru"
|
23
|
+
gem.authors = ["miros"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
require "rspec/core/rake_task"
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
37
|
+
t.rcov = true
|
38
|
+
t.rcov_opts = "--exclude /gems/,/Library/,/usr/,spec,lib/tasks"
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'yard'
|
44
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2.1
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{cm-carrierwave_dav}
|
8
|
+
s.version = "0.1.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["miros"]
|
12
|
+
s.date = %q{2011-06-01}
|
13
|
+
s.description = %q{Web Dav adapter for carrierwave}
|
14
|
+
s.email = %q{mirosm@mirosm.ru}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"cm-carrierwave_dav.gemspec",
|
29
|
+
"lib/carrierwave_dav.rb",
|
30
|
+
"lib/carrierwave_dav/file.rb",
|
31
|
+
"lib/carrierwave_dav/storage.rb",
|
32
|
+
"spec/carrierwave_dav/file_spec.rb",
|
33
|
+
"spec/carrierwave_dav/storage_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/miros/carrierwave_dav}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{Web Dav adapter for carrierwave}
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<carrierwave>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<net_dav>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec-core>, ["~> 2.6.3"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
53
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<addressable>, ["= 2.2.4"])
|
58
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
62
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
63
|
+
s.add_dependency(%q<carrierwave>, [">= 0"])
|
64
|
+
s.add_dependency(%q<net_dav>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec-core>, ["~> 2.6.3"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
67
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
68
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
69
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<addressable>, ["= 2.2.4"])
|
72
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
73
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
77
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
78
|
+
s.add_dependency(%q<carrierwave>, [">= 0"])
|
79
|
+
s.add_dependency(%q<net_dav>, [">= 0"])
|
80
|
+
s.add_dependency(%q<rspec-core>, ["~> 2.6.3"])
|
81
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
82
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
83
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
84
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
85
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
86
|
+
s.add_dependency(%q<addressable>, ["= 2.2.4"])
|
87
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
88
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'carrierwave'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
require 'carrierwave_dav/file'
|
7
|
+
require 'carrierwave_dav/storage'
|
8
|
+
|
9
|
+
module CarrierWave
|
10
|
+
module Dav
|
11
|
+
|
12
|
+
mattr_accessor :dav_factory
|
13
|
+
self.dav_factory = Net::DAV.method(:new)
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'net/dav'
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Dav
|
5
|
+
|
6
|
+
class File
|
7
|
+
def initialize(file_url, dav_path, connection = nil)
|
8
|
+
@file_url = file_url
|
9
|
+
@dav_path = append_trailing_slash(dav_path)
|
10
|
+
|
11
|
+
uri = URI.parse(file_url)
|
12
|
+
@file_path = uri.path
|
13
|
+
|
14
|
+
@dav_host = file_url.gsub(@file_path, '')
|
15
|
+
|
16
|
+
@connection = connection || CarrierWave::Dav.dav_factory.call(@dav_host)
|
17
|
+
@created_dirs = []
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :connection, :file_path, :dav_host, :created_dirs, :file_url
|
21
|
+
|
22
|
+
# это урл для ссылок на файлы
|
23
|
+
def url
|
24
|
+
"/" + file_url.gsub(@dav_path, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
def path
|
28
|
+
file_url
|
29
|
+
end
|
30
|
+
|
31
|
+
def read
|
32
|
+
connection.get(file_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def write(file)
|
36
|
+
mkpath(::File.dirname(file_path))
|
37
|
+
connection.put_string(file_path, file.read)
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete
|
41
|
+
delete_path(file_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def size
|
45
|
+
read.size
|
46
|
+
end
|
47
|
+
|
48
|
+
def mkpath(path)
|
49
|
+
parts = path.split("/").reject(&:blank?)
|
50
|
+
parts.inject("") do |current_path, part|
|
51
|
+
current_path = ::File.join(current_path, part)
|
52
|
+
create_path(current_path)
|
53
|
+
current_path
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_path(path)
|
58
|
+
path = append_trailing_slash(path)
|
59
|
+
begin
|
60
|
+
connection.mkdir(path)
|
61
|
+
@created_dirs << path
|
62
|
+
rescue EOFError
|
63
|
+
# почему то ответ nginx приводит к этому эксепшену
|
64
|
+
# папка тем не менее создаётся
|
65
|
+
@created_dirs << path
|
66
|
+
rescue Net::HTTPServerException => exc
|
67
|
+
# если папка уже есть - плевать
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def destroy_created_dirs!(options = {})
|
72
|
+
# Удаляем папки в порядке обратном созданию
|
73
|
+
options[:min_depth] ||= 0
|
74
|
+
dirs = @created_dirs.select{|dir| dir_depth(dir) >= options[:min_depth]}
|
75
|
+
dirs.reverse.each {|folder| delete_path(folder)}
|
76
|
+
end
|
77
|
+
|
78
|
+
def content_type
|
79
|
+
@content_type
|
80
|
+
end
|
81
|
+
|
82
|
+
def content_type=(new_content_type)
|
83
|
+
@content_type = new_content_type
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def dir_depth(dir)
|
89
|
+
dir.split("/").reject(&:blank?).count
|
90
|
+
end
|
91
|
+
|
92
|
+
def delete_path(path)
|
93
|
+
connection.delete(path)
|
94
|
+
rescue Exception
|
95
|
+
# не обращаем внимания на ошибки при удалении
|
96
|
+
end
|
97
|
+
|
98
|
+
def append_trailing_slash(path)
|
99
|
+
path.last == "/" ? path : path + "/"
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'net/dav'
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Dav
|
5
|
+
class Storage < CarrierWave::Storage::Abstract
|
6
|
+
|
7
|
+
def initialize(uploader, dav_path)
|
8
|
+
super(uploader)
|
9
|
+
@dav_path = dav_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def store!(file)
|
13
|
+
f = CarrierWave::Dav::File.new(uploader.store_path, @dav_path)
|
14
|
+
f.write(file)
|
15
|
+
f
|
16
|
+
end
|
17
|
+
|
18
|
+
def retrieve!(identifier)
|
19
|
+
CarrierWave::Dav::File.new(uploader.store_path(identifier), @dav_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::Dav::File do
|
4
|
+
|
5
|
+
describe "#file_path" do
|
6
|
+
it "returns path to file from host root" do
|
7
|
+
file = described_class.new('http://localhost:1234/appstore/applications/file.txt', "http://localhost:1234/appstore/")
|
8
|
+
file.file_path.should == "/appstore/applications/file.txt"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#dav_host" do
|
13
|
+
it "returns correct dav_host when host has port" do
|
14
|
+
file = described_class.new('http://localhost:1234/appstore/applications/file.txt', "http://localhost:1234/appstore/")
|
15
|
+
file.dav_host.should == "http://localhost:1234"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns dav_host when host has no port" do
|
19
|
+
file = described_class.new('http://localhost/appstore/applications/file.txt', "http://localhost/appstore/")
|
20
|
+
file.dav_host.should == "http://localhost"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#path" do
|
25
|
+
it "returns full file uri including dav host" do
|
26
|
+
file = described_class.new('http://localhost:1234/appstore/applications/file.txt', "http://localhost:1234/appstore/")
|
27
|
+
file.path.should == 'http://localhost:1234/appstore/applications/file.txt'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#url" do
|
32
|
+
it "returns file url" do
|
33
|
+
file = described_class.new('http://localhost:1234/appstore/applications/file.txt', "http://localhost:1234/appstore/")
|
34
|
+
file.url.should == '/applications/file.txt'
|
35
|
+
end
|
36
|
+
it "returns correct url when dav path has no trailing slash" do
|
37
|
+
file = described_class.new('http://localhost:1234/appstore/applications/file.txt', "http://localhost:1234/appstore")
|
38
|
+
file.url.should == '/applications/file.txt'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "creates connection with appropriate url" do
|
43
|
+
CarrierWave::Dav.dav_factory.should_receive(:call).with("http://localhost:1234")
|
44
|
+
described_class.new('http://localhost:1234/appstore/applications/file.txt', "http://localhost:1234/appstore/")
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "working with files" do
|
48
|
+
let(:connection) {mock("connection").as_null_object}
|
49
|
+
let(:file) {described_class.new("http://localhost:1234/appstore/some/path/file.txt", "http://localhost:1234/appstore", connection)}
|
50
|
+
|
51
|
+
describe "#read" do
|
52
|
+
it "reads file from storage" do
|
53
|
+
file_data = mock
|
54
|
+
connection.should_receive(:get).with("/appstore/some/path/file.txt") {file_data}
|
55
|
+
file.read.should == file_data
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#size" do
|
60
|
+
it "returns size of file" do
|
61
|
+
connection.should_receive(:get).with("/appstore/some/path/file.txt") {"12345"}
|
62
|
+
file.size.should == 5
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#write" do
|
67
|
+
it "tries to create folder for file" do
|
68
|
+
file.should_receive(:mkpath).with("/appstore/some/path")
|
69
|
+
file.write(StringIO.new("data"))
|
70
|
+
end
|
71
|
+
it "writes file to storage" do
|
72
|
+
connection.should_receive(:put_string).with("/appstore/some/path/file.txt", "data")
|
73
|
+
file.write(StringIO.new("data"))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#mkpath" do
|
78
|
+
it "creates dirs one-by-one" do
|
79
|
+
connection.should_receive(:mkdir).with("/some/").ordered
|
80
|
+
connection.should_receive(:mkdir).with("/some/long/").ordered
|
81
|
+
connection.should_receive(:mkdir).with("/some/long/path/").ordered
|
82
|
+
file.mkpath("/some/long/path")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "memorizes created dirs " do
|
86
|
+
file.mkpath("/some/long/path")
|
87
|
+
file.created_dirs.should == ["/some/", "/some/long/", "/some/long/path/"]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "memorizes only dirs that were really created" do
|
91
|
+
connection.should_receive(:mkdir).with("/some/").and_raise(Net::HTTPServerException.new(nil, nil))
|
92
|
+
|
93
|
+
file.mkpath("/some/long/path")
|
94
|
+
file.created_dirs.should == ["/some/long/", "/some/long/path/"]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "ignores EOFError errors" do
|
98
|
+
connection.should_receive(:mkdir).with("/some/").and_raise(EOFError)
|
99
|
+
|
100
|
+
file.mkpath("/some/long/path")
|
101
|
+
file.created_dirs.should == ["/some/", "/some/long/", "/some/long/path/"]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#destroy_created_dirs!" do
|
106
|
+
it "destroy created dirs in reversed order" do
|
107
|
+
file.mkpath("/some/long/path")
|
108
|
+
|
109
|
+
connection.should_receive(:delete).with("/some/long/path/").ordered
|
110
|
+
connection.should_receive(:delete).with("/some/long/").ordered
|
111
|
+
connection.should_receive(:delete).with("/some/").ordered
|
112
|
+
|
113
|
+
file.destroy_created_dirs!
|
114
|
+
end
|
115
|
+
context "when min_depth param given" do
|
116
|
+
it "deletes only directories with depth >= min_depth" do
|
117
|
+
file.mkpath("/some/very/long/path")
|
118
|
+
|
119
|
+
connection.should_receive(:delete).with("/some/very/long/path/").ordered
|
120
|
+
connection.should_receive(:delete).with("/some/very/long/").ordered
|
121
|
+
connection.should_not_receive(:delete).with("/some/very/")
|
122
|
+
connection.should_not_receive(:delete).with("/some/")
|
123
|
+
|
124
|
+
file.destroy_created_dirs!(:min_depth => 3)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#delete" do
|
132
|
+
it "deletes file" do
|
133
|
+
connection.should_receive(:delete).with("/appstore/some/path/file.txt")
|
134
|
+
file.delete
|
135
|
+
end
|
136
|
+
|
137
|
+
it "ignores all errors of file deletion" do
|
138
|
+
connection.stub(:delete).and_raise(Exception)
|
139
|
+
expect { file.delete }.to_not raise_error
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::Dav::Storage do
|
4
|
+
|
5
|
+
let(:uploader) {mock("uploader", :store_path => "http://host/files/file.txt")}
|
6
|
+
let(:storage) {described_class.new(uploader, "http://host/files")}
|
7
|
+
let(:file) {StringIO.new("some_data")}
|
8
|
+
|
9
|
+
it "allows to store file" do
|
10
|
+
stub_any_request
|
11
|
+
storage.store!(file)
|
12
|
+
|
13
|
+
a_request(:mkcol, "http://host/files/").should have_been_made
|
14
|
+
a_request(:put, "http://host/files/file.txt").with(:body => "some_data").should have_been_made
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows to retrieve file" do
|
18
|
+
uploader.should_receive(:store_path).with("identifier") {"http://host/files/file.txt"}
|
19
|
+
|
20
|
+
dav_file = storage.retrieve!("identifier")
|
21
|
+
dav_file.should be_instance_of(CarrierWave::Dav::File)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'ap'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
require 'carrierwave_dav'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
def stub_any_request
|
16
|
+
stub_request(:any, /.*/)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cm-carrierwave_dav
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- miros
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2011-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: carrierwave
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: net_dav
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-core
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.6.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.6.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.6.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.6.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: jeweler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rcov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: addressable
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.2.4
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.2.4
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: awesome_print
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: Web Dav adapter for carrierwave
|
196
|
+
email: mirosm@mirosm.ru
|
197
|
+
executables: []
|
198
|
+
extensions: []
|
199
|
+
extra_rdoc_files:
|
200
|
+
- LICENSE.txt
|
201
|
+
- README.rdoc
|
202
|
+
files:
|
203
|
+
- ".document"
|
204
|
+
- ".rspec"
|
205
|
+
- ".rvmrc"
|
206
|
+
- Gemfile
|
207
|
+
- LICENSE.txt
|
208
|
+
- README.rdoc
|
209
|
+
- Rakefile
|
210
|
+
- VERSION
|
211
|
+
- cm-carrierwave_dav.gemspec
|
212
|
+
- lib/carrierwave_dav.rb
|
213
|
+
- lib/carrierwave_dav/file.rb
|
214
|
+
- lib/carrierwave_dav/storage.rb
|
215
|
+
- spec/carrierwave_dav/file_spec.rb
|
216
|
+
- spec/carrierwave_dav/storage_spec.rb
|
217
|
+
- spec/spec_helper.rb
|
218
|
+
homepage: http://github.com/miros/carrierwave_dav
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
metadata: {}
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - ">="
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubyforge_project:
|
238
|
+
rubygems_version: 2.2.2
|
239
|
+
signing_key:
|
240
|
+
specification_version: 3
|
241
|
+
summary: Web Dav adapter for carrierwave
|
242
|
+
test_files: []
|