dragonfly 0.6.2 → 0.7.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/.gitignore +2 -0
- data/.specopts +2 -0
- data/.yardopts +11 -5
- data/Gemfile +22 -0
- data/Gemfile.rails.2.3.5 +13 -0
- data/History.md +49 -0
- data/README.md +18 -28
- data/Rakefile +24 -36
- data/VERSION +1 -1
- data/config.ru +4 -1
- data/dragonfly.gemspec +85 -99
- data/extra_docs/Analysers.md +66 -30
- data/extra_docs/Caching.md +22 -0
- data/extra_docs/Configuration.md +116 -0
- data/extra_docs/DataStorage.md +114 -14
- data/extra_docs/Encoding.md +62 -37
- data/extra_docs/GeneralUsage.md +118 -0
- data/extra_docs/Generators.md +92 -0
- data/extra_docs/Heroku.md +51 -0
- data/extra_docs/Index.md +8 -9
- data/extra_docs/MimeTypes.md +18 -17
- data/extra_docs/Models.md +251 -0
- data/extra_docs/Processing.md +94 -70
- data/extra_docs/Rack.md +53 -0
- data/extra_docs/Rails2.md +44 -0
- data/extra_docs/Rails3.md +51 -0
- data/extra_docs/Sinatra.md +21 -0
- data/extra_docs/URLs.md +114 -0
- data/features/images.feature +6 -7
- data/features/no_processing.feature +0 -6
- data/features/rails_2.3.5.feature +1 -1
- data/features/rails_3.0.0.rc.feature +8 -0
- data/features/steps/dragonfly_steps.rb +14 -12
- data/features/steps/rails_steps.rb +20 -9
- data/features/support/env.rb +10 -11
- data/fixtures/files/app/views/albums/new.html.erb +4 -4
- data/fixtures/files/app/views/albums/show.html.erb +1 -1
- data/fixtures/files/features/manage_album_images.feature +1 -1
- data/fixtures/files/features/step_definitions/{album_steps.rb → image_steps.rb} +4 -3
- data/fixtures/files/features/support/paths.rb +2 -0
- data/fixtures/files/features/text_images.feature +7 -0
- data/fixtures/rails_3.0.0.rc/template.rb +21 -0
- data/irbrc.rb +2 -1
- data/lib/dragonfly.rb +4 -16
- data/lib/dragonfly/{active_record_extensions.rb → active_model_extensions.rb} +1 -1
- data/lib/dragonfly/active_model_extensions/attachment.rb +146 -0
- data/lib/dragonfly/{active_record_extensions → active_model_extensions}/class_methods.rb +5 -6
- data/lib/dragonfly/{active_record_extensions → active_model_extensions}/instance_methods.rb +1 -1
- data/lib/dragonfly/{active_record_extensions → active_model_extensions}/validations.rb +5 -9
- data/lib/dragonfly/analyser.rb +59 -0
- data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
- data/lib/dragonfly/analysis/r_magick_analyser.rb +46 -31
- data/lib/dragonfly/app.rb +138 -173
- data/lib/dragonfly/config/heroku.rb +19 -0
- data/lib/dragonfly/config/r_magick.rb +37 -0
- data/lib/dragonfly/config/{rails_defaults.rb → rails.rb} +6 -7
- data/lib/dragonfly/configurable.rb +30 -27
- data/lib/dragonfly/core_ext/object.rb +1 -1
- data/lib/dragonfly/data_storage/file_data_store.rb +59 -26
- data/lib/dragonfly/data_storage/mongo_data_store.rb +65 -0
- data/lib/dragonfly/data_storage/s3data_store.rb +31 -12
- data/lib/dragonfly/encoder.rb +13 -0
- data/lib/dragonfly/encoding/r_magick_encoder.rb +10 -19
- data/lib/dragonfly/endpoint.rb +43 -0
- data/lib/dragonfly/function_manager.rb +65 -0
- data/lib/dragonfly/{processing/r_magick_text_processor.rb → generation/r_magick_generator.rb} +25 -11
- data/lib/dragonfly/generator.rb +9 -0
- data/lib/dragonfly/job.rb +290 -0
- data/lib/dragonfly/job_builder.rb +39 -0
- data/lib/dragonfly/job_definitions.rb +26 -0
- data/lib/dragonfly/job_endpoint.rb +17 -0
- data/lib/dragonfly/loggable.rb +28 -0
- data/lib/dragonfly/middleware.rb +21 -14
- data/lib/dragonfly/processing/r_magick_processor.rb +71 -48
- data/lib/dragonfly/processor.rb +9 -0
- data/lib/dragonfly/r_magick_utils.rb +24 -0
- data/lib/dragonfly/rails/images.rb +10 -7
- data/lib/dragonfly/routed_endpoint.rb +42 -0
- data/lib/dragonfly/serializer.rb +32 -0
- data/lib/dragonfly/simple_cache.rb +23 -0
- data/lib/dragonfly/simple_endpoint.rb +64 -0
- data/lib/dragonfly/temp_object.rb +77 -45
- data/spec/argument_matchers.rb +7 -17
- data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
- data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
- data/spec/dragonfly/{active_record_extensions → active_model_extensions}/model_spec.rb +282 -244
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
- data/spec/dragonfly/analyser_spec.rb +123 -0
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +2 -2
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +10 -1
- data/spec/dragonfly/app_spec.rb +175 -69
- data/spec/dragonfly/configurable_spec.rb +14 -0
- data/spec/dragonfly/data_storage/data_store_spec.rb +36 -9
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +61 -38
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +18 -0
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +34 -39
- data/spec/dragonfly/deprecation_spec.rb +20 -0
- data/spec/dragonfly/function_manager_spec.rb +154 -0
- data/spec/dragonfly/generation/r_magick_generator_spec.rb +119 -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 +66 -0
- data/spec/dragonfly/job_spec.rb +605 -0
- data/spec/dragonfly/loggable_spec.rb +80 -0
- data/spec/dragonfly/middleware_spec.rb +37 -17
- data/spec/dragonfly/processing/r_magick_processor_spec.rb +182 -166
- data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
- data/spec/dragonfly/serializer_spec.rb +61 -0
- data/spec/dragonfly/simple_cache_spec.rb +27 -0
- data/spec/dragonfly/simple_endpoint_spec.rb +78 -0
- data/spec/dragonfly/temp_object_spec.rb +154 -119
- data/spec/simple_matchers.rb +22 -0
- data/spec/spec_helper.rb +28 -4
- data/yard/templates/default/layout/html/layout.erb +18 -11
- metadata +89 -190
- data/config.rb +0 -5
- data/extra_docs/ActiveRecord.md +0 -196
- data/extra_docs/ExampleUseCases.md +0 -189
- data/extra_docs/GettingStarted.md +0 -114
- data/extra_docs/Shortcuts.md +0 -118
- data/extra_docs/UsingWithRails.md +0 -81
- data/features/rails_3.0.0.beta3.feature +0 -7
- data/fixtures/rails_3.0.0.beta3/template.rb +0 -16
- data/lib/dragonfly/active_record_extensions/attachment.rb +0 -170
- data/lib/dragonfly/analyser_list.rb +0 -9
- data/lib/dragonfly/analysis/base.rb +0 -10
- data/lib/dragonfly/belongs_to_app.rb +0 -24
- data/lib/dragonfly/config/heroku_rails_images.rb +0 -23
- data/lib/dragonfly/config/r_magick_images.rb +0 -69
- data/lib/dragonfly/config/r_magick_text.rb +0 -25
- data/lib/dragonfly/config/rails_images.rb +0 -13
- data/lib/dragonfly/data_storage/base.rb +0 -21
- data/lib/dragonfly/data_storage/base64_data_store.rb +0 -23
- data/lib/dragonfly/data_storage/transparent_data_store.rb +0 -21
- data/lib/dragonfly/delegatable.rb +0 -14
- data/lib/dragonfly/delegator.rb +0 -62
- data/lib/dragonfly/encoder_list.rb +0 -9
- data/lib/dragonfly/encoding/base.rb +0 -14
- data/lib/dragonfly/encoding/transparent_encoder.rb +0 -14
- data/lib/dragonfly/extended_temp_object.rb +0 -120
- data/lib/dragonfly/parameters.rb +0 -163
- data/lib/dragonfly/processing/base.rb +0 -10
- data/lib/dragonfly/processor_list.rb +0 -9
- data/lib/dragonfly/url_handler.rb +0 -147
- data/spec/dragonfly/active_record_extensions/attachment_spec.rb +0 -8
- data/spec/dragonfly/active_record_extensions/migration.rb +0 -42
- data/spec/dragonfly/active_record_extensions/models.rb +0 -6
- data/spec/dragonfly/active_record_extensions/spec_helper.rb +0 -24
- data/spec/dragonfly/belongs_to_app_spec.rb +0 -55
- data/spec/dragonfly/delegatable_spec.rb +0 -32
- data/spec/dragonfly/delegator_spec.rb +0 -145
- data/spec/dragonfly/extended_temp_object_spec.rb +0 -71
- data/spec/dragonfly/parameters_spec.rb +0 -298
- data/spec/dragonfly/processing/r_magick_text_processor_spec.rb +0 -84
- data/spec/dragonfly/url_handler_spec.rb +0 -247
- data/spec/dragonfly_spec.rb +0 -16
- data/spec/ginger_scenarios.rb +0 -13
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
def response_for(array)
|
4
|
+
Rack::MockResponse.new(*array)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Dragonfly::RoutedEndpoint do
|
8
|
+
|
9
|
+
def env_for(url, opts={})
|
10
|
+
Rack::MockRequest.env_for(url, opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@app = test_app
|
15
|
+
@endpoint = Dragonfly::RoutedEndpoint.new(@app) {|params, app|
|
16
|
+
app.fetch(params[:uid])
|
17
|
+
}
|
18
|
+
@app.datastore.stub!(:retrieve).with('some_uid').and_return Dragonfly::TempObject.new('wassup')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise an error when there are no routing parameters" do
|
22
|
+
lambda{
|
23
|
+
@endpoint.call(env_for('/blah'))
|
24
|
+
}.should raise_error(Dragonfly::RoutedEndpoint::NoRoutingParams)
|
25
|
+
end
|
26
|
+
|
27
|
+
{
|
28
|
+
'Rails' => 'action_dispatch.request.path_parameters',
|
29
|
+
'Usher' => 'usher.params',
|
30
|
+
'HTTP Router' => 'router.params',
|
31
|
+
'Rack-Mount' => 'rack.routing_args',
|
32
|
+
'Dragonfly' => 'dragonfly.params'
|
33
|
+
}.each do |name, key|
|
34
|
+
|
35
|
+
it "should work with #{name} routing args" do
|
36
|
+
response = response_for @endpoint.call(env_for('/blah', key => {:uid => 'some_uid'}))
|
37
|
+
response.body.should == 'wassup'
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should merge with query parameters" do
|
43
|
+
env = Rack::MockRequest.env_for('/big/buns?uid=some_uid', 'dragonfly.params' => {:something => 'else'})
|
44
|
+
response = response_for @endpoint.call(env)
|
45
|
+
response.body.should == 'wassup'
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe Dragonfly::Serializer do
|
5
|
+
|
6
|
+
include Dragonfly::Serializer
|
7
|
+
|
8
|
+
[
|
9
|
+
'a',
|
10
|
+
'sdhflasd',
|
11
|
+
'/2010/03/01/hello.png',
|
12
|
+
'//..',
|
13
|
+
'whats/up.egg.frog',
|
14
|
+
'£ñçùí;'
|
15
|
+
].each do |string|
|
16
|
+
it "should encode #{string.inspect} properly with no padding/line break" do
|
17
|
+
b64_encode(string).should_not =~ /\n|=/
|
18
|
+
end
|
19
|
+
it "should correctly encode and decode #{string.inspect} to the same string" do
|
20
|
+
str = b64_decode(b64_encode(string))
|
21
|
+
str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
22
|
+
str.should == string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
[
|
27
|
+
:hello,
|
28
|
+
nil,
|
29
|
+
true,
|
30
|
+
4,
|
31
|
+
2.3,
|
32
|
+
'wassup man',
|
33
|
+
[3,4,5],
|
34
|
+
{:wo => 'there'},
|
35
|
+
[{:this => 'should', :work => [3, 5.3, nil, {false => 'egg'}]}, [], true]
|
36
|
+
].each do |object|
|
37
|
+
it "should correctly marshal encode #{object.inspect} properly with no padding/line break" do
|
38
|
+
encoded = marshal_encode(object)
|
39
|
+
# raise encoded.index("\n").inspect
|
40
|
+
encoded.should be_a(String)
|
41
|
+
encoded.should_not =~ /\n|=/
|
42
|
+
end
|
43
|
+
it "should correctly marshal encode and decode #{object.inspect} to the same object" do
|
44
|
+
marshal_decode(marshal_encode(object)).should == object
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "marshal_decode" do
|
49
|
+
it "should raise an error if the string passed in is empty" do
|
50
|
+
lambda{
|
51
|
+
marshal_decode('')
|
52
|
+
}.should raise_error(Dragonfly::Serializer::BadString)
|
53
|
+
end
|
54
|
+
it "should raise an error if the string passed in is gobbledeegook" do
|
55
|
+
lambda{
|
56
|
+
marshal_decode('ahasdkjfhasdkfjh')
|
57
|
+
}.should raise_error(Dragonfly::Serializer::BadString)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../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,78 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
def request(app, path)
|
5
|
+
Rack::MockRequest.new(app).get(path)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Dragonfly::SimpleEndpoint do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@app = test_app
|
12
|
+
@app.protect_from_dos_attacks = false
|
13
|
+
@uid = @app.store('HELLO THERE')
|
14
|
+
@endpoint = Dragonfly::SimpleEndpoint.new(@app)
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
@app.destroy(@uid)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return the thing when given the url" do
|
22
|
+
url = "/#{@app.fetch(@uid).serialize}"
|
23
|
+
response = request(@endpoint, url)
|
24
|
+
response.status.should == 200
|
25
|
+
response.body.should == 'HELLO THERE'
|
26
|
+
response.content_type.should == 'application/octet-stream'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return a 400 if no sha given but protection on" do
|
30
|
+
@app.protect_from_dos_attacks = true
|
31
|
+
url = "/#{@app.fetch(@uid).serialize}"
|
32
|
+
response = request(@endpoint, url)
|
33
|
+
response.status.should == 400
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return a 400 if wrong sha given and protection on" do
|
37
|
+
@app.protect_from_dos_attacks = true
|
38
|
+
url = "/#{@app.fetch(@uid).serialize}?s=asdfs"
|
39
|
+
response = request(@endpoint, url)
|
40
|
+
response.status.should == 400
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return a 404 when the url isn't known" do
|
44
|
+
response = request(@endpoint, '/sadhfasdfdsfsdf')
|
45
|
+
response.status.should == 404
|
46
|
+
response.body.should == 'Not found'
|
47
|
+
response.content_type.should == 'text/plain'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return a 404 when the url is a well-encoded but bad array" do
|
51
|
+
url = "/#{Dragonfly::Serializer.marshal_encode([[:egg, {:some => 'args'}]])}"
|
52
|
+
response = request(@endpoint, url)
|
53
|
+
response.status.should == 404
|
54
|
+
response.body.should == 'Not found'
|
55
|
+
response.content_type.should == 'text/plain'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should still work when mapped to a prefix" do
|
59
|
+
endpoint = @endpoint
|
60
|
+
rack_app = Rack::Builder.new do
|
61
|
+
map '/some_prefix' do
|
62
|
+
run endpoint
|
63
|
+
end
|
64
|
+
end.to_app
|
65
|
+
url = "/some_prefix/#{@app.fetch(@uid).serialize}"
|
66
|
+
response = request(rack_app, url)
|
67
|
+
response.status.should == 200
|
68
|
+
response.body.should == 'HELLO THERE'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return a simple text response at the root" do
|
72
|
+
response = request(@endpoint, '/')
|
73
|
+
response.status.should == 200
|
74
|
+
response.body.length.should > 0
|
75
|
+
response.content_type.should == 'text/plain'
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -22,6 +22,15 @@ describe Dragonfly::TempObject do
|
|
22
22
|
File.new('/tmp/test_file')
|
23
23
|
end
|
24
24
|
|
25
|
+
def new_temp_object(data, opts={})
|
26
|
+
klass = opts.delete(:class) || Dragonfly::TempObject
|
27
|
+
klass.new(initialization_object(data), opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialization_object(data)
|
31
|
+
raise NotImplementedError, "This should be implemented in the describe block!"
|
32
|
+
end
|
33
|
+
|
25
34
|
def get_parts(temp_object)
|
26
35
|
parts = []
|
27
36
|
temp_object.each do |bytes|
|
@@ -41,78 +50,102 @@ describe Dragonfly::TempObject do
|
|
41
50
|
|
42
51
|
describe "common behaviour", :shared => true do
|
43
52
|
|
44
|
-
|
45
|
-
@temp_object = new_temp_object('HELLO')
|
46
|
-
end
|
53
|
+
describe "simple initialization" do
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
@temp_object.data.should == 'HELLO'
|
55
|
+
before(:each) do
|
56
|
+
@temp_object = new_temp_object('HELLO')
|
51
57
|
end
|
52
|
-
end
|
53
58
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
it "should contain the correct data" do
|
59
|
-
@temp_object.file.read.should == 'HELLO'
|
60
|
-
end
|
61
|
-
it "should yield a file then close it if a block is given" do
|
62
|
-
@temp_object.file do |f|
|
63
|
-
f.read.should == 'HELLO'
|
64
|
-
f.should_receive :close
|
59
|
+
describe "data" do
|
60
|
+
it "should return the data correctly" do
|
61
|
+
@temp_object.data.should == 'HELLO'
|
65
62
|
end
|
66
63
|
end
|
67
|
-
it "should return whatever is returned from the block if a block is given" do
|
68
|
-
@temp_object.file do |f|
|
69
|
-
'doogie'
|
70
|
-
end.should == 'doogie'
|
71
|
-
end
|
72
|
-
end
|
73
64
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
65
|
+
describe "file" do
|
66
|
+
it "should return a readable file" do
|
67
|
+
@temp_object.file.should be_a(File)
|
68
|
+
end
|
69
|
+
it "should contain the correct data" do
|
70
|
+
@temp_object.file.read.should == 'HELLO'
|
71
|
+
end
|
72
|
+
it "should yield a file then close it if a block is given" do
|
73
|
+
@temp_object.file do |f|
|
74
|
+
f.read.should == 'HELLO'
|
75
|
+
f.should_receive :close
|
76
|
+
end
|
77
|
+
end
|
78
|
+
it "should return whatever is returned from the block if a block is given" do
|
79
|
+
@temp_object.file do |f|
|
80
|
+
'doogie'
|
81
|
+
end.should == 'doogie'
|
82
|
+
end
|
78
83
|
end
|
79
|
-
|
80
|
-
|
84
|
+
|
85
|
+
describe "tempfile" do
|
86
|
+
it "should create a closed tempfile" do
|
87
|
+
@temp_object.tempfile.should be_a(Tempfile)
|
88
|
+
@temp_object.tempfile.should be_closed
|
89
|
+
end
|
90
|
+
it "should contain the correct data" do
|
91
|
+
@temp_object.tempfile.open.read.should == 'HELLO'
|
92
|
+
end
|
81
93
|
end
|
82
|
-
end
|
83
94
|
|
84
|
-
|
85
|
-
|
86
|
-
|
95
|
+
describe "path" do
|
96
|
+
it "should return the absolute file path" do
|
97
|
+
@temp_object.path.should == @temp_object.tempfile.path
|
98
|
+
end
|
87
99
|
end
|
88
|
-
end
|
89
100
|
|
90
|
-
|
91
|
-
|
92
|
-
|
101
|
+
describe "size" do
|
102
|
+
it "should return the size in bytes" do
|
103
|
+
@temp_object.size.should == 5
|
104
|
+
end
|
93
105
|
end
|
94
|
-
end
|
95
106
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
107
|
+
describe "to_file" do
|
108
|
+
before(:each) do
|
109
|
+
@filename = 'eggnog.txt'
|
110
|
+
FileUtils.rm(@filename) if File.exists?(@filename)
|
111
|
+
end
|
112
|
+
after(:each) do
|
113
|
+
FileUtils.rm(@filename) if File.exists?(@filename)
|
114
|
+
end
|
115
|
+
it "should write to a file" do
|
116
|
+
@temp_object.to_file(@filename)
|
117
|
+
File.exists?(@filename).should be_true
|
118
|
+
end
|
119
|
+
it "should write the correct data to the file" do
|
120
|
+
@temp_object.to_file(@filename)
|
121
|
+
File.read(@filename).should == 'HELLO'
|
122
|
+
end
|
123
|
+
it "should return a readable file" do
|
124
|
+
file = @temp_object.to_file(@filename)
|
125
|
+
file.should be_a(File)
|
126
|
+
file.read.should == 'HELLO'
|
127
|
+
end
|
100
128
|
end
|
101
|
-
|
102
|
-
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "initializing attributes too" do
|
133
|
+
it "should set the name" do
|
134
|
+
temp_object = Dragonfly::TempObject.new(initialization_object('HELLO'), :name => 'monkey.egg')
|
135
|
+
temp_object.name.should == 'monkey.egg'
|
103
136
|
end
|
104
|
-
it "should
|
105
|
-
|
106
|
-
|
137
|
+
it "should set the meta" do
|
138
|
+
temp_object = Dragonfly::TempObject.new(initialization_object('HELLO'), :meta => {:dr => 'doolittle'})
|
139
|
+
temp_object.meta.should == {:dr => 'doolittle'}
|
107
140
|
end
|
108
|
-
it "should
|
109
|
-
|
110
|
-
|
141
|
+
it "should set the format" do
|
142
|
+
temp_object = Dragonfly::TempObject.new(initialization_object('HELLO'), :format => :jpg)
|
143
|
+
temp_object.format.should == :jpg
|
111
144
|
end
|
112
|
-
it "should
|
113
|
-
|
114
|
-
|
115
|
-
|
145
|
+
it "should raise an error if an invalid option is given" do
|
146
|
+
lambda {
|
147
|
+
Dragonfly::TempObject.new(initialization_object('HELLO'), :doobie => 'doo')
|
148
|
+
}.should raise_error(ArgumentError)
|
116
149
|
end
|
117
150
|
end
|
118
151
|
|
@@ -127,7 +160,7 @@ describe Dragonfly::TempObject do
|
|
127
160
|
end
|
128
161
|
it "should yield the number of bytes specified in the class configuration" do
|
129
162
|
klass = Class.new(Dragonfly::TempObject)
|
130
|
-
temp_object = new_temp_object(File.read(sample_path('round.gif')), klass)
|
163
|
+
temp_object = new_temp_object(File.read(sample_path('round.gif')), :class => klass)
|
131
164
|
klass.block_size = 3001
|
132
165
|
parts = get_parts(temp_object)
|
133
166
|
parts[0...-1].each do |part|
|
@@ -142,8 +175,8 @@ describe Dragonfly::TempObject do
|
|
142
175
|
|
143
176
|
describe "initializing from a string" do
|
144
177
|
|
145
|
-
def
|
146
|
-
|
178
|
+
def initialization_object(data)
|
179
|
+
data
|
147
180
|
end
|
148
181
|
|
149
182
|
it_should_behave_like "common behaviour"
|
@@ -157,8 +190,8 @@ describe Dragonfly::TempObject do
|
|
157
190
|
|
158
191
|
describe "initializing from a tempfile" do
|
159
192
|
|
160
|
-
def
|
161
|
-
|
193
|
+
def initialization_object(data)
|
194
|
+
new_tempfile(data)
|
162
195
|
end
|
163
196
|
|
164
197
|
it_should_behave_like "common behaviour"
|
@@ -172,8 +205,8 @@ describe Dragonfly::TempObject do
|
|
172
205
|
|
173
206
|
describe "initializing from a file" do
|
174
207
|
|
175
|
-
def
|
176
|
-
|
208
|
+
def initialization_object(data)
|
209
|
+
new_file(data)
|
177
210
|
end
|
178
211
|
|
179
212
|
it_should_behave_like "common behaviour"
|
@@ -201,41 +234,6 @@ describe Dragonfly::TempObject do
|
|
201
234
|
end
|
202
235
|
end
|
203
236
|
|
204
|
-
describe "modify_self!" do
|
205
|
-
|
206
|
-
before(:each) do
|
207
|
-
@temp_object = Dragonfly::TempObject.new('DATA_ONE')
|
208
|
-
@temp_object.data # Make sure internal stuff is initialized
|
209
|
-
@temp_object.file #
|
210
|
-
end
|
211
|
-
it "should modify itself" do
|
212
|
-
@temp_object.modify_self!('DATA_TWO')
|
213
|
-
@temp_object.data.should == 'DATA_TWO'
|
214
|
-
end
|
215
|
-
it "should return itself" do
|
216
|
-
@temp_object.modify_self!('DATA_TWO').should == @temp_object
|
217
|
-
end
|
218
|
-
it "should modify itself when the new object is a file" do
|
219
|
-
@temp_object.modify_self!(File.new(SAMPLES_DIR + '/beach.png'))
|
220
|
-
@temp_object.data.should == File.read(SAMPLES_DIR + '/beach.png')
|
221
|
-
end
|
222
|
-
it "should modify itself when the new object is a tempfile" do
|
223
|
-
tempfile = new_tempfile
|
224
|
-
data = tempfile.read
|
225
|
-
@temp_object.modify_self!(tempfile)
|
226
|
-
@temp_object.data.should == data
|
227
|
-
end
|
228
|
-
it "should still work when the object is itself" do
|
229
|
-
@temp_object.modify_self!(@temp_object)
|
230
|
-
@temp_object.data.should == 'DATA_ONE'
|
231
|
-
end
|
232
|
-
it "should keep the same name" do
|
233
|
-
@temp_object.name = 'billy.bob'
|
234
|
-
@temp_object.modify_self!('WASSUP PUNk')
|
235
|
-
@temp_object.name.should == 'billy.bob'
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
237
|
describe "name" do
|
240
238
|
before(:each) do
|
241
239
|
@obj = new_tempfile
|
@@ -254,46 +252,83 @@ describe Dragonfly::TempObject do
|
|
254
252
|
temp_object = Dragonfly::TempObject.new(file)
|
255
253
|
temp_object.name.should == 'round.gif'
|
256
254
|
end
|
257
|
-
it "should still be nil if set to empty string" do
|
258
|
-
temp_object = Dragonfly::TempObject.new('sdf')
|
259
|
-
temp_object.name = ''
|
255
|
+
it "should still be nil if set to empty string on initialize" do
|
256
|
+
temp_object = Dragonfly::TempObject.new('sdf', :name => '')
|
260
257
|
temp_object.name.should be_nil
|
261
258
|
end
|
262
259
|
end
|
263
260
|
|
264
261
|
describe "ext" do
|
265
|
-
before(:each) do
|
266
|
-
@temp_object = Dragonfly::TempObject.new('asfsadf')
|
267
|
-
end
|
268
262
|
it "should use the correct extension from name" do
|
269
|
-
|
270
|
-
|
263
|
+
temp_object = Dragonfly::TempObject.new('asfsadf', :name => 'hello.there.mate')
|
264
|
+
temp_object.ext.should == 'mate'
|
271
265
|
end
|
272
266
|
it "should be nil if name has none" do
|
273
|
-
|
274
|
-
|
267
|
+
temp_object = Dragonfly::TempObject.new('asfsadf', :name => 'hello')
|
268
|
+
temp_object.ext.should be_nil
|
275
269
|
end
|
276
270
|
it "should be nil if name is nil" do
|
277
|
-
|
278
|
-
|
271
|
+
temp_object = Dragonfly::TempObject.new('asfsadf')
|
272
|
+
temp_object.ext.should be_nil
|
279
273
|
end
|
280
274
|
end
|
281
|
-
|
275
|
+
|
282
276
|
describe "basename" do
|
283
|
-
before(:each) do
|
284
|
-
@temp_object = Dragonfly::TempObject.new('asfsadf')
|
285
|
-
end
|
286
277
|
it "should use the correct basename from name" do
|
287
|
-
|
288
|
-
|
278
|
+
temp_object = Dragonfly::TempObject.new('A', :name => 'hello.there.mate')
|
279
|
+
temp_object.basename.should == 'hello.there'
|
289
280
|
end
|
290
281
|
it "should be the name if it has no ext" do
|
291
|
-
|
292
|
-
|
282
|
+
temp_object = Dragonfly::TempObject.new('A', :name => 'hello')
|
283
|
+
temp_object.basename.should == 'hello'
|
293
284
|
end
|
294
285
|
it "should be nil if name is nil" do
|
295
|
-
|
296
|
-
|
286
|
+
temp_object = Dragonfly::TempObject.new('A', :name => nil)
|
287
|
+
temp_object.basename.should be_nil
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "meta" do
|
292
|
+
before(:each) do
|
293
|
+
@temp_object = Dragonfly::TempObject.new('get outta here!')
|
294
|
+
end
|
295
|
+
it "should return an empty hash if not set" do
|
296
|
+
@temp_object.meta.should == {}
|
297
|
+
end
|
298
|
+
it "should allow setting" do
|
299
|
+
@temp_object.meta[:teeth] = 'many'
|
300
|
+
@temp_object.meta.should == {:teeth => 'many'}
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "format" do
|
305
|
+
it "should return nil if not set" do
|
306
|
+
temp_object = Dragonfly::TempObject.new('wassin my belly??!')
|
307
|
+
temp_object.format.should be_nil
|
308
|
+
end
|
309
|
+
it "should allow setting on initialize" do
|
310
|
+
temp_object = Dragonfly::TempObject.new('wassin my belly??!', :format => :jpg)
|
311
|
+
temp_object.format.should == :jpg
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe "extract_attributes_from" do
|
316
|
+
before(:each) do
|
317
|
+
@temp_object = Dragonfly::TempObject.new("ne'er gonna give you up",
|
318
|
+
:meta => {:a => 4},
|
319
|
+
:name => 'fred.txt'
|
320
|
+
)
|
321
|
+
@attributes = {:meta => {:b => 5}, :ogle => 'bogle'}
|
322
|
+
@temp_object.extract_attributes_from(@attributes)
|
323
|
+
end
|
324
|
+
it "should overwrite its own attributes if specified" do
|
325
|
+
@temp_object.meta.should == {:b => 5}
|
326
|
+
end
|
327
|
+
it "should leave non-specified attributes untouched" do
|
328
|
+
@temp_object.name.should == 'fred.txt'
|
329
|
+
end
|
330
|
+
it "should remove attributes from the hash" do
|
331
|
+
@attributes.should == {:ogle => 'bogle'}
|
297
332
|
end
|
298
333
|
end
|
299
334
|
|