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
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
module M
|
4
|
-
def m; end
|
5
|
-
end
|
6
|
-
|
7
|
-
class A
|
8
|
-
include Dragonfly::Delegatable
|
9
|
-
def a; end
|
10
|
-
end
|
11
|
-
|
12
|
-
class B < A
|
13
|
-
include M
|
14
|
-
def b; end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Dragonfly::Delegatable do
|
18
|
-
|
19
|
-
describe "delegatable_methods" do
|
20
|
-
it "should include all methods defined after including, including mixed-in and inherited" do
|
21
|
-
B.new.delegatable_methods.should == [:b, :m, :a].map{|m| m.to_method_name }
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should work the second (cached) time" do
|
25
|
-
b = B.new
|
26
|
-
b.delegatable_methods
|
27
|
-
b.delegatable_methods.should == [:b, :m, :a].map{|m| m.to_method_name }
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
class CarDriver
|
4
|
-
include Dragonfly::Delegatable
|
5
|
-
|
6
|
-
def drive(car)
|
7
|
-
"Driving car #{car}"
|
8
|
-
end
|
9
|
-
def open_boot
|
10
|
-
:open_boot
|
11
|
-
end
|
12
|
-
def clean(car)
|
13
|
-
"Cleaning #{car}"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class LorryDriver
|
18
|
-
include Dragonfly::BelongsToApp
|
19
|
-
include Dragonfly::Delegatable
|
20
|
-
|
21
|
-
def drive(lorry)
|
22
|
-
"Driving lorry #{lorry}"
|
23
|
-
end
|
24
|
-
def open_back_doors
|
25
|
-
:open_back_doors
|
26
|
-
end
|
27
|
-
def clean(lorry)
|
28
|
-
throw :unable_to_handle
|
29
|
-
end
|
30
|
-
def pick_up(lorry)
|
31
|
-
throw :unable_to_handle
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class BusDriver
|
36
|
-
include Dragonfly::Delegatable
|
37
|
-
include Dragonfly::Configurable
|
38
|
-
|
39
|
-
configurable_attr :height
|
40
|
-
|
41
|
-
def initialize(age); @age = age; end
|
42
|
-
def age; @age; end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe Dragonfly::Delegator do
|
46
|
-
|
47
|
-
before(:each) do
|
48
|
-
@delegator = Object.new
|
49
|
-
@delegator.extend Dragonfly::Delegator
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "when no items have been registered" do
|
53
|
-
|
54
|
-
it "should raise an error when calling an unknown method" do
|
55
|
-
lambda{ @delegator.drive }.should raise_error(NoMethodError)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should should return delegatable_methods as an empty array" do
|
59
|
-
@delegator.delegatable_methods.should == []
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return the object registered when registering" do
|
63
|
-
@delegator.register(CarDriver).should be_a(CarDriver)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "after registering a number of classes" do
|
69
|
-
|
70
|
-
before(:each) do
|
71
|
-
@delegator.app = Dragonfly::App[:test]
|
72
|
-
@car_driver = @delegator.register(CarDriver)
|
73
|
-
@lorry_driver = @delegator.register(LorryDriver)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should raise an error when calling an unknown method" do
|
77
|
-
lambda{ @delegator.swim }.should raise_error(NoMethodError)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should correctly delegate when only one item implements the method" do
|
81
|
-
@delegator.open_boot.should == :open_boot
|
82
|
-
@delegator.open_back_doors.should == :open_back_doors
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should allow delegating explicitly" do
|
86
|
-
@delegator.delegate(:open_boot).should == :open_boot
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should delegate to the last registered when more than one item implements the method" do
|
90
|
-
@delegator.drive('fishmonger').should == "Driving lorry fishmonger"
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should return all the callable methods" do
|
94
|
-
@delegator.delegatable_methods.sort.should == %w(clean drive open_back_doors open_boot pick_up).map{|m| m.to_method_name }
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should say if if has a callable method (as a string)" do
|
98
|
-
@delegator.has_delegatable_method?('drive').should be_true
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should say if if has a callable method (as a symbol)" do
|
102
|
-
@delegator.has_delegatable_method?(:drive).should be_true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should skip methods that throw :unable_to_handle" do
|
106
|
-
@delegator.clean('my car').should == "Cleaning my car"
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should raise an error if nothing was able to handle it" do
|
110
|
-
lambda{ @delegator.pick_up('my lorry') }.should raise_error(Dragonfly::Delegator::UnableToHandle)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should return registered objects" do
|
114
|
-
@delegator.registered_objects.should == [@car_driver, @lorry_driver]
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should set the registered object's app to its own if object should belong to an app" do
|
118
|
-
@lorry_driver.app.should == @delegator.app
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should enable unregistering classes" do
|
122
|
-
@delegator.unregister(LorryDriver)
|
123
|
-
@delegator.registered_objects.map(&:class).should == [CarDriver]
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should enable unregistering all" do
|
127
|
-
@delegator.unregister_all
|
128
|
-
@delegator.registered_objects.should == []
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "configuring on registration" do
|
134
|
-
it "should pass the args on register to the object initializer" do
|
135
|
-
@delegator.register(BusDriver, 43)
|
136
|
-
@delegator.age.should == 43
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should run configure if a block given" do
|
140
|
-
@delegator.register(BusDriver, 43){|c| c.height = 180 }
|
141
|
-
@delegator.height.should == 180
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ExtendedTempObject do
|
4
|
-
|
5
|
-
describe "when configured correctly" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@app = Dragonfly::App[:test]
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "analysis" do
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
analyser_class = Class.new(Dragonfly::Analysis::Base) do
|
15
|
-
def width(temp_object); temp_object.data.size; end
|
16
|
-
end
|
17
|
-
@analyser = @app.register_analyser(analyser_class)
|
18
|
-
@object = Dragonfly::ExtendedTempObject.new('asdf', @app)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should respond to something that the analyser responds to" do
|
22
|
-
@object.should respond_to(:width)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should not respond to something that the analyser doesn't respond to" do
|
26
|
-
@object.should_not respond_to(:spaghetti)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should delegate the analysis to the analyser" do
|
30
|
-
@object.width.should == 4
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should cache the result so that it doesn't call it a second time" do
|
34
|
-
@analyser.should_receive(:width).with(@object).and_return(4)
|
35
|
-
@object.width.should == 4
|
36
|
-
@analyser.should_not_receive(:width)
|
37
|
-
@object.width.should == 4
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should do the analysis again when it has been modified" do
|
41
|
-
@object.width.should == 4
|
42
|
-
@object.modify_self!('hellothisisnew')
|
43
|
-
@object.width.should == 14
|
44
|
-
@analyser.should_not_receive(:width)
|
45
|
-
@object.width.should == 14
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "encoding" do
|
51
|
-
before(:each) do
|
52
|
-
encoder_class = Class.new(Dragonfly::Encoding::Base)
|
53
|
-
@encoder = @app.register_encoder(encoder_class)
|
54
|
-
@temp_object = Dragonfly::ExtendedTempObject.new('abcde', @app)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should encode the data and return the new temp object" do
|
58
|
-
@encoder.should_receive(:encode).with(@temp_object, :some_format, :some => 'option').and_return('ABCDE')
|
59
|
-
new_temp_object = @temp_object.encode(:some_format, :some => 'option')
|
60
|
-
new_temp_object.data.should == 'ABCDE'
|
61
|
-
end
|
62
|
-
it "should encode its own data" do
|
63
|
-
@encoder.should_receive(:encode).with(@temp_object, :some_format, :some => 'option').and_return('ABCDE')
|
64
|
-
@temp_object.encode!(:some_format, :some => 'option')
|
65
|
-
@temp_object.data.should == 'ABCDE'
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
@@ -1,298 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::Parameters do
|
4
|
-
|
5
|
-
def standard_attributes
|
6
|
-
{
|
7
|
-
:uid => 'ahaha',
|
8
|
-
:processing_method => :round,
|
9
|
-
:format => :gif,
|
10
|
-
:processing_options => {:radius => 5},
|
11
|
-
:encoding => {:flumps_per_minute => 56}
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "initializing" do
|
16
|
-
it "should allow initializing without a hash" do
|
17
|
-
parameters = Dragonfly::Parameters.new
|
18
|
-
parameters.uid.should be_nil
|
19
|
-
end
|
20
|
-
it "should allow initializing with a hash" do
|
21
|
-
parameters = Dragonfly::Parameters.new(:uid => 'b')
|
22
|
-
parameters.uid.should == 'b'
|
23
|
-
end
|
24
|
-
it "should raise an error if initialized with a bad hash key" do
|
25
|
-
lambda{
|
26
|
-
Dragonfly::Parameters.new(:fridge => 'cold')
|
27
|
-
}.should raise_error(ArgumentError)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "accessors" do
|
32
|
-
before(:each) do
|
33
|
-
@parameters = Dragonfly::Parameters.new
|
34
|
-
end
|
35
|
-
it "should give the accessors the correct defaults" do
|
36
|
-
@parameters.uid.should be_nil
|
37
|
-
@parameters.processing_method.should be_nil
|
38
|
-
@parameters.format.should be_nil
|
39
|
-
@parameters.processing_options.should == {}
|
40
|
-
@parameters.encoding.should == {}
|
41
|
-
end
|
42
|
-
it "should provide writers too" do
|
43
|
-
@parameters.uid = 'hello'
|
44
|
-
@parameters.uid.should == 'hello'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "array style accessors" do
|
49
|
-
before(:each) do
|
50
|
-
@parameters = Dragonfly::Parameters.new(:uid => 'hello')
|
51
|
-
end
|
52
|
-
it "should be the same as calling the corresponding reader" do
|
53
|
-
@parameters[:uid].should == @parameters.uid
|
54
|
-
end
|
55
|
-
it "should be the same as calling the corresponding writer" do
|
56
|
-
@parameters[:uid] = 'goodbye'
|
57
|
-
@parameters.uid.should == 'goodbye'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "comparing" do
|
62
|
-
before(:each) do
|
63
|
-
@parameters1 = Dragonfly::Parameters.new(standard_attributes)
|
64
|
-
@parameters2 = Dragonfly::Parameters.new(standard_attributes)
|
65
|
-
end
|
66
|
-
it "should return true when two have all the same attributes" do
|
67
|
-
@parameters1.should == @parameters2
|
68
|
-
end
|
69
|
-
%w(uid processing_method format processing_options encoding).each do |attribute|
|
70
|
-
it "should return false when #{attribute} is different" do
|
71
|
-
@parameters2[attribute.to_sym] = 'fish'
|
72
|
-
@parameters1.should_not == @parameters2
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "to_hash" do
|
78
|
-
it "should return the attributes as a hash" do
|
79
|
-
parameters = Dragonfly::Parameters.new(standard_attributes)
|
80
|
-
parameters.to_hash.should == standard_attributes
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "custom parameters classes" do
|
85
|
-
|
86
|
-
before(:each) do
|
87
|
-
@parameters_class = Class.new(Dragonfly::Parameters)
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "when defaults are not set" do
|
91
|
-
it "should return the standard defaults" do
|
92
|
-
parameters = @parameters_class.new_with_defaults
|
93
|
-
parameters.processing_method.should be_nil
|
94
|
-
parameters.processing_options.should == {}
|
95
|
-
parameters.format.should be_nil
|
96
|
-
parameters.encoding.should == {}
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "when defaults are set" do
|
101
|
-
before(:each) do
|
102
|
-
@parameters_class.configure do |c|
|
103
|
-
c.default_processing_method = :resize
|
104
|
-
c.default_processing_options = {:scale => '0.5'}
|
105
|
-
c.default_format = :png
|
106
|
-
c.default_encoding = {:bit_rate => 24}
|
107
|
-
end
|
108
|
-
end
|
109
|
-
it "should not affect .new" do
|
110
|
-
parameters = @parameters_class.new
|
111
|
-
parameters.processing_method.should be_nil
|
112
|
-
parameters.processing_options.should == {}
|
113
|
-
parameters.format.should be_nil
|
114
|
-
parameters.encoding.should == {}
|
115
|
-
end
|
116
|
-
it "should return the default if not set on parameters" do
|
117
|
-
parameters = @parameters_class.new_with_defaults
|
118
|
-
parameters.processing_method.should == :resize
|
119
|
-
parameters.processing_options.should == {:scale => '0.5'}
|
120
|
-
parameters.format.should == :png
|
121
|
-
parameters.encoding.should == {:bit_rate => 24}
|
122
|
-
end
|
123
|
-
it "should return the correct parameter if set" do
|
124
|
-
parameters = @parameters_class.new_with_defaults(
|
125
|
-
:processing_method => :yo,
|
126
|
-
:processing_options => {:a => 'b'},
|
127
|
-
:format => :txt,
|
128
|
-
:encoding => {:ah => :arg}
|
129
|
-
)
|
130
|
-
parameters.processing_method.should == :yo
|
131
|
-
parameters.processing_options.should == {:a => 'b'}
|
132
|
-
parameters.format.should == :txt
|
133
|
-
parameters.encoding.should == {:ah => :arg}
|
134
|
-
end
|
135
|
-
it "should not override nil if explicity set" do
|
136
|
-
@parameters_class.new_with_defaults(:format => nil).format.should be_nil
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "shortcuts" do
|
143
|
-
|
144
|
-
before(:each) do
|
145
|
-
@parameters_class = Class.new(Dragonfly::Parameters)
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should allow for setting simple shortcuts" do
|
149
|
-
attributes = {
|
150
|
-
:processing_method => :duncan,
|
151
|
-
:processing_options => {:bill => :gates},
|
152
|
-
:format => 'mamamia',
|
153
|
-
:encoding => {:doogie => :howser}
|
154
|
-
}
|
155
|
-
@parameters_class.add_shortcut(:doobie, attributes)
|
156
|
-
@parameters_class.hash_from_shortcut(:doobie).should == attributes
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should raise an error if the shortcut doesn't exist" do
|
160
|
-
lambda{
|
161
|
-
@parameters_class.hash_from_shortcut(:idontexist)
|
162
|
-
}.should raise_error(Dragonfly::Parameters::InvalidShortcut)
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "block shortcuts" do
|
166
|
-
|
167
|
-
before(:each) do
|
168
|
-
@parameters_class.add_shortcut(/^hello.*$/, Symbol) do |processing_method, format, matches|
|
169
|
-
{:processing_method => processing_method, :format => format}
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should allow for more complex shortcuts by using a block and matching args" do
|
174
|
-
@parameters_class.hash_from_shortcut('hellothere', :tif).should == {:processing_method => 'hellothere', :format => :tif}
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should raise an error if the shortcut doesn't match properly" do
|
178
|
-
lambda{
|
179
|
-
@parameters_class.hash_from_shortcut('hellothere', 'tif')
|
180
|
-
}.should raise_error(Dragonfly::Parameters::InvalidShortcut)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should raise an error if the shortcut matches but has the wrong number of args" do
|
184
|
-
lambda{
|
185
|
-
@parameters_class.hash_from_shortcut('hellothere', :tif, 'YO')
|
186
|
-
}.should raise_error(Dragonfly::Parameters::InvalidShortcut)
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should let later shortcuts have priority over earlier ones" do
|
190
|
-
@parameters_class.add_shortcut(/hello/, :tif) do |a, b|
|
191
|
-
{:processing_method => :bumble}
|
192
|
-
end
|
193
|
-
@parameters_class.hash_from_shortcut('hellothere', :tif).should == {:processing_method => :bumble}
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
describe "single regexp shortcuts" do
|
199
|
-
|
200
|
-
it "should yield regexp match data if the args is just one regexp" do
|
201
|
-
@parameters_class.add_shortcut(/^hello(.*)$/) do |arg, match_data|
|
202
|
-
{:processing_options => {:arg => arg, :match_data => match_data}}
|
203
|
-
end
|
204
|
-
processing_options = @parameters_class.hash_from_shortcut('hellothere')[:processing_options]
|
205
|
-
processing_options[:arg].should == 'hellothere'
|
206
|
-
processing_options[:match_data].should be_a(MatchData)
|
207
|
-
processing_options[:match_data][1].should == 'there'
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
describe ".from_shortcut" do
|
213
|
-
before(:each) do
|
214
|
-
@parameters_class.add_shortcut(/^hello.*$/) do |processing_method, matches|
|
215
|
-
{:processing_method => processing_method}
|
216
|
-
end
|
217
|
-
@parameters_class.default_format = :tif
|
218
|
-
end
|
219
|
-
it "should just be the parameters equivalent of 'hash_from_shortcut', including defaults" do
|
220
|
-
@parameters_class.from_shortcut('hellothere').should ==
|
221
|
-
@parameters_class.new(@parameters_class.hash_from_shortcut('hellothere').merge(:format => :tif))
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
|
-
describe ".from_args" do
|
228
|
-
|
229
|
-
before(:each) do
|
230
|
-
@parameters_class = Class.new(Dragonfly::Parameters)
|
231
|
-
@parameters_class.default_format = :tif
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should be the same as 'new_with_defaults' if empty args" do
|
235
|
-
@parameters_class.from_args.should == @parameters_class.new_with_defaults
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should treat the arguments as actual parameter values (including defaults) if args is a single hash" do
|
239
|
-
@parameters_class.from_args(:uid => 'some_uid', :processing_method => :resize).
|
240
|
-
should == @parameters_class.new_with_defaults(:uid => 'some_uid', :processing_method => :resize)
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should simply return the same parameters if args is a single parameters object" do
|
244
|
-
@parameters_class.from_args(@parameters_class.new(:uid => 'some_uid', :processing_method => :resize)).
|
245
|
-
should == @parameters_class.new(:uid => 'some_uid', :processing_method => :resize)
|
246
|
-
end
|
247
|
-
|
248
|
-
it "should treat the arguments as shortcut arguments otherwise" do
|
249
|
-
@parameters_class.should_receive(:from_shortcut).with('innit').and_return(parameters = mock('parameters'))
|
250
|
-
@parameters_class.from_args('innit').should == parameters
|
251
|
-
end
|
252
|
-
|
253
|
-
end
|
254
|
-
|
255
|
-
describe "unique_signature" do
|
256
|
-
|
257
|
-
before(:each) do
|
258
|
-
@parameters = Dragonfly::Parameters.new(standard_attributes)
|
259
|
-
@parameters2 = Dragonfly::Parameters.new(standard_attributes)
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should a unique identifier based on its attributes" do
|
263
|
-
@parameters.unique_signature.should be_a(String)
|
264
|
-
@parameters.unique_signature.length.should > 0
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should be the same if the attributes are the same" do
|
268
|
-
@parameters.unique_signature.should == @parameters2.unique_signature
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should be different when the uid is changed" do
|
272
|
-
@parameters2.uid = 'different yo'
|
273
|
-
@parameters.unique_signature.should_not == @parameters2.unique_signature
|
274
|
-
end
|
275
|
-
|
276
|
-
it "should be different when the format is changed" do
|
277
|
-
@parameters2.format = :tif
|
278
|
-
@parameters.unique_signature.should_not == @parameters2.unique_signature
|
279
|
-
end
|
280
|
-
|
281
|
-
it "should be different when the processing_method is changed" do
|
282
|
-
@parameters2.processing_method = :doogie
|
283
|
-
@parameters.unique_signature.should_not == @parameters2.unique_signature
|
284
|
-
end
|
285
|
-
|
286
|
-
it "should be different when the processing_options are changed" do
|
287
|
-
@parameters2.processing_options[:slumdog] = 'millionaire'
|
288
|
-
@parameters.unique_signature.should_not == @parameters2.unique_signature
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should be different when the encoding options are changed" do
|
292
|
-
@parameters2.encoding[:flumps_per_minute] = 50.3
|
293
|
-
@parameters.unique_signature.should_not == @parameters2.unique_signature
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
|
298
|
-
end
|