carrierwave-mongoid 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/carrierwave/mongoid/version.rb +1 -1
- data/lib/carrierwave/storage/grid_fs.rb +6 -9
- data/spec/storage/grid_fs_spec.rb +22 -6
- metadata +16 -16
@@ -38,26 +38,23 @@ module CarrierWave
|
|
38
38
|
class GridFS < Abstract
|
39
39
|
|
40
40
|
class File
|
41
|
+
attr_reader :path
|
41
42
|
|
42
43
|
def initialize(uploader, path)
|
43
44
|
@path = path
|
44
45
|
@uploader = uploader
|
45
46
|
end
|
46
47
|
|
47
|
-
def path
|
48
|
-
@path
|
49
|
-
end
|
50
|
-
|
51
48
|
def url
|
52
49
|
unless @uploader.grid_fs_access_url
|
53
50
|
nil
|
54
51
|
else
|
55
|
-
|
52
|
+
::File.join(@uploader.grid_fs_access_url, path)
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
59
56
|
def read
|
60
|
-
grid.open(
|
57
|
+
grid.open(path, 'r').data
|
61
58
|
end
|
62
59
|
|
63
60
|
def write(file)
|
@@ -67,15 +64,15 @@ module CarrierWave
|
|
67
64
|
end
|
68
65
|
|
69
66
|
def delete
|
70
|
-
grid.delete(
|
67
|
+
grid.delete(path)
|
71
68
|
end
|
72
69
|
|
73
70
|
def content_type
|
74
|
-
grid.open(
|
71
|
+
grid.open(path, 'r').content_type
|
75
72
|
end
|
76
73
|
|
77
74
|
def file_length
|
78
|
-
grid.open(
|
75
|
+
grid.open(path, 'r').file_length
|
79
76
|
end
|
80
77
|
alias :size :file_length
|
81
78
|
|
@@ -38,7 +38,6 @@ shared_examples_for "a GridFS connection" do
|
|
38
38
|
it "should have a file length" do
|
39
39
|
@grid_fs_file.file_length.should == 13
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
|
44
43
|
describe '#retrieve!' do
|
@@ -56,16 +55,21 @@ shared_examples_for "a GridFS connection" do
|
|
56
55
|
@grid_fs_file.path.should == 'uploads/bar.txt'
|
57
56
|
end
|
58
57
|
|
59
|
-
it "should not have a URL unless set" do
|
58
|
+
it "should not have a URL unless access_url is set" do
|
60
59
|
@grid_fs_file.url.should be_nil
|
61
60
|
end
|
62
61
|
|
63
|
-
it "should return a URL path if
|
62
|
+
it "should return a relative URL path if access_url is set to the root path" do
|
63
|
+
@uploader.stub!(:grid_fs_access_url).and_return("/")
|
64
|
+
@grid_fs_file.url.should == "/uploads/bar.txt"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return a URL path if access_url is set to a file path" do
|
64
68
|
@uploader.stub!(:grid_fs_access_url).and_return("/image/show")
|
65
69
|
@grid_fs_file.url.should == "/image/show/uploads/bar.txt"
|
66
70
|
end
|
67
71
|
|
68
|
-
it "should return an absolute URL if
|
72
|
+
it "should return an absolute URL if access_url is set to an absolute URL" do
|
69
73
|
@uploader.stub!(:grid_fs_access_url).and_return("http://example.com/images/")
|
70
74
|
@grid_fs_file.url.should == "http://example.com/images/uploads/bar.txt"
|
71
75
|
end
|
@@ -73,6 +77,19 @@ shared_examples_for "a GridFS connection" do
|
|
73
77
|
it "should be deletable" do
|
74
78
|
@grid_fs_file.delete
|
75
79
|
lambda {@grid.open('uploads/bar.txt', 'r')}.should raise_error(Mongo::GridFileNotFound)
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#retrieve! on a store_dir with leading slash' do
|
85
|
+
before do
|
86
|
+
@uploader.stub!(:store_path).with('bar.txt').and_return('/uploads/bar.txt')
|
87
|
+
@grid_fs_file = @storage.retrieve!('bar.txt')
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return a relative URL path if access_url is set to the root path" do
|
91
|
+
@uploader.stub!(:grid_fs_access_url).and_return("/")
|
92
|
+
@grid_fs_file.url.should == "/uploads/bar.txt"
|
76
93
|
end
|
77
94
|
end
|
78
95
|
|
@@ -131,8 +148,7 @@ describe CarrierWave::Storage::GridFS do
|
|
131
148
|
end
|
132
149
|
end
|
133
150
|
|
134
|
-
|
135
|
-
describe "resize_to_fill" do
|
151
|
+
describe "resize_to_fill" do
|
136
152
|
before do
|
137
153
|
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
138
154
|
@uploader_class.class_eval{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-04-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: carrierwave
|
17
|
-
requirement: &
|
17
|
+
requirement: &70216819494840 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.5.6
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70216819494840
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: mongoid
|
28
|
-
requirement: &
|
28
|
+
requirement: &70216819480940 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '2.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70216819480940
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70216819480100 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '2.6'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70216819480100
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bson_ext
|
50
|
-
requirement: &
|
50
|
+
requirement: &70216819479460 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '1.3'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70216819479460
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
requirement: &
|
61
|
+
requirement: &70216819478840 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0.9'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70216819478840
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: mini_magick
|
72
|
-
requirement: &
|
72
|
+
requirement: &70216819478440 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70216819478440
|
81
81
|
description: Mongoid support for CarrierWave
|
82
82
|
email:
|
83
83
|
- jonas.nicklas@gmail.com
|
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
segments:
|
121
121
|
- 0
|
122
|
-
hash: -
|
122
|
+
hash: -3626845613401080446
|
123
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
124
|
none: false
|
125
125
|
requirements:
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash: -
|
131
|
+
hash: -3626845613401080446
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project: carrierwave-mongoid
|
134
134
|
rubygems_version: 1.8.11
|