dragonfly 0.8.6 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- data/{.specopts → .rspec} +0 -1
- data/.yardopts +6 -2
- data/Gemfile +14 -13
- data/History.md +47 -9
- data/README.md +25 -5
- data/Rakefile +37 -79
- data/VERSION +1 -1
- data/dragonfly.gemspec +140 -89
- data/extra_docs/Analysers.md +8 -48
- data/extra_docs/Configuration.md +40 -25
- data/extra_docs/Couch.md +49 -0
- data/extra_docs/DataStorage.md +94 -24
- data/extra_docs/Encoding.md +6 -35
- data/extra_docs/ExampleUseCases.md +113 -0
- data/extra_docs/GeneralUsage.md +7 -23
- data/extra_docs/Generators.md +15 -49
- data/extra_docs/Heroku.md +7 -8
- data/extra_docs/ImageMagick.md +126 -0
- data/extra_docs/MimeTypes.md +3 -3
- data/extra_docs/Models.md +163 -0
- data/extra_docs/Mongo.md +1 -4
- data/extra_docs/Processing.md +7 -60
- data/extra_docs/Rails2.md +3 -1
- data/extra_docs/Rails3.md +2 -10
- data/extra_docs/ServingRemotely.md +83 -0
- data/extra_docs/Sinatra.md +3 -3
- data/extra_docs/URLs.md +60 -33
- data/features/rails_3.0.5.feature +8 -0
- data/features/steps/rails_steps.rb +7 -18
- data/features/support/env.rb +10 -37
- data/features/support/setup.rb +32 -0
- data/fixtures/rails_3.0.5/files/app/models/album.rb +5 -0
- data/fixtures/rails_3.0.5/files/app/views/albums/new.html.erb +7 -0
- data/fixtures/{files → rails_3.0.5/files}/app/views/albums/show.html.erb +2 -0
- data/fixtures/{files → rails_3.0.5/files}/config/initializers/dragonfly.rb +0 -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/{files → rails_3.0.5/files}/features/step_definitions/image_steps.rb +11 -1
- data/fixtures/{files → rails_3.0.5/files}/features/support/paths.rb +2 -0
- data/fixtures/{files → rails_3.0.5/files}/features/text_images.feature +0 -0
- data/fixtures/{rails_3.0.3 → rails_3.0.5}/template.rb +2 -2
- data/irbrc.rb +2 -1
- data/lib/dragonfly.rb +7 -0
- data/lib/dragonfly/active_model_extensions/attachment.rb +134 -46
- data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +144 -0
- data/lib/dragonfly/active_model_extensions/class_methods.rb +62 -9
- data/lib/dragonfly/active_model_extensions/instance_methods.rb +2 -2
- data/lib/dragonfly/active_model_extensions/validations.rb +10 -6
- data/lib/dragonfly/analyser.rb +0 -1
- data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
- data/lib/dragonfly/analysis/image_magick_analyser.rb +2 -43
- data/lib/dragonfly/app.rb +64 -55
- data/lib/dragonfly/config/heroku.rb +1 -1
- data/lib/dragonfly/config/image_magick.rb +2 -37
- data/lib/dragonfly/config/rails.rb +5 -2
- data/lib/dragonfly/configurable.rb +115 -35
- data/lib/dragonfly/core_ext/object.rb +1 -1
- data/lib/dragonfly/core_ext/string.rb +1 -1
- data/lib/dragonfly/data_storage/couch_data_store.rb +84 -0
- data/lib/dragonfly/data_storage/file_data_store.rb +43 -18
- data/lib/dragonfly/data_storage/mongo_data_store.rb +8 -4
- data/lib/dragonfly/data_storage/s3data_store.rb +82 -38
- data/lib/dragonfly/encoding/image_magick_encoder.rb +2 -53
- data/lib/dragonfly/function_manager.rb +4 -2
- data/lib/dragonfly/generation/image_magick_generator.rb +2 -136
- 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 +44 -0
- data/lib/dragonfly/{encoding/r_magick_encoder.rb → image_magick/encoder.rb} +10 -14
- data/lib/dragonfly/image_magick/generator.rb +145 -0
- data/lib/dragonfly/image_magick/processor.rb +104 -0
- data/lib/dragonfly/image_magick/utils.rb +72 -0
- data/lib/dragonfly/image_magick_utils.rb +2 -79
- data/lib/dragonfly/job.rb +152 -90
- data/lib/dragonfly/middleware.rb +5 -19
- data/lib/dragonfly/processing/image_magick_processor.rb +2 -95
- data/lib/dragonfly/rails/images.rb +15 -10
- data/lib/dragonfly/response.rb +26 -12
- data/lib/dragonfly/serializer.rb +1 -4
- data/lib/dragonfly/server.rb +103 -0
- data/lib/dragonfly/temp_object.rb +56 -101
- data/lib/dragonfly/url_mapper.rb +78 -0
- data/spec/dragonfly/active_model_extensions/model_spec.rb +772 -65
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +90 -10
- data/spec/dragonfly/analyser_spec.rb +1 -1
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +5 -14
- data/spec/dragonfly/app_spec.rb +35 -180
- data/spec/dragonfly/configurable_spec.rb +259 -18
- data/spec/dragonfly/core_ext/string_spec.rb +2 -2
- data/spec/dragonfly/core_ext/symbol_spec.rb +1 -1
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +84 -0
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +149 -22
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +21 -2
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +207 -43
- data/spec/dragonfly/data_storage/{data_store_spec.rb → shared_data_store_examples.rb} +16 -15
- data/spec/dragonfly/function_manager_spec.rb +2 -2
- data/spec/dragonfly/{generation/hash_with_css_style_keys_spec.rb → hash_with_css_style_keys_spec.rb} +2 -2
- data/spec/dragonfly/{analysis/shared_analyser_spec.rb → image_magick/analyser_spec.rb} +19 -6
- data/spec/dragonfly/{encoding/image_magick_encoder_spec.rb → image_magick/encoder_spec.rb} +2 -2
- data/spec/dragonfly/image_magick/generator_spec.rb +172 -0
- data/spec/dragonfly/{processing/shared_processing_spec.rb → image_magick/processor_spec.rb} +55 -6
- data/spec/dragonfly/image_magick/utils_spec.rb +18 -0
- data/spec/dragonfly/job_builder_spec.rb +1 -1
- data/spec/dragonfly/job_definitions_spec.rb +1 -1
- data/spec/dragonfly/job_endpoint_spec.rb +26 -3
- data/spec/dragonfly/job_spec.rb +426 -208
- data/spec/dragonfly/loggable_spec.rb +2 -2
- data/spec/dragonfly/middleware_spec.rb +5 -26
- data/spec/dragonfly/routed_endpoint_spec.rb +1 -1
- data/spec/dragonfly/serializer_spec.rb +1 -14
- data/spec/dragonfly/server_spec.rb +261 -0
- data/spec/dragonfly/simple_cache_spec.rb +1 -1
- data/spec/dragonfly/temp_object_spec.rb +84 -130
- data/spec/dragonfly/url_mapper_spec.rb +130 -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 +12 -22
- data/spec/{argument_matchers.rb → support/argument_matchers.rb} +0 -0
- data/spec/{image_matchers.rb → support/image_matchers.rb} +4 -4
- data/spec/support/simple_matchers.rb +53 -0
- data/yard/handlers/configurable_attr_handler.rb +2 -2
- data/yard/templates/default/fulldoc/html/css/common.css +12 -10
- data/yard/templates/default/layout/html/layout.erb +6 -0
- metadata +267 -308
- data/Gemfile.rails.2.3.5 +0 -20
- data/features/3.0.3.feature +0 -8
- data/features/rails_2.3.5.feature +0 -7
- data/fixtures/files/app/models/album.rb +0 -3
- data/fixtures/files/app/views/albums/new.html.erb +0 -4
- data/fixtures/files/features/manage_album_images.feature +0 -12
- data/fixtures/rails_2.3.5/template.rb +0 -10
- data/lib/dragonfly/analysis/r_magick_analyser.rb +0 -63
- data/lib/dragonfly/config/r_magick.rb +0 -46
- data/lib/dragonfly/generation/hash_with_css_style_keys.rb +0 -23
- data/lib/dragonfly/generation/r_magick_generator.rb +0 -155
- data/lib/dragonfly/processing/r_magick_processor.rb +0 -126
- data/lib/dragonfly/r_magick_utils.rb +0 -48
- data/lib/dragonfly/simple_endpoint.rb +0 -76
- data/spec/dragonfly/active_model_extensions/active_model_setup.rb +0 -97
- data/spec/dragonfly/active_model_extensions/active_record_setup.rb +0 -85
- data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +0 -15
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +0 -31
- data/spec/dragonfly/config/r_magick_spec.rb +0 -29
- data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +0 -41
- data/spec/dragonfly/generation/image_magick_generator_spec.rb +0 -12
- data/spec/dragonfly/generation/r_magick_generator_spec.rb +0 -28
- data/spec/dragonfly/generation/shared_generator_spec.rb +0 -91
- data/spec/dragonfly/image_magick_utils_spec.rb +0 -16
- data/spec/dragonfly/processing/image_magick_processor_spec.rb +0 -29
- data/spec/dragonfly/processing/r_magick_processor_spec.rb +0 -30
- data/spec/dragonfly/simple_endpoint_spec.rb +0 -97
- data/spec/simple_matchers.rb +0 -44
@@ -0,0 +1,130 @@
|
|
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
|
+
|
65
|
+
it "should call to_s on non-string values" do
|
66
|
+
@url_mapper.url_for('job' => 'asdf', 'size' => 500).should == '/media/asdf-500'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "params_for" do
|
71
|
+
before(:each) do
|
72
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:job')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should map correctly" do
|
76
|
+
@url_mapper.params_for('/media/asdf').should == {'job' => 'asdf'}
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should include query parameters" do
|
80
|
+
@url_mapper.params_for('/media/asdf', 'when=now').should == {'job' => 'asdf', 'when' => 'now'}
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should generally be ok with wierd characters" do
|
84
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:doobie')
|
85
|
+
@url_mapper.params_for('/media/sd sdf jl£@$ sdf:_', 'job=goodun').should == {'job' => 'goodun', 'doobie' => 'sd sdf jl£@$ sdf:_'}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "matching urls with standard format /media/:job/:basename.:format" do
|
90
|
+
before(:each) do
|
91
|
+
@url_mapper = Dragonfly::UrlMapper.new('/media/:job/:basename.:format',
|
92
|
+
:job => '\w',
|
93
|
+
:basename => '[^\/]',
|
94
|
+
:format => '[^\.]'
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
{
|
99
|
+
'' => nil,
|
100
|
+
'/' => nil,
|
101
|
+
'/media' => {'job' => nil, 'basename' => nil, 'format' => nil},
|
102
|
+
'/media/' => nil,
|
103
|
+
'/moodia/asdf' => nil,
|
104
|
+
'/media/asdf/' => nil,
|
105
|
+
'/mount/media/asdf' => nil,
|
106
|
+
'/media/asdf/stuff.egg' => {'job' => 'asdf', 'basename' => 'stuff', 'format' => 'egg'},
|
107
|
+
'/media/asdf' => {'job' => 'asdf', 'basename' => nil, 'format' => nil},
|
108
|
+
'/media/asdf/stuff' => {'job' => 'asdf', 'basename' => 'stuff', 'format' => nil},
|
109
|
+
'/media/asdf.egg' => {'job' => 'asdf', 'basename' => nil, 'format' => 'egg'},
|
110
|
+
'/media/asdf/stuff/egg' => nil,
|
111
|
+
'/media/asdf/stuff.dog.egg' => {'job' => 'asdf', 'basename' => 'stuff.dog', 'format' => 'egg'},
|
112
|
+
'/media/asdf/s=2 -.d.e' => {'job' => 'asdf', 'basename' => 's=2 -.d', 'format' => 'e'},
|
113
|
+
'/media/asdf-40x40/stuff.egg' => nil
|
114
|
+
}.each do |path, params|
|
115
|
+
|
116
|
+
it "should turn the url #{path} into params #{params.inspect}" do
|
117
|
+
@url_mapper.params_for(path).should == params
|
118
|
+
end
|
119
|
+
|
120
|
+
if params
|
121
|
+
it "should turn the params #{params.inspect} into url #{path}" do
|
122
|
+
@url_mapper.url_for(params).should == path
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'deprecations' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@app = test_app
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "url_suffix" do
|
10
|
+
it "should give an appropriate error" do
|
11
|
+
@app.configure do |c|
|
12
|
+
expect{
|
13
|
+
c.url_suffix = 'darble'
|
14
|
+
}.to raise_error(NoMethodError, /deprecated.*please use url_format/)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "url_path_prefix" do
|
20
|
+
it "should give an appropriate error" do
|
21
|
+
@app.configure do |c|
|
22
|
+
expect{
|
23
|
+
c.url_path_prefix = '/darble'
|
24
|
+
}.to raise_error(NoMethodError, /deprecated.*please use url_format/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "middleware" do
|
30
|
+
it "should give an appropriate error" do
|
31
|
+
app = Rack::Builder.new do
|
32
|
+
use Dragonfly::Middleware, :images, '/media'
|
33
|
+
run proc{[200, {}, []]}
|
34
|
+
end
|
35
|
+
expect{
|
36
|
+
app.call({})
|
37
|
+
}.to raise_error(ArgumentError, /deprecated/)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "infer_mime_type_from_file_ext" do
|
42
|
+
it "should give an appropriate error" do
|
43
|
+
@app.configure do |c|
|
44
|
+
expect{
|
45
|
+
c.infer_mime_type_from_file_ext = false
|
46
|
+
}.to raise_error(NoMethodError, /deprecated.*please use trust_file_extensions = false/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "a configured imagemagick app" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@app = Dragonfly[:images].configure_with(:imagemagick)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "convert command path" do
|
10
|
+
before(:each) do
|
11
|
+
@processor = @app.processor.get_registered(Dragonfly::ImageMagick::Processor)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should default to 'convert'" do
|
15
|
+
@processor.convert_command.should == 'convert'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should change when configured through the app" do
|
19
|
+
@app.configure do |c|
|
20
|
+
c.convert_command = '/usr/eggs'
|
21
|
+
end
|
22
|
+
@processor.convert_command.should == '/usr/eggs'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'dragonfly/active_model_extensions/spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "model urls" do
|
5
|
+
|
6
|
+
def new_tempfile(data='HELLO', filename='hello.txt')
|
7
|
+
tempfile = Tempfile.new('test')
|
8
|
+
tempfile.write(data)
|
9
|
+
tempfile.rewind
|
10
|
+
tempfile.stub!(:original_filename).and_return(filename)
|
11
|
+
tempfile
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@app = test_app.configure do |c|
|
16
|
+
c.url_format = '/media/:job/:basename.:format'
|
17
|
+
end
|
18
|
+
@app.define_macro(MyModel, :image_accessor)
|
19
|
+
Item.class_eval do
|
20
|
+
image_accessor :preview_image # has name etc.
|
21
|
+
image_accessor :other_image # doesn't have magic stuff
|
22
|
+
end
|
23
|
+
@item = Item.new
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should include the name in the url if it has the magic attribute" do
|
27
|
+
@item.preview_image = new_tempfile
|
28
|
+
@item.save!
|
29
|
+
item = Item.find(@item.id)
|
30
|
+
item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt$}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should work without the name if the name magic attr doesn't exist" do
|
34
|
+
@item.other_image = new_tempfile
|
35
|
+
@item.save!
|
36
|
+
item = Item.find(@item.id)
|
37
|
+
item.other_image.url.should =~ %r{^/media/\w+$}
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should include the name in the url even if it has no ext" do
|
41
|
+
@item.preview_image = new_tempfile("hello", 'hello')
|
42
|
+
@item.save!
|
43
|
+
item = Item.find(@item.id)
|
44
|
+
item.preview_image.url.should =~ %r{^/media/\w+/hello$}
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should change the ext when there's an encoding step" do
|
48
|
+
@item.preview_image = new_tempfile
|
49
|
+
@item.save!
|
50
|
+
item = Item.find(@item.id)
|
51
|
+
item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/hello\.bum$}
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not include the name if it has none" do
|
55
|
+
@item.preview_image = "HELLO"
|
56
|
+
@item.save!
|
57
|
+
item = Item.find(@item.id)
|
58
|
+
item.preview_image.url.should =~ %r{^/media/\w+$}
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should have an ext when there's an encoding step but no name" do
|
62
|
+
@item.preview_image = "HELLO"
|
63
|
+
@item.save!
|
64
|
+
item = Item.find(@item.id)
|
65
|
+
item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+\.bum$}
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should work as normal with dos protection" do
|
69
|
+
@app.server.protect_from_dos_attacks = true
|
70
|
+
@item.preview_image = new_tempfile
|
71
|
+
@item.save!
|
72
|
+
item = Item.find(@item.id)
|
73
|
+
item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt\?sha=\w+$}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should allow configuring the url" do
|
77
|
+
@app.configure do |c|
|
78
|
+
c.url_format = '/img/:job'
|
79
|
+
end
|
80
|
+
@item.preview_image = new_tempfile
|
81
|
+
@item.save!
|
82
|
+
item = Item.find(@item.id)
|
83
|
+
item.preview_image.url.should =~ %r{^/img/\w+$}
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "remote on-the-fly urls" do
|
4
|
+
|
5
|
+
THUMBS = {}
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@app = test_app.configure do |c|
|
9
|
+
c.generator.add :test do
|
10
|
+
"TEST"
|
11
|
+
end
|
12
|
+
c.server.before_serve do |job, env|
|
13
|
+
uid = job.store(:path => 'yay.txt')
|
14
|
+
THUMBS[job.serialize] = uid
|
15
|
+
end
|
16
|
+
c.define_url do |app, job, opts|
|
17
|
+
uid = THUMBS[job.serialize]
|
18
|
+
if uid
|
19
|
+
app.datastore.url_for(uid)
|
20
|
+
else
|
21
|
+
app.server.url_for(job)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
c.datastore = Dragonfly::DataStorage::FileDataStore.new
|
25
|
+
c.datastore.root_path = '/var/tmp/dragonfly'
|
26
|
+
c.datastore.server_root = '/var/tmp'
|
27
|
+
end
|
28
|
+
@job = @app.generate(:test)
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:each) do
|
32
|
+
THUMBS.delete_if{true}
|
33
|
+
FileUtils.rm_f('/var/tmp/dragonfly/yay.txt')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should give the url for the server" do
|
37
|
+
@job.url.should == "/#{@job.serialize}"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should store the content when first called" do
|
41
|
+
File.exist?('/var/tmp/dragonfly/yay.txt').should be_false
|
42
|
+
@app.server.call('PATH_INFO' => @job.url, 'REQUEST_METHOD' => 'GET')
|
43
|
+
File.read('/var/tmp/dragonfly/yay.txt').should == 'TEST'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should point to the external url the second time" do
|
47
|
+
@app.server.call('PATH_INFO' => @job.url, 'REQUEST_METHOD' => 'GET')
|
48
|
+
@job.url.should == '/dragonfly/yay.txt'
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "getting rack response directly" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@app = Dragonfly[:to_response].configure do |c|
|
7
|
+
c.generator.add :test do
|
8
|
+
"bunheads"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should give a rack response" do
|
14
|
+
response = @app.generate(:test, 1, 1).to_response
|
15
|
+
response.should be_a(Array)
|
16
|
+
response.length.should == 3
|
17
|
+
response[0].should == 200
|
18
|
+
response[1]['Content-Type'].should == 'application/octet-stream'
|
19
|
+
response[2].data.should == 'bunheads'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow passing in the env" do
|
23
|
+
response = @app.generate(:test, 1, 1).to_response('REQUEST_METHOD' => 'POST')
|
24
|
+
response.should be_a(Array)
|
25
|
+
response.length.should == 3
|
26
|
+
response[0].should == 405
|
27
|
+
response[1]['Content-Type'].should == 'text/plain'
|
28
|
+
response[2].should == ["POST method not allowed"]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,30 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup(:default, :test)
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'rspec'
|
8
|
+
require 'dragonfly'
|
4
9
|
require 'fileutils'
|
5
10
|
|
6
|
-
require
|
7
|
-
$:.unshift(File.dirname(__FILE__))
|
8
|
-
require 'argument_matchers'
|
9
|
-
require 'simple_matchers'
|
10
|
-
require 'image_matchers'
|
11
|
+
require 'webmock/rspec'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
# A hack as system calls weren't using my path
|
15
|
-
extra_paths = %w(/opt/local/bin)
|
16
|
-
ENV['PATH'] ||= ''
|
17
|
-
ENV['PATH'] += ':' + extra_paths.join(':')
|
18
|
-
|
19
|
-
# If this is jRuby, ignore the rmagick tests
|
20
|
-
ENV['IGNORE_RMAGICK'] = 'true' if RUBY_PLATFORM == 'java' || defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
13
|
+
# Requires supporting files with custom matchers and macros, etc,
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
21
15
|
|
22
16
|
SAMPLES_DIR = File.expand_path(File.dirname(__FILE__) + '/../samples') unless defined?(SAMPLES_DIR)
|
23
17
|
|
24
|
-
Spec::Runner.configure do |c|
|
25
|
-
c.after(:all){ Dir["#{ROOT_PATH}/Gemfile*.lock"].each{|f| FileUtils.rm_f(f) } }
|
26
|
-
end
|
27
|
-
|
28
18
|
def todo
|
29
19
|
raise "TODO"
|
30
20
|
end
|
@@ -56,6 +46,6 @@ def suppressing_stderr
|
|
56
46
|
$stderr.reopen(tempfile)
|
57
47
|
yield
|
58
48
|
ensure
|
59
|
-
tempfile.close
|
49
|
+
tempfile.close!
|
60
50
|
$stderr.reopen(original_stderr)
|
61
51
|
end
|
File without changes
|
@@ -22,25 +22,25 @@ def image_properties(image)
|
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
RSpec::Matchers.define :have_width do |width|
|
26
26
|
match do |given|
|
27
27
|
width.should === image_properties(given)[:width].to_i
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
RSpec::Matchers.define :have_height do |height|
|
32
32
|
match do |given|
|
33
33
|
height.should === image_properties(given)[:height].to_i
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
RSpec::Matchers.define :have_format do |format|
|
38
38
|
match do |given|
|
39
39
|
image_properties(given)[:format].should == format
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
RSpec::Matchers.define :have_size do |size|
|
44
44
|
match do |given|
|
45
45
|
image_properties(given)[:size].should == size
|
46
46
|
end
|