mm-carrierwave 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +114 -0
- data/README.textile +16 -0
- data/Rakefile +2 -0
- data/lib/carrierwave/orm/mongomapper.rb +30 -0
- data/lib/version.rb +5 -0
- data/mm-carrierwave.gemspec +30 -0
- data/spec/fixtures/bork.txt +1 -0
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/fixtures/test.jpeg +1 -0
- data/spec/fixtures/test.jpg +1 -0
- data/spec/lib/carrierwave/orm/mongomapper_spec.rb +289 -0
- data/spec/public/uploads/test.jpg +1 -0
- data/spec/spec_helper.rb +100 -0
- metadata +236 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mm-carrierwave (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
abstract (1.0.0)
|
10
|
+
actionmailer (3.0.3)
|
11
|
+
actionpack (= 3.0.3)
|
12
|
+
mail (~> 2.2.9)
|
13
|
+
actionpack (3.0.3)
|
14
|
+
activemodel (= 3.0.3)
|
15
|
+
activesupport (= 3.0.3)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.4)
|
19
|
+
rack (~> 1.2.1)
|
20
|
+
rack-mount (~> 0.6.13)
|
21
|
+
rack-test (~> 0.5.6)
|
22
|
+
tzinfo (~> 0.3.23)
|
23
|
+
activemodel (3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
i18n (~> 0.4)
|
27
|
+
activerecord (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
arel (~> 2.0.2)
|
31
|
+
tzinfo (~> 0.3.23)
|
32
|
+
activeresource (3.0.3)
|
33
|
+
activemodel (= 3.0.3)
|
34
|
+
activesupport (= 3.0.3)
|
35
|
+
activesupport (3.0.3)
|
36
|
+
arel (2.0.6)
|
37
|
+
bson (1.1.5)
|
38
|
+
bson_ext (1.1.5)
|
39
|
+
builder (2.1.2)
|
40
|
+
carrierwave (0.5.1)
|
41
|
+
activesupport (~> 3.0)
|
42
|
+
diff-lcs (1.1.2)
|
43
|
+
erubis (2.6.6)
|
44
|
+
abstract (>= 1.0.0)
|
45
|
+
i18n (0.5.0)
|
46
|
+
jnunemaker-validatable (1.8.4)
|
47
|
+
activesupport (>= 2.3.4)
|
48
|
+
json (1.4.6)
|
49
|
+
mail (2.2.12)
|
50
|
+
activesupport (>= 2.3.6)
|
51
|
+
i18n (>= 0.4.0)
|
52
|
+
mime-types (~> 1.16)
|
53
|
+
treetop (~> 1.4.8)
|
54
|
+
mime-types (1.16)
|
55
|
+
mini_magick (2.3)
|
56
|
+
subexec (~> 0.0.4)
|
57
|
+
mongo (1.1.5)
|
58
|
+
bson (>= 1.1.5)
|
59
|
+
mongo_mapper (0.8.6)
|
60
|
+
activesupport (>= 2.3.4)
|
61
|
+
jnunemaker-validatable (~> 1.8.4)
|
62
|
+
plucky (~> 0.3.6)
|
63
|
+
plucky (0.3.6)
|
64
|
+
mongo (~> 1.1)
|
65
|
+
polyglot (0.3.1)
|
66
|
+
rack (1.2.1)
|
67
|
+
rack-mount (0.6.13)
|
68
|
+
rack (>= 1.0.0)
|
69
|
+
rack-test (0.5.6)
|
70
|
+
rack (>= 1.0)
|
71
|
+
rails (3.0.3)
|
72
|
+
actionmailer (= 3.0.3)
|
73
|
+
actionpack (= 3.0.3)
|
74
|
+
activerecord (= 3.0.3)
|
75
|
+
activeresource (= 3.0.3)
|
76
|
+
activesupport (= 3.0.3)
|
77
|
+
bundler (~> 1.0)
|
78
|
+
railties (= 3.0.3)
|
79
|
+
railties (3.0.3)
|
80
|
+
actionpack (= 3.0.3)
|
81
|
+
activesupport (= 3.0.3)
|
82
|
+
rake (>= 0.8.7)
|
83
|
+
thor (~> 0.14.4)
|
84
|
+
rake (0.8.7)
|
85
|
+
rspec (2.1.0)
|
86
|
+
rspec-core (~> 2.1.0)
|
87
|
+
rspec-expectations (~> 2.1.0)
|
88
|
+
rspec-mocks (~> 2.1.0)
|
89
|
+
rspec-core (2.1.0)
|
90
|
+
rspec-expectations (2.1.0)
|
91
|
+
diff-lcs (~> 1.1.2)
|
92
|
+
rspec-mocks (2.1.0)
|
93
|
+
subexec (0.0.4)
|
94
|
+
thor (0.14.6)
|
95
|
+
timecop (0.3.5)
|
96
|
+
treetop (1.4.9)
|
97
|
+
polyglot (>= 0.3.1)
|
98
|
+
tzinfo (0.3.23)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
activemodel
|
105
|
+
bson_ext (= 1.1.5)
|
106
|
+
carrierwave
|
107
|
+
jnunemaker-validatable
|
108
|
+
json
|
109
|
+
mini_magick (~> 2.3)
|
110
|
+
mm-carrierwave!
|
111
|
+
mongo_mapper
|
112
|
+
rails (~> 3.0.0)
|
113
|
+
rspec (~> 2.1.0)
|
114
|
+
timecop
|
data/README.textile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
h1. MongoMapper CarrierWave "!http://stillmaintained.com/80beans/mm-carrierwave.png!":http://stillmaintained.com/80beans/mm-carrierwave
|
2
|
+
|
3
|
+
Orm to use MongoMapper and Carrierwave.
|
4
|
+
|
5
|
+
https://github.com/jnunemaker/mongomapper
|
6
|
+
https://github.com/jnicklas/carrierwave
|
7
|
+
|
8
|
+
|
9
|
+
h2. Status
|
10
|
+
|
11
|
+
Everything works except validations right now.
|
12
|
+
|
13
|
+
|
14
|
+
h2. License
|
15
|
+
|
16
|
+
Copyright (c) 2010 80beans, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'mongo_mapper'
|
4
|
+
|
5
|
+
module CarrierWave
|
6
|
+
module MongoMapper
|
7
|
+
include CarrierWave::Mount
|
8
|
+
##
|
9
|
+
# See +CarrierWave::Mount#mount_uploader+ for documentation
|
10
|
+
#
|
11
|
+
def mount_uploader(column, uploader, options={}, &block)
|
12
|
+
options[:mount_on] ||= "#{column}_filename"
|
13
|
+
key options[:mount_on]
|
14
|
+
|
15
|
+
super
|
16
|
+
|
17
|
+
alias_method :read_uploader, :read_attribute
|
18
|
+
alias_method :write_uploader, :write_attribute
|
19
|
+
|
20
|
+
# validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
|
21
|
+
# validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
|
22
|
+
|
23
|
+
after_save "store_#{column}!".to_sym
|
24
|
+
before_save "write_#{column}_identifier".to_sym
|
25
|
+
after_destroy "remove_#{column}!".to_sym
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
MongoMapper::Document.append_extensions(CarrierWave::MongoMapper)
|
data/lib/version.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "lib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mm-carrierwave"
|
7
|
+
s.version = Mm::Carrierwave::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Robert Beekman"]
|
10
|
+
s.email = ["robert@80beans.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Mongomapper ORM for Carrierwave}
|
13
|
+
s.description = %q{Mongomapper ORM for Carrierwave}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rails", ["~> 3.0.0"]
|
21
|
+
s.add_development_dependency('rspec', ["~> 2.1.0"])
|
22
|
+
s.add_development_dependency "mini_magick", ["~> 2.3"]
|
23
|
+
s.add_development_dependency "bson_ext", ["= 1.1.5"]
|
24
|
+
s.add_development_dependency "carrierwave"
|
25
|
+
s.add_development_dependency "activemodel"
|
26
|
+
s.add_development_dependency "mongo_mapper"
|
27
|
+
s.add_development_dependency "timecop"
|
28
|
+
s.add_development_dependency "json"
|
29
|
+
s.add_development_dependency "jnunemaker-validatable"
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
bork bork bork Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
this is stuff
|
@@ -0,0 +1 @@
|
|
1
|
+
this is stuff
|
@@ -0,0 +1,289 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'mongo_mapper'
|
4
|
+
require 'lib/carrierwave/orm/mongomapper'
|
5
|
+
|
6
|
+
MongoMapper.database = "carrierwave_test"
|
7
|
+
|
8
|
+
|
9
|
+
def reset_mongo_class(uploader = MongoUploader)
|
10
|
+
class_name = 'MongoUser'
|
11
|
+
Object.send(:remove_const, class_name) rescue nil
|
12
|
+
klass = Object.const_set(class_name, Class.new)
|
13
|
+
klass.class_eval do
|
14
|
+
include MongoMapper::Document
|
15
|
+
set_collection_name :users
|
16
|
+
|
17
|
+
mount_uploader :image, uploader
|
18
|
+
end
|
19
|
+
klass
|
20
|
+
end
|
21
|
+
|
22
|
+
class MongoUploader < CarrierWave::Uploader::Base; end
|
23
|
+
|
24
|
+
class WhiteListUploader < CarrierWave::Uploader::Base
|
25
|
+
def extension_white_list
|
26
|
+
%(txt)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ProcessingErrorUploader < CarrierWave::Uploader::Base
|
31
|
+
process :monkey
|
32
|
+
def monkey
|
33
|
+
raise CarrierWave::ProcessingError, "Ohh noez!"
|
34
|
+
end
|
35
|
+
def extension_white_list
|
36
|
+
%(jpg)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe CarrierWave::MongoMapper do
|
42
|
+
|
43
|
+
after do
|
44
|
+
MongoUser.collection.drop
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#image' do
|
48
|
+
|
49
|
+
context "when nothing is assigned" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
mongo_user_klass = reset_mongo_class
|
53
|
+
@document = mongo_user_klass.new
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns a blank uploader" do
|
57
|
+
@document.image.should be_blank
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when an empty string is assigned" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
mongo_user_klass = reset_mongo_class
|
66
|
+
@document = mongo_user_klass.new(:image_filename => "")
|
67
|
+
@document.save
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a blank uploader" do
|
71
|
+
@saved_doc = MongoUser.first
|
72
|
+
@saved_doc.image.should be_blank
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when a filename is saved in the database" do
|
78
|
+
|
79
|
+
before do
|
80
|
+
mongo_user_klass = reset_mongo_class
|
81
|
+
@document = mongo_user_klass.new(:image_filename => "test.jpg")
|
82
|
+
@document.save
|
83
|
+
@doc = MongoUser.first
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns an uploader" do
|
87
|
+
@doc.image.should be_an_instance_of(MongoUploader)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "sets the path to the store directory" do
|
91
|
+
@doc.image.current_path.should == public_path('uploads/test.jpg')
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#image=' do
|
99
|
+
|
100
|
+
before do
|
101
|
+
mongo_user_klass = reset_mongo_class
|
102
|
+
@doc = mongo_user_klass.new
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when nil is assigned" do
|
106
|
+
|
107
|
+
it "does not set the value" do
|
108
|
+
@doc.image = nil
|
109
|
+
@doc.image.should be_blank
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when an empty string is assigned" do
|
115
|
+
|
116
|
+
it "does not set the value" do
|
117
|
+
@doc.image = ''
|
118
|
+
@doc.image.should be_blank
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when a file is assigned" do
|
124
|
+
|
125
|
+
it "should cache a file" do
|
126
|
+
@doc.image = stub_file('test.jpeg')
|
127
|
+
@doc.image.should be_an_instance_of(MongoUploader)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
|
131
|
+
@doc.image_filename.should be_nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should copy a file into into the cache directory" do
|
135
|
+
@doc.image = stub_file('test.jpeg')
|
136
|
+
@doc.image.current_path.should =~ /^#{public_path('uploads\/tmp')}/
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
pending 'when validating integrity' do
|
142
|
+
before do
|
143
|
+
mongo_user_klass = reset_mongo_class(WhiteListUploader)
|
144
|
+
@doc = mongo_user_klass.new
|
145
|
+
@doc.image = stub_file('test.jpg')
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should make the document invalid when an integrity error occurs" do
|
149
|
+
@doc.should_not be_valid
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should use I18n for integrity error messages" do
|
153
|
+
@doc.valid?
|
154
|
+
@doc.errors[:image].should == ['is not an allowed file type']
|
155
|
+
|
156
|
+
change_locale_and_store_translations(:pt, :activemodel => {
|
157
|
+
:errors => {
|
158
|
+
:messages => {
|
159
|
+
:carrierwave_integrity_error => 'tipo de imagem não permitido.'
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}) do
|
163
|
+
@doc.should_not be_valid
|
164
|
+
@doc.errors[:image].should == ['tipo de imagem não permitido.']
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
pending 'when validating processing' do
|
170
|
+
before do
|
171
|
+
mongo_user_klass = reset_mongo_class(ProcessingErrorUploader)
|
172
|
+
@doc = mongo_user_klass.new
|
173
|
+
@doc.image = stub_file('test.jpg')
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should make the document invalid when a processing error occurs" do
|
177
|
+
@doc.should_not be_valid
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should use I18n for processing error messages" do
|
181
|
+
@doc.valid?
|
182
|
+
@doc.errors[:image].should == ['failed to be processed']
|
183
|
+
|
184
|
+
change_locale_and_store_translations(:pt, :activemodel => {
|
185
|
+
:errors => {
|
186
|
+
:messages => {
|
187
|
+
:carrierwave_processing_error => 'falha ao processar imagem.'
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}) do
|
191
|
+
@doc.should_not be_valid
|
192
|
+
@doc.errors[:image].should == ['falha ao processar imagem.']
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#save" do
|
200
|
+
|
201
|
+
before do
|
202
|
+
mongo_user_klass = reset_mongo_class
|
203
|
+
@doc = mongo_user_klass.new
|
204
|
+
end
|
205
|
+
|
206
|
+
context "when no file is assigned" do
|
207
|
+
|
208
|
+
it "image is blank" do
|
209
|
+
@doc.save
|
210
|
+
@doc.image.should be_blank
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
context "when a file is assigned" do
|
216
|
+
|
217
|
+
it "copies the file to the upload directory" do
|
218
|
+
@doc.image = stub_file('test.jpg')
|
219
|
+
@doc.save
|
220
|
+
@doc.image.should be_an_instance_of(MongoUploader)
|
221
|
+
@doc.image.current_path.should == public_path('uploads/test.jpg')
|
222
|
+
end
|
223
|
+
|
224
|
+
it "saves the filename in the database" do
|
225
|
+
@doc.image = stub_file('test.jpg')
|
226
|
+
@doc.save
|
227
|
+
@doc.image_filename.should == 'test.jpg'
|
228
|
+
end
|
229
|
+
|
230
|
+
context "when remove_image? is true" do
|
231
|
+
|
232
|
+
it "removes the image" do
|
233
|
+
@doc.image = stub_file('test.jpeg')
|
234
|
+
@doc.save
|
235
|
+
@doc.remove_image = true
|
236
|
+
@doc.save
|
237
|
+
@doc.reload
|
238
|
+
@doc.image.should be_blank
|
239
|
+
@doc.image_filename.should == ''
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
describe '#destroy' do
|
249
|
+
|
250
|
+
before do
|
251
|
+
mongo_user_klass = reset_mongo_class
|
252
|
+
@doc = mongo_user_klass.new
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "when file assigned" do
|
256
|
+
|
257
|
+
it "removes the file from the filesystem" do
|
258
|
+
@doc.image = stub_file('test.jpeg')
|
259
|
+
@doc.save.should be_true
|
260
|
+
File.exist?(public_path('uploads/test.jpeg')).should be_true
|
261
|
+
@doc.image.should be_an_instance_of(MongoUploader)
|
262
|
+
@doc.image.current_path.should == public_path('uploads/test.jpeg')
|
263
|
+
@doc.destroy
|
264
|
+
File.exist?(public_path('uploads/test.jpeg')).should be_false
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "when file is not assigned" do
|
270
|
+
|
271
|
+
it "deletes the instance of MongoUser after save" do
|
272
|
+
@doc.save
|
273
|
+
MongoUser.count.should eql(1)
|
274
|
+
@doc.destroy
|
275
|
+
end
|
276
|
+
|
277
|
+
it "deletes the instance of MongoUser after save and then re-looking up the instance" do
|
278
|
+
@doc.save
|
279
|
+
MongoUser.count.should eql(1)
|
280
|
+
@doc = MongoUser.first
|
281
|
+
@doc.destroy
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
this is stuff
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
require 'tempfile'
|
7
|
+
require 'time'
|
8
|
+
require 'logger'
|
9
|
+
|
10
|
+
require 'carrierwave'
|
11
|
+
require 'timecop'
|
12
|
+
|
13
|
+
alias :running :lambda
|
14
|
+
|
15
|
+
def file_path( *paths )
|
16
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
17
|
+
end
|
18
|
+
|
19
|
+
def public_path( *paths )
|
20
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
|
21
|
+
end
|
22
|
+
|
23
|
+
CarrierWave.root = public_path
|
24
|
+
|
25
|
+
module CarrierWave
|
26
|
+
module Test
|
27
|
+
module MockStorage
|
28
|
+
def mock_storage(kind)
|
29
|
+
storage = mock("storage for #{kind} uploader")
|
30
|
+
storage.stub!(:setup!)
|
31
|
+
storage
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module MockFiles
|
36
|
+
def stub_merb_tempfile(filename)
|
37
|
+
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
38
|
+
|
39
|
+
t = Tempfile.new(filename)
|
40
|
+
FileUtils.copy_file(file_path(filename), t.path)
|
41
|
+
|
42
|
+
return t
|
43
|
+
end
|
44
|
+
|
45
|
+
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
46
|
+
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
47
|
+
|
48
|
+
t = Tempfile.new(filename)
|
49
|
+
FileUtils.copy_file(file_path(filename), t.path)
|
50
|
+
|
51
|
+
# This is stupid, but for some reason rspec won't play nice...
|
52
|
+
eval <<-EOF
|
53
|
+
def t.original_filename; '#{fake_name || filename}'; end
|
54
|
+
def t.content_type; '#{mime_type}'; end
|
55
|
+
def t.local_path; path; end
|
56
|
+
EOF
|
57
|
+
|
58
|
+
return t
|
59
|
+
end
|
60
|
+
|
61
|
+
def stub_stringio(filename, mime_type=nil, fake_name=nil)
|
62
|
+
if filename
|
63
|
+
t = StringIO.new( IO.read( file_path( filename ) ) )
|
64
|
+
else
|
65
|
+
t = StringIO.new
|
66
|
+
end
|
67
|
+
t.stub!(:local_path).and_return("")
|
68
|
+
t.stub!(:original_filename).and_return(filename || fake_name)
|
69
|
+
t.stub!(:content_type).and_return(mime_type)
|
70
|
+
return t
|
71
|
+
end
|
72
|
+
|
73
|
+
def stub_file(filename, mime_type=nil, fake_name=nil)
|
74
|
+
f = File.open(file_path(filename))
|
75
|
+
return f
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module I18nHelpers
|
80
|
+
def change_locale_and_store_translations(locale, translations, &block)
|
81
|
+
current_locale = I18n.locale
|
82
|
+
begin
|
83
|
+
I18n.backend.store_translations locale, translations
|
84
|
+
I18n.locale = locale
|
85
|
+
yield
|
86
|
+
ensure
|
87
|
+
I18n.reload!
|
88
|
+
I18n.locale = current_locale
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
RSpec.configure do |config|
|
96
|
+
config.include CarrierWave::Test::Matchers
|
97
|
+
config.include CarrierWave::Test::MockFiles
|
98
|
+
config.include CarrierWave::Test::MockStorage
|
99
|
+
config.include CarrierWave::Test::I18nHelpers
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mm-carrierwave
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Robert Beekman
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-21 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
version: 2.1.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: mini_magick
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 5
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 3
|
65
|
+
version: "2.3"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: bson_ext
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - "="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 25
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 1
|
80
|
+
- 5
|
81
|
+
version: 1.1.5
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: carrierwave
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: activemodel
|
100
|
+
prerelease: false
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
type: :development
|
111
|
+
version_requirements: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: mongo_mapper
|
114
|
+
prerelease: false
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
type: :development
|
125
|
+
version_requirements: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: timecop
|
128
|
+
prerelease: false
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
type: :development
|
139
|
+
version_requirements: *id008
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: json
|
142
|
+
prerelease: false
|
143
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
type: :development
|
153
|
+
version_requirements: *id009
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: jnunemaker-validatable
|
156
|
+
prerelease: false
|
157
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: "0"
|
166
|
+
type: :development
|
167
|
+
version_requirements: *id010
|
168
|
+
description: Mongomapper ORM for Carrierwave
|
169
|
+
email:
|
170
|
+
- robert@80beans.com
|
171
|
+
executables: []
|
172
|
+
|
173
|
+
extensions: []
|
174
|
+
|
175
|
+
extra_rdoc_files: []
|
176
|
+
|
177
|
+
files:
|
178
|
+
- .gitignore
|
179
|
+
- Gemfile
|
180
|
+
- Gemfile.lock
|
181
|
+
- README.textile
|
182
|
+
- Rakefile
|
183
|
+
- lib/carrierwave/orm/mongomapper.rb
|
184
|
+
- lib/version.rb
|
185
|
+
- mm-carrierwave.gemspec
|
186
|
+
- spec/fixtures/bork.txt
|
187
|
+
- spec/fixtures/landscape.jpg
|
188
|
+
- spec/fixtures/portrait.jpg
|
189
|
+
- spec/fixtures/test.jpeg
|
190
|
+
- spec/fixtures/test.jpg
|
191
|
+
- spec/lib/carrierwave/orm/mongomapper_spec.rb
|
192
|
+
- spec/public/uploads/test.jpg
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
has_rdoc: true
|
195
|
+
homepage: ""
|
196
|
+
licenses: []
|
197
|
+
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
none: false
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
hash: 3
|
209
|
+
segments:
|
210
|
+
- 0
|
211
|
+
version: "0"
|
212
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
|
+
none: false
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
hash: 3
|
218
|
+
segments:
|
219
|
+
- 0
|
220
|
+
version: "0"
|
221
|
+
requirements: []
|
222
|
+
|
223
|
+
rubyforge_project:
|
224
|
+
rubygems_version: 1.3.7
|
225
|
+
signing_key:
|
226
|
+
specification_version: 3
|
227
|
+
summary: Mongomapper ORM for Carrierwave
|
228
|
+
test_files:
|
229
|
+
- spec/fixtures/bork.txt
|
230
|
+
- spec/fixtures/landscape.jpg
|
231
|
+
- spec/fixtures/portrait.jpg
|
232
|
+
- spec/fixtures/test.jpeg
|
233
|
+
- spec/fixtures/test.jpg
|
234
|
+
- spec/lib/carrierwave/orm/mongomapper_spec.rb
|
235
|
+
- spec/public/uploads/test.jpg
|
236
|
+
- spec/spec_helper.rb
|