oahu-dragonfly 0.8.2
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/.rspec +1 -0
- data/.yardopts +24 -0
- data/Gemfile +30 -0
- data/History.md +323 -0
- data/LICENSE +20 -0
- data/README.md +88 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/config.ru +14 -0
- data/docs.watchr +1 -0
- data/dragonfly.gemspec +297 -0
- data/extra_docs/Analysers.md +66 -0
- data/extra_docs/Caching.md +23 -0
- data/extra_docs/Configuration.md +124 -0
- data/extra_docs/Couch.md +49 -0
- data/extra_docs/DataStorage.md +153 -0
- data/extra_docs/Encoding.md +67 -0
- data/extra_docs/GeneralUsage.md +121 -0
- data/extra_docs/Generators.md +60 -0
- data/extra_docs/Heroku.md +50 -0
- data/extra_docs/ImageMagick.md +125 -0
- data/extra_docs/Index.md +33 -0
- data/extra_docs/MimeTypes.md +40 -0
- data/extra_docs/Models.md +272 -0
- data/extra_docs/Mongo.md +45 -0
- data/extra_docs/Processing.md +77 -0
- data/extra_docs/Rack.md +52 -0
- data/extra_docs/Rails2.md +57 -0
- data/extra_docs/Rails3.md +62 -0
- data/extra_docs/Sinatra.md +25 -0
- data/extra_docs/URLs.md +169 -0
- data/features/images.feature +47 -0
- data/features/no_processing.feature +14 -0
- data/features/rails_3.0.5.feature +8 -0
- data/features/steps/common_steps.rb +8 -0
- data/features/steps/dragonfly_steps.rb +66 -0
- data/features/steps/rails_steps.rb +28 -0
- data/features/support/env.rb +13 -0
- data/features/support/setup.rb +32 -0
- data/fixtures/rails_3.0.5/files/app/models/album.rb +7 -0
- data/fixtures/rails_3.0.5/files/app/views/albums/new.html.erb +7 -0
- data/fixtures/rails_3.0.5/files/app/views/albums/show.html.erb +6 -0
- data/fixtures/rails_3.0.5/files/config/initializers/dragonfly.rb +4 -0
- data/fixtures/rails_3.0.5/files/features/manage_album_images.feature +38 -0
- data/fixtures/rails_3.0.5/files/features/step_definitions/helper_steps.rb +7 -0
- data/fixtures/rails_3.0.5/files/features/step_definitions/image_steps.rb +25 -0
- data/fixtures/rails_3.0.5/files/features/support/paths.rb +17 -0
- data/fixtures/rails_3.0.5/files/features/text_images.feature +7 -0
- data/fixtures/rails_3.0.5/template.rb +20 -0
- data/irbrc.rb +18 -0
- data/lib/dragonfly.rb +55 -0
- data/lib/dragonfly/active_model_extensions.rb +13 -0
- data/lib/dragonfly/active_model_extensions/attachment.rb +250 -0
- data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +148 -0
- data/lib/dragonfly/active_model_extensions/class_methods.rb +95 -0
- data/lib/dragonfly/active_model_extensions/instance_methods.rb +28 -0
- data/lib/dragonfly/active_model_extensions/validations.rb +41 -0
- data/lib/dragonfly/analyser.rb +58 -0
- data/lib/dragonfly/analysis/file_command_analyser.rb +32 -0
- data/lib/dragonfly/analysis/image_magick_analyser.rb +6 -0
- data/lib/dragonfly/app.rb +172 -0
- data/lib/dragonfly/config/heroku.rb +19 -0
- data/lib/dragonfly/config/image_magick.rb +6 -0
- data/lib/dragonfly/config/rails.rb +20 -0
- data/lib/dragonfly/configurable.rb +207 -0
- data/lib/dragonfly/core_ext/array.rb +7 -0
- data/lib/dragonfly/core_ext/hash.rb +7 -0
- data/lib/dragonfly/core_ext/object.rb +12 -0
- data/lib/dragonfly/core_ext/string.rb +9 -0
- data/lib/dragonfly/core_ext/symbol.rb +9 -0
- data/lib/dragonfly/data_storage.rb +9 -0
- data/lib/dragonfly/data_storage/couch_data_store.rb +64 -0
- data/lib/dragonfly/data_storage/file_data_store.rb +141 -0
- data/lib/dragonfly/data_storage/mongo_data_store.rb +86 -0
- data/lib/dragonfly/data_storage/s3data_store.rb +145 -0
- data/lib/dragonfly/encoder.rb +13 -0
- data/lib/dragonfly/encoding/image_magick_encoder.rb +6 -0
- data/lib/dragonfly/function_manager.rb +71 -0
- data/lib/dragonfly/generation/image_magick_generator.rb +6 -0
- data/lib/dragonfly/generator.rb +9 -0
- data/lib/dragonfly/hash_with_css_style_keys.rb +21 -0
- data/lib/dragonfly/image_magick/analyser.rb +51 -0
- data/lib/dragonfly/image_magick/config.rb +41 -0
- data/lib/dragonfly/image_magick/encoder.rb +57 -0
- data/lib/dragonfly/image_magick/generator.rb +145 -0
- data/lib/dragonfly/image_magick/processor.rb +99 -0
- data/lib/dragonfly/image_magick/utils.rb +72 -0
- data/lib/dragonfly/image_magick_utils.rb +4 -0
- data/lib/dragonfly/job.rb +451 -0
- data/lib/dragonfly/job_builder.rb +39 -0
- data/lib/dragonfly/job_definitions.rb +26 -0
- data/lib/dragonfly/job_endpoint.rb +15 -0
- data/lib/dragonfly/loggable.rb +28 -0
- data/lib/dragonfly/middleware.rb +20 -0
- data/lib/dragonfly/processing/image_magick_processor.rb +6 -0
- data/lib/dragonfly/processor.rb +9 -0
- data/lib/dragonfly/rails/images.rb +27 -0
- data/lib/dragonfly/response.rb +97 -0
- data/lib/dragonfly/routed_endpoint.rb +40 -0
- data/lib/dragonfly/serializer.rb +32 -0
- data/lib/dragonfly/server.rb +113 -0
- data/lib/dragonfly/simple_cache.rb +23 -0
- data/lib/dragonfly/temp_object.rb +175 -0
- data/lib/dragonfly/url_mapper.rb +78 -0
- data/samples/beach.png +0 -0
- data/samples/egg.png +0 -0
- data/samples/round.gif +0 -0
- data/samples/sample.docx +0 -0
- data/samples/taj.jpg +0 -0
- data/spec/dragonfly/active_model_extensions/model_spec.rb +1426 -0
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +91 -0
- data/spec/dragonfly/analyser_spec.rb +123 -0
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +48 -0
- data/spec/dragonfly/app_spec.rb +135 -0
- data/spec/dragonfly/configurable_spec.rb +461 -0
- data/spec/dragonfly/core_ext/array_spec.rb +19 -0
- data/spec/dragonfly/core_ext/hash_spec.rb +19 -0
- data/spec/dragonfly/core_ext/string_spec.rb +17 -0
- data/spec/dragonfly/core_ext/symbol_spec.rb +17 -0
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +76 -0
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +296 -0
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +57 -0
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +258 -0
- data/spec/dragonfly/data_storage/shared_data_store_examples.rb +77 -0
- data/spec/dragonfly/function_manager_spec.rb +154 -0
- data/spec/dragonfly/hash_with_css_style_keys_spec.rb +24 -0
- data/spec/dragonfly/image_magick/analyser_spec.rb +64 -0
- data/spec/dragonfly/image_magick/encoder_spec.rb +41 -0
- data/spec/dragonfly/image_magick/generator_spec.rb +172 -0
- data/spec/dragonfly/image_magick/processor_spec.rb +233 -0
- data/spec/dragonfly/image_magick/utils_spec.rb +18 -0
- data/spec/dragonfly/job_builder_spec.rb +37 -0
- data/spec/dragonfly/job_definitions_spec.rb +35 -0
- data/spec/dragonfly/job_endpoint_spec.rb +173 -0
- data/spec/dragonfly/job_spec.rb +1046 -0
- data/spec/dragonfly/loggable_spec.rb +80 -0
- data/spec/dragonfly/middleware_spec.rb +47 -0
- data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
- data/spec/dragonfly/serializer_spec.rb +61 -0
- data/spec/dragonfly/server_spec.rb +278 -0
- data/spec/dragonfly/simple_cache_spec.rb +27 -0
- data/spec/dragonfly/temp_object_spec.rb +306 -0
- data/spec/dragonfly/url_mapper_spec.rb +126 -0
- data/spec/functional/deprecations_spec.rb +51 -0
- data/spec/functional/image_magick_app_spec.rb +27 -0
- data/spec/functional/model_urls_spec.rb +85 -0
- data/spec/functional/remote_on_the_fly_spec.rb +51 -0
- data/spec/functional/to_response_spec.rb +31 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/argument_matchers.rb +19 -0
- data/spec/support/image_matchers.rb +47 -0
- data/spec/support/simple_matchers.rb +53 -0
- data/yard/handlers/configurable_attr_handler.rb +38 -0
- data/yard/setup.rb +15 -0
- data/yard/templates/default/fulldoc/html/css/common.css +107 -0
- data/yard/templates/default/layout/html/layout.erb +89 -0
- data/yard/templates/default/module/html/configuration_summary.erb +31 -0
- data/yard/templates/default/module/setup.rb +17 -0
- metadata +544 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dragonfly::SimpleCache do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@cache = Dragonfly::SimpleCache.new(2)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should act as a normal hash" do
|
|
10
|
+
@cache[:egg] = 'four'
|
|
11
|
+
@cache[:egg].should == 'four'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should allow filling up to the limit" do
|
|
15
|
+
@cache[:a] = 1
|
|
16
|
+
@cache[:b] = 2
|
|
17
|
+
@cache.should == {:a => 1, :b => 2}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should get rid of the first added when full" do
|
|
21
|
+
@cache[:a] = 1
|
|
22
|
+
@cache[:b] = 2
|
|
23
|
+
@cache[:c] = 3
|
|
24
|
+
@cache.should == {:b => 2, :c => 3}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dragonfly::TempObject do
|
|
4
|
+
|
|
5
|
+
####### Helper Methods #######
|
|
6
|
+
|
|
7
|
+
def sample_path(filename)
|
|
8
|
+
File.join(SAMPLES_DIR, filename)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new_tempfile(data='HELLO')
|
|
12
|
+
tempfile = Tempfile.new('test')
|
|
13
|
+
tempfile.write(data)
|
|
14
|
+
tempfile.rewind
|
|
15
|
+
tempfile
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def new_file(data='HELLO', path="/tmp/test_file")
|
|
19
|
+
File.open(path, 'w') do |f|
|
|
20
|
+
f.write(data)
|
|
21
|
+
end
|
|
22
|
+
File.new(path)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def new_pathname(data='HELLO', path="/tmp/test_file")
|
|
26
|
+
File.open(path, 'w') do |f|
|
|
27
|
+
f.write(data)
|
|
28
|
+
end
|
|
29
|
+
Pathname.new(path)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def new_temp_object(data, klass=Dragonfly::TempObject)
|
|
33
|
+
klass.new(initialization_object(data))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def initialization_object(data)
|
|
37
|
+
raise NotImplementedError, "This should be implemented in the describe block!"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def get_parts(temp_object)
|
|
41
|
+
parts = []
|
|
42
|
+
temp_object.each do |bytes|
|
|
43
|
+
parts << bytes
|
|
44
|
+
end
|
|
45
|
+
parts.length.should >= 2 # Sanity check to check that the sample file is adequate for this test
|
|
46
|
+
parts
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
###############################
|
|
50
|
+
|
|
51
|
+
it "should raise an error if initialized with a non-string/file/tempfile" do
|
|
52
|
+
lambda{
|
|
53
|
+
Dragonfly::TempObject.new(3)
|
|
54
|
+
}.should raise_error(ArgumentError)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
shared_examples_for "common behaviour" do
|
|
58
|
+
|
|
59
|
+
describe "simple initialization" do
|
|
60
|
+
|
|
61
|
+
before(:each) do
|
|
62
|
+
@temp_object = new_temp_object('HELLO')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "data" do
|
|
66
|
+
it "should return the data correctly" do
|
|
67
|
+
@temp_object.data.should == 'HELLO'
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "file" do
|
|
72
|
+
it "should return a readable file" do
|
|
73
|
+
@temp_object.file.should be_a(File)
|
|
74
|
+
end
|
|
75
|
+
it "should contain the correct data" do
|
|
76
|
+
@temp_object.file.read.should == 'HELLO'
|
|
77
|
+
end
|
|
78
|
+
it "should yield a file then close it if a block is given" do
|
|
79
|
+
@temp_object.file do |f|
|
|
80
|
+
f.read.should == 'HELLO'
|
|
81
|
+
f.should_receive :close
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
it "should return whatever is returned from the block if a block is given" do
|
|
85
|
+
@temp_object.file do |f|
|
|
86
|
+
'doogie'
|
|
87
|
+
end.should == 'doogie'
|
|
88
|
+
end
|
|
89
|
+
it "should enable reading the file twice" do
|
|
90
|
+
@temp_object.file{|f| f.read }.should == "HELLO"
|
|
91
|
+
@temp_object.file{|f| f.read }.should == "HELLO"
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "tempfile" do
|
|
96
|
+
it "should create a closed tempfile" do
|
|
97
|
+
@temp_object.tempfile.should be_a(Tempfile)
|
|
98
|
+
@temp_object.tempfile.should be_closed
|
|
99
|
+
end
|
|
100
|
+
it "should contain the correct data" do
|
|
101
|
+
@temp_object.tempfile.open.read.should == 'HELLO'
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "path" do
|
|
106
|
+
it "should return an absolute file path" do
|
|
107
|
+
@temp_object.path.should =~ %r{^/\w+}
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe "size" do
|
|
112
|
+
it "should return the size in bytes" do
|
|
113
|
+
@temp_object.size.should == 5
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe "to_file" do
|
|
118
|
+
before(:each) do
|
|
119
|
+
@filename = 'eggnog.txt'
|
|
120
|
+
FileUtils.rm(@filename) if File.exists?(@filename)
|
|
121
|
+
end
|
|
122
|
+
after(:each) do
|
|
123
|
+
FileUtils.rm(@filename) if File.exists?(@filename)
|
|
124
|
+
end
|
|
125
|
+
it "should write to a file" do
|
|
126
|
+
@temp_object.to_file(@filename)
|
|
127
|
+
File.exists?(@filename).should be_true
|
|
128
|
+
end
|
|
129
|
+
it "should write the correct data to the file" do
|
|
130
|
+
@temp_object.to_file(@filename)
|
|
131
|
+
File.read(@filename).should == 'HELLO'
|
|
132
|
+
end
|
|
133
|
+
it "should return a readable file" do
|
|
134
|
+
file = @temp_object.to_file(@filename)
|
|
135
|
+
file.should be_a(File)
|
|
136
|
+
file.read.should == 'HELLO'
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
describe "each" do
|
|
143
|
+
it "should yield 8192 bytes each time" do
|
|
144
|
+
temp_object = new_temp_object(File.read(sample_path('round.gif')))
|
|
145
|
+
parts = get_parts(temp_object)
|
|
146
|
+
parts[0...-1].each do |part|
|
|
147
|
+
part.bytesize.should == 8192
|
|
148
|
+
end
|
|
149
|
+
parts.last.bytesize.should <= 8192
|
|
150
|
+
end
|
|
151
|
+
it "should yield the number of bytes specified in the class configuration" do
|
|
152
|
+
klass = Class.new(Dragonfly::TempObject)
|
|
153
|
+
temp_object = new_temp_object(File.read(sample_path('round.gif')), klass)
|
|
154
|
+
klass.block_size = 3001
|
|
155
|
+
parts = get_parts(temp_object)
|
|
156
|
+
parts[0...-1].each do |part|
|
|
157
|
+
part.length.should == 3001
|
|
158
|
+
end
|
|
159
|
+
parts.last.length.should <= 3001
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe "initializing from a string" do
|
|
166
|
+
|
|
167
|
+
def initialization_object(data)
|
|
168
|
+
data
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it_should_behave_like "common behaviour"
|
|
172
|
+
|
|
173
|
+
it "should not create a file when calling each" do
|
|
174
|
+
temp_object = new_temp_object('HELLO')
|
|
175
|
+
temp_object.should_not_receive(:tempfile)
|
|
176
|
+
temp_object.each{}
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe "initializing from a tempfile" do
|
|
181
|
+
|
|
182
|
+
def initialization_object(data)
|
|
183
|
+
new_tempfile(data)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it_should_behave_like "common behaviour"
|
|
187
|
+
|
|
188
|
+
it "should not create a data string when calling each" do
|
|
189
|
+
temp_object = new_temp_object('HELLO')
|
|
190
|
+
temp_object.should_not_receive(:data)
|
|
191
|
+
temp_object.each{}
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "should return the tempfile's path" do
|
|
195
|
+
temp_object = new_temp_object('HELLO')
|
|
196
|
+
temp_object.path.should == temp_object.tempfile.path
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
describe "initializing from a file" do
|
|
201
|
+
|
|
202
|
+
def initialization_object(data)
|
|
203
|
+
new_file(data)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it_should_behave_like "common behaviour"
|
|
207
|
+
|
|
208
|
+
it "should not create a data string when calling each" do
|
|
209
|
+
temp_object = new_temp_object('HELLO')
|
|
210
|
+
temp_object.should_not_receive(:data)
|
|
211
|
+
temp_object.each{}
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "should return the file's path" do
|
|
215
|
+
file = new_file('HELLO')
|
|
216
|
+
temp_object = Dragonfly::TempObject.new(file)
|
|
217
|
+
temp_object.path.should == file.path
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should return an absolute path even if the file wasn't instantiated like that" do
|
|
221
|
+
file = new_file('HELLO', 'testfile')
|
|
222
|
+
temp_object = Dragonfly::TempObject.new(file)
|
|
223
|
+
temp_object.path.should =~ %r{^/\w.*testfile}
|
|
224
|
+
file.close
|
|
225
|
+
FileUtils.rm(file.path)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
describe "initializing from a pathname" do
|
|
230
|
+
|
|
231
|
+
def initialization_object(data)
|
|
232
|
+
new_pathname(data)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it_should_behave_like "common behaviour"
|
|
236
|
+
|
|
237
|
+
it "should not create a data string when calling each" do
|
|
238
|
+
temp_object = new_temp_object('HELLO')
|
|
239
|
+
temp_object.should_not_receive(:data)
|
|
240
|
+
temp_object.each{}
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it "should return the file's path" do
|
|
244
|
+
pathname = new_pathname('HELLO')
|
|
245
|
+
temp_object = Dragonfly::TempObject.new(pathname)
|
|
246
|
+
temp_object.path.should == pathname.to_s
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "should return an absolute path even if the pathname is relative" do
|
|
250
|
+
pathname = new_pathname('HELLO', 'testfile')
|
|
251
|
+
temp_object = Dragonfly::TempObject.new(pathname)
|
|
252
|
+
temp_object.path.should =~ %r{^/\w.*testfile}
|
|
253
|
+
pathname.delete
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe "initializing from another temp object" do
|
|
258
|
+
|
|
259
|
+
def initialization_object(data)
|
|
260
|
+
Dragonfly::TempObject.new(data)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
before(:each) do
|
|
264
|
+
@temp_object1 = Dragonfly::TempObject.new(new_tempfile('hello'))
|
|
265
|
+
@temp_object2 = Dragonfly::TempObject.new(@temp_object1)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it_should_behave_like "common behaviour"
|
|
269
|
+
|
|
270
|
+
it "should not be the same object" do
|
|
271
|
+
@temp_object1.should_not == @temp_object2
|
|
272
|
+
end
|
|
273
|
+
it "should have the same data" do
|
|
274
|
+
@temp_object1.data.should == @temp_object2.data
|
|
275
|
+
end
|
|
276
|
+
it "should have the same file path" do
|
|
277
|
+
@temp_object1.path.should == @temp_object2.path
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
describe "original_filename" do
|
|
282
|
+
before(:each) do
|
|
283
|
+
@obj = new_tempfile
|
|
284
|
+
end
|
|
285
|
+
it "should set the original_filename if the initial object responds to 'original filename'" do
|
|
286
|
+
def @obj.original_filename
|
|
287
|
+
'jimmy.page'
|
|
288
|
+
end
|
|
289
|
+
Dragonfly::TempObject.new(@obj).original_filename.should == 'jimmy.page'
|
|
290
|
+
end
|
|
291
|
+
it "should not set the name if the initial object doesn't respond to 'original filename'" do
|
|
292
|
+
Dragonfly::TempObject.new(@obj).original_filename.should be_nil
|
|
293
|
+
end
|
|
294
|
+
it "should set the name if the initial object is a file object" do
|
|
295
|
+
file = File.new(SAMPLES_DIR + '/round.gif')
|
|
296
|
+
temp_object = Dragonfly::TempObject.new(file)
|
|
297
|
+
temp_object.original_filename.should == 'round.gif'
|
|
298
|
+
end
|
|
299
|
+
it "should set the name if the initial object is a pathname" do
|
|
300
|
+
pathname = Pathname.new(SAMPLES_DIR + '/round.gif')
|
|
301
|
+
temp_object = Dragonfly::TempObject.new(pathname)
|
|
302
|
+
temp_object.original_filename.should == 'round.gif'
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Dragonfly::UrlMapper do
|
|
5
|
+
|
|
6
|
+
describe "validating the url format" do
|
|
7
|
+
it "should be ok with a valid one" do
|
|
8
|
+
Dragonfly::UrlMapper.new('/media/:job/:name')
|
|
9
|
+
end
|
|
10
|
+
it "should throw an error if params aren't separated" do
|
|
11
|
+
lambda{
|
|
12
|
+
Dragonfly::UrlMapper.new('/media/:job:name')
|
|
13
|
+
}.should raise_error(Dragonfly::UrlMapper::BadUrlFormat)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "params_in_url" do
|
|
18
|
+
it "should return everything specified in the url" do
|
|
19
|
+
url_mapper = Dragonfly::UrlMapper.new('/media/:job/:basename.:ext')
|
|
20
|
+
url_mapper.params_in_url.should == ['job', 'basename', 'ext']
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "url_regexp" do
|
|
25
|
+
it "should return a regexp with non-greedy optional groups that include the preceding slash/dot/dash" do
|
|
26
|
+
url_mapper = Dragonfly::UrlMapper.new('/media/:job/:basename-:size.:format')
|
|
27
|
+
url_mapper.url_regexp.should == %r{^/media(/[^\/\-\.]+?)?(/[^\/\-\.]+?)?(\-[^\/\-\.]+?)?(\.[^\/\-\.]+?)?$}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should allow setting custom patterns in the url" do
|
|
31
|
+
url_mapper = Dragonfly::UrlMapper.new('/media/:job-:size.:format',
|
|
32
|
+
:job => '\w',
|
|
33
|
+
:size => '\d',
|
|
34
|
+
:format => '[^\.]'
|
|
35
|
+
)
|
|
36
|
+
url_mapper.url_regexp.should == %r{^/media(/\w+?)?(\-\d+?)?(\.[^\.]+?)?$}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should make optional match patterns (ending in ?) apply to the whole group including the preceding seperator" do
|
|
40
|
+
url_mapper = Dragonfly::UrlMapper.new('/media/:job', :job => '\w')
|
|
41
|
+
url_mapper.url_regexp.should == %r{^/media(/\w+?)?$}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "url_for" do
|
|
46
|
+
before(:each) do
|
|
47
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:job-:size',
|
|
48
|
+
:job => '\w',
|
|
49
|
+
:size => '\w'
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should map correctly" do
|
|
54
|
+
@url_mapper.url_for('job' => 'asdf', 'size' => '30x30').should == '/media/asdf-30x30'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should add extra params as query parameters" do
|
|
58
|
+
@url_mapper.url_for('job' => 'asdf', 'size' => '30x30', 'when' => 'now').should == '/media/asdf-30x30?when=now'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should not worry if params aren't given" do
|
|
62
|
+
@url_mapper.url_for('job' => 'asdf', 'when' => 'now', 'then' => 'soon').should == '/media/asdf?when=now&then=soon'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "params_for" do
|
|
67
|
+
before(:each) do
|
|
68
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:job')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should map correctly" do
|
|
72
|
+
@url_mapper.params_for('/media/asdf').should == {'job' => 'asdf'}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should include query parameters" do
|
|
76
|
+
@url_mapper.params_for('/media/asdf', 'when=now').should == {'job' => 'asdf', 'when' => 'now'}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should generally be ok with wierd characters" do
|
|
80
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:doobie')
|
|
81
|
+
@url_mapper.params_for('/media/sd sdf jl£@$ sdf:_', 'job=goodun').should == {'job' => 'goodun', 'doobie' => 'sd sdf jl£@$ sdf:_'}
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "matching urls with standard format /media/:job/:basename.:format" do
|
|
86
|
+
before(:each) do
|
|
87
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:job/:basename.:format',
|
|
88
|
+
:job => '\w',
|
|
89
|
+
:basename => '[^\/]',
|
|
90
|
+
:format => '[^\.]'
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
{
|
|
95
|
+
'' => nil,
|
|
96
|
+
'/' => nil,
|
|
97
|
+
'/media' => {'job' => nil, 'basename' => nil, 'format' => nil},
|
|
98
|
+
'/media/' => nil,
|
|
99
|
+
'/moodia/asdf' => nil,
|
|
100
|
+
'/media/asdf/' => nil,
|
|
101
|
+
'/mount/media/asdf' => nil,
|
|
102
|
+
'/media/asdf/stuff.egg' => {'job' => 'asdf', 'basename' => 'stuff', 'format' => 'egg'},
|
|
103
|
+
'/media/asdf' => {'job' => 'asdf', 'basename' => nil, 'format' => nil},
|
|
104
|
+
'/media/asdf/stuff' => {'job' => 'asdf', 'basename' => 'stuff', 'format' => nil},
|
|
105
|
+
'/media/asdf.egg' => {'job' => 'asdf', 'basename' => nil, 'format' => 'egg'},
|
|
106
|
+
'/media/asdf/stuff/egg' => nil,
|
|
107
|
+
'/media/asdf/stuff.dog.egg' => {'job' => 'asdf', 'basename' => 'stuff.dog', 'format' => 'egg'},
|
|
108
|
+
'/media/asdf/s=2 -.d.e' => {'job' => 'asdf', 'basename' => 's=2 -.d', 'format' => 'e'},
|
|
109
|
+
'/media/asdf-40x40/stuff.egg' => nil
|
|
110
|
+
}.each do |path, params|
|
|
111
|
+
|
|
112
|
+
it "should turn the url #{path} into params #{params.inspect}" do
|
|
113
|
+
@url_mapper.params_for(path).should == params
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
if params
|
|
117
|
+
it "should turn the params #{params.inspect} into url #{path}" do
|
|
118
|
+
@url_mapper.url_for(params).should == path
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|