dragonfly 0.1.6 → 0.2.1
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/.yardopts +4 -0
- data/{README.markdown → README.md} +12 -24
- data/Rakefile +6 -6
- data/VERSION +1 -1
- data/config.rb +1 -3
- data/docs.watchr +1 -1
- data/dragonfly-rails.gemspec +2 -5
- data/dragonfly.gemspec +32 -12
- data/extra_docs/ActiveRecord.md +195 -0
- data/extra_docs/Analysers.md +63 -0
- data/extra_docs/DataStorage.md +33 -0
- data/extra_docs/Encoding.md +58 -0
- data/extra_docs/GettingStarted.md +114 -0
- data/extra_docs/Processing.md +58 -0
- data/extra_docs/Shortcuts.md +118 -0
- data/extra_docs/UsingWithRails.md +104 -0
- data/features/{dragonfly.feature → images.feature} +14 -4
- data/features/no_processing.feature +20 -0
- data/features/steps/dragonfly_steps.rb +29 -8
- data/features/support/env.rb +20 -8
- data/generators/dragonfly_app/USAGE +0 -1
- data/generators/dragonfly_app/dragonfly_app_generator.rb +1 -13
- data/generators/dragonfly_app/templates/metal_file.erb +1 -1
- data/lib/dragonfly/active_record_extensions.rb +1 -0
- data/lib/dragonfly/active_record_extensions/attachment.rb +52 -6
- data/lib/dragonfly/active_record_extensions/validations.rb +26 -6
- data/lib/dragonfly/analysis/base.rb +6 -3
- data/lib/dragonfly/analysis/r_magick_analyser.rb +0 -6
- data/lib/dragonfly/app.rb +53 -35
- data/lib/dragonfly/configurable.rb +1 -1
- data/lib/dragonfly/data_storage/file_data_store.rb +8 -8
- data/lib/dragonfly/delegatable.rb +14 -0
- data/lib/dragonfly/delegator.rb +50 -0
- data/lib/dragonfly/encoding/base.rb +7 -7
- data/lib/dragonfly/encoding/r_magick_encoder.rb +3 -0
- data/lib/dragonfly/encoding/transparent_encoder.rb +1 -1
- data/lib/dragonfly/extended_temp_object.rb +13 -7
- data/lib/dragonfly/parameters.rb +17 -11
- data/lib/dragonfly/processing/base.rb +9 -0
- data/lib/dragonfly/processing/r_magick_processor.rb +15 -1
- data/lib/dragonfly/r_magick_configuration.rb +12 -8
- data/lib/dragonfly/rails/images.rb +1 -1
- data/lib/dragonfly/temp_object.rb +14 -2
- data/lib/dragonfly/url_handler.rb +5 -6
- data/samples/sample.docx +0 -0
- data/spec/dragonfly/active_record_extensions/model_spec.rb +175 -84
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +0 -8
- data/spec/dragonfly/app_spec.rb +3 -3
- data/spec/dragonfly/configurable_spec.rb +1 -1
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +55 -40
- data/spec/dragonfly/delegatable_spec.rb +32 -0
- data/spec/dragonfly/delegator_spec.rb +133 -0
- data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +28 -0
- data/spec/dragonfly/extended_temp_object_spec.rb +5 -5
- data/spec/dragonfly/parameters_spec.rb +22 -32
- data/spec/dragonfly/processing/rmagick_processor_spec.rb +1 -2
- data/spec/dragonfly/temp_object_spec.rb +51 -0
- data/spec/dragonfly/url_handler_spec.rb +10 -15
- data/yard/handlers/configurable_attr_handler.rb +38 -0
- data/yard/setup.rb +9 -0
- data/yard/templates/default/fulldoc/html/css/common.css +27 -0
- data/yard/templates/default/module/html/configuration_summary.erb +31 -0
- data/yard/templates/default/module/setup.rb +17 -0
- metadata +31 -12
- data/features/support/image_helpers.rb +0 -9
- data/generators/dragonfly_app/templates/custom_processing.erb +0 -13
- data/lib/dragonfly/analysis/analyser.rb +0 -45
- data/lib/dragonfly/processing/processor.rb +0 -14
- data/spec/dragonfly/analysis/analyser_spec.rb +0 -85
@@ -16,14 +16,6 @@ describe Dragonfly::Analysis::RMagickAnalyser do
|
|
16
16
|
@analyser.height(@beach).should == 355
|
17
17
|
end
|
18
18
|
|
19
|
-
it "should return the mime type" do
|
20
|
-
@analyser.mime_type(@beach).should == 'image/png'
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should return nil if it doesn't know the mime type" do
|
24
|
-
@analyser.mime_type(Dragonfly::TempObject.new('asdf')).should be_nil
|
25
|
-
end
|
26
|
-
|
27
19
|
it "should return the number of colours" do
|
28
20
|
@analyser.number_of_colours(@beach).should == 34703
|
29
21
|
end
|
data/spec/dragonfly/app_spec.rb
CHANGED
@@ -60,7 +60,7 @@ describe Dragonfly::App do
|
|
60
60
|
it "should return 404 if the datastore raises data not found" do
|
61
61
|
@app.url_handler.protect_from_dos_attacks = false
|
62
62
|
@app.should_receive(:fetch).and_raise(Dragonfly::DataStorage::DataNotFound)
|
63
|
-
response = make_request(@app, 'hello.png')
|
63
|
+
response = make_request(@app, '/hello.png')
|
64
64
|
response.status.should == 404
|
65
65
|
end
|
66
66
|
|
@@ -76,12 +76,12 @@ describe Dragonfly::App do
|
|
76
76
|
end
|
77
77
|
it "should use the temp object mime-type" do
|
78
78
|
@temp_object.should_receive(:mime_type).and_return 'my/type'
|
79
|
-
response = make_request(@app, 'hello.png')
|
79
|
+
response = make_request(@app, '/hello.png')
|
80
80
|
response.headers['Content-Type'].should == 'my/type'
|
81
81
|
end
|
82
82
|
it "should use the app's fallback mime-type if the temp_object one isn't known" do
|
83
83
|
@temp_object.should_receive(:mime_type).and_return nil
|
84
|
-
response = make_request(@app, 'hello.png')
|
84
|
+
response = make_request(@app, '/hello.png')
|
85
85
|
response.headers['Content-Type'].should == 'egg/heads'
|
86
86
|
end
|
87
87
|
end
|
@@ -20,12 +20,12 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
20
20
|
|
21
21
|
it_should_behave_like 'data_store'
|
22
22
|
|
23
|
+
before(:each) do
|
24
|
+
@temp_object = Dragonfly::TempObject.new('goobydoo')
|
25
|
+
end
|
26
|
+
|
23
27
|
describe "store" do
|
24
28
|
|
25
|
-
before(:each) do
|
26
|
-
@temp_object = Dragonfly::TempObject.new('goobydoo')
|
27
|
-
end
|
28
|
-
|
29
29
|
def it_should_write_to_file(storage_path, temp_object)
|
30
30
|
FileUtils.should_receive(:cp).with(temp_object.path, storage_path)
|
31
31
|
end
|
@@ -35,30 +35,15 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
35
35
|
@data_store.store(@temp_object)
|
36
36
|
end
|
37
37
|
|
38
|
-
it "should store the file with a numbered suffix if the filename already exists" do
|
39
|
-
FileUtils.mkdir_p(@file_pattern_prefix)
|
40
|
-
FileUtils.touch("#{@file_pattern_prefix}_file")
|
41
|
-
it_should_write_to_file("#{@file_pattern_prefix}_file_2", @temp_object)
|
42
|
-
@data_store.store(@temp_object)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should store the file with an incremented number suffix if the filename already exists" do
|
46
|
-
FileUtils.mkdir_p(@file_pattern_prefix)
|
47
|
-
FileUtils.touch("#{@file_pattern_prefix}_file")
|
48
|
-
FileUtils.touch("#{@file_pattern_prefix}_file_2")
|
49
|
-
it_should_write_to_file("#{@file_pattern_prefix}_file_3", @temp_object)
|
50
|
-
@data_store.store(@temp_object)
|
51
|
-
end
|
52
|
-
|
53
38
|
it "should use the temp_object name if it exists" do
|
54
39
|
@temp_object.name = 'hello'
|
55
40
|
it_should_write_to_file("#{@file_pattern_prefix}_hello", @temp_object)
|
56
41
|
@data_store.store(@temp_object)
|
57
42
|
end
|
58
43
|
|
59
|
-
it "should
|
44
|
+
it "should strip the extension of the temp_object name" do
|
60
45
|
@temp_object.name = 'hello.you.png'
|
61
|
-
it_should_write_to_file("#{@file_pattern_prefix}_hello.you
|
46
|
+
it_should_write_to_file("#{@file_pattern_prefix}_hello.you", @temp_object)
|
62
47
|
@data_store.store(@temp_object)
|
63
48
|
end
|
64
49
|
|
@@ -68,40 +53,70 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
68
53
|
@data_store.store(@temp_object)
|
69
54
|
end
|
70
55
|
|
71
|
-
|
72
|
-
|
73
|
-
|
56
|
+
describe "when the filename already exists" do
|
57
|
+
|
58
|
+
it "should store the file with a numbered suffix" do
|
59
|
+
FileUtils.mkdir_p(@file_pattern_prefix)
|
60
|
+
FileUtils.touch("#{@file_pattern_prefix}_file")
|
61
|
+
it_should_write_to_file("#{@file_pattern_prefix}_file_2", @temp_object)
|
62
|
+
@data_store.store(@temp_object)
|
63
|
+
end
|
74
64
|
|
75
|
-
|
76
|
-
|
77
|
-
|
65
|
+
it "should store the file with a numbered suffix taking into account the name" do
|
66
|
+
@temp_object.name = 'hello.png'
|
67
|
+
FileUtils.mkdir_p(@file_pattern_prefix)
|
68
|
+
FileUtils.touch("#{@file_pattern_prefix}_hello")
|
69
|
+
it_should_write_to_file("#{@file_pattern_prefix}_hello_2", @temp_object)
|
70
|
+
@data_store.store(@temp_object)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should store the file with an incremented number suffix" do
|
74
|
+
FileUtils.mkdir_p(@file_pattern_prefix)
|
75
|
+
FileUtils.touch("#{@file_pattern_prefix}_file")
|
76
|
+
FileUtils.touch("#{@file_pattern_prefix}_file_2")
|
77
|
+
it_should_write_to_file("#{@file_pattern_prefix}_file_3", @temp_object)
|
78
|
+
@data_store.store(@temp_object)
|
79
|
+
end
|
80
|
+
|
78
81
|
end
|
82
|
+
|
83
|
+
describe "return value" do
|
84
|
+
|
85
|
+
it "should return the filepath without the root of the stored file when a file name is not provided" do
|
86
|
+
@data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}_file"
|
87
|
+
end
|
79
88
|
|
89
|
+
it "should return the filepath without the root of the stored file when a file name is provided" do
|
90
|
+
@temp_object.name = 'hello.you.png'
|
91
|
+
@data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}_hello.you"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "errors" do
|
99
|
+
|
80
100
|
it "should raise an error if it can't create a directory" do
|
81
101
|
FileUtils.should_receive(:mkdir_p).and_raise(Errno::EACCES)
|
82
102
|
lambda{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::DataStorage::UnableToStore)
|
83
103
|
end
|
84
|
-
|
104
|
+
|
85
105
|
it "should raise an error if it can't create a file" do
|
86
106
|
FileUtils.should_receive(:cp).and_raise(Errno::EACCES)
|
87
107
|
lambda{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::DataStorage::UnableToStore)
|
88
108
|
end
|
89
|
-
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "destroying" do
|
113
|
+
|
90
114
|
it "should prune empty directories when destroying" do
|
91
115
|
uid = @data_store.store(@temp_object)
|
92
116
|
@data_store.destroy(uid)
|
93
117
|
@data_store.root_path.should be_an_empty_directory
|
94
118
|
end
|
95
|
-
|
96
|
-
describe "retrieving" do
|
97
|
-
it "should retrieve the correct file even though the extension isn't given" do
|
98
|
-
@temp_object.name = 'hello.there'
|
99
|
-
uid = @data_store.store(@temp_object)
|
100
|
-
uid.should =~ /_hello$/
|
101
|
-
Dragonfly::TempObject.new(@data_store.retrieve(uid)).data.should == @temp_object.data
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
119
|
+
|
105
120
|
end
|
106
|
-
|
121
|
+
|
107
122
|
end
|
@@ -0,0 +1,32 @@
|
|
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.sort.should == %w(a b m)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should work the second (cached) time" do
|
25
|
+
b = B.new
|
26
|
+
b.delegatable_methods
|
27
|
+
b.delegatable_methods.sort.should == %w(a b m)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,133 @@
|
|
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::Delegatable
|
19
|
+
|
20
|
+
def drive(lorry)
|
21
|
+
"Driving lorry #{lorry}"
|
22
|
+
end
|
23
|
+
def open_back_doors
|
24
|
+
:open_back_doors
|
25
|
+
end
|
26
|
+
def clean(lorry)
|
27
|
+
throw :unable_to_handle
|
28
|
+
end
|
29
|
+
def pick_up(lorry)
|
30
|
+
throw :unable_to_handle
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class BusDriver
|
35
|
+
include Dragonfly::Delegatable
|
36
|
+
include Dragonfly::Configurable
|
37
|
+
|
38
|
+
configurable_attr :height
|
39
|
+
|
40
|
+
def initialize(age); @age = age; end
|
41
|
+
def age; @age; end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Dragonfly::Delegator do
|
45
|
+
|
46
|
+
before(:each) do
|
47
|
+
@delegator = Dragonfly::Delegator.new
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "when no items have been registered" do
|
51
|
+
|
52
|
+
it "should raise an error when calling an unknown method" do
|
53
|
+
lambda{ @delegator.drive }.should raise_error(NoMethodError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should should return callable_methods as an empty array" do
|
57
|
+
@delegator.callable_methods.should == []
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "after registering a number of classes" do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
@delegator.register(CarDriver)
|
66
|
+
@delegator.register(LorryDriver)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should raise an error when calling an unknown method" do
|
70
|
+
lambda{ @delegator.swim }.should raise_error(NoMethodError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should correctly delegate when only one item implements the method" do
|
74
|
+
@delegator.open_boot.should == :open_boot
|
75
|
+
@delegator.open_back_doors.should == :open_back_doors
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should delegate to the last registered when more than one item implements the method" do
|
79
|
+
@delegator.drive('fishmonger').should == "Driving lorry fishmonger"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return all the callable methods" do
|
83
|
+
@delegator.callable_methods.sort.should == %w(clean drive open_back_doors open_boot pick_up)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should say if if has a callable method (as a string)" do
|
87
|
+
@delegator.has_callable_method?('drive').should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should say if if has a callable method (as a symbol)" do
|
91
|
+
@delegator.has_callable_method?(:drive).should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should skip methods that throw :unable_to_handle" do
|
95
|
+
@delegator.clean('my car').should == "Cleaning my car"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should raise an error if nothing was able to handle it" do
|
99
|
+
lambda{ @delegator.pick_up('my lorry') }.should raise_error(Dragonfly::Delegator::UnableToHandle)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return registered objects" do
|
103
|
+
objects = @delegator.registered_objects
|
104
|
+
objects.length.should == 2
|
105
|
+
objects[0].should be_a(CarDriver)
|
106
|
+
objects[1].should be_a(LorryDriver)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should enable unregistering classes" do
|
110
|
+
@delegator.unregister(LorryDriver)
|
111
|
+
@delegator.registered_objects.map(&:class).should == [CarDriver]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should enable unregistering all" do
|
115
|
+
@delegator.unregister_all
|
116
|
+
@delegator.registered_objects.should == []
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "configuring on registration" do
|
122
|
+
it "should pass the args on register to the object initializer" do
|
123
|
+
@delegator.register(BusDriver, 43)
|
124
|
+
@delegator.age.should == 43
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should run configure if a block given" do
|
128
|
+
@delegator.register(BusDriver, 43){|c| c.height = 180 }
|
129
|
+
@delegator.height.should == 180
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Dragonfly::Encoding::RMagickEncoder do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
|
7
|
+
@image = Dragonfly::TempObject.new(File.new(sample_file))
|
8
|
+
@encoder = Dragonfly::Encoding::RMagickEncoder.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#encode" do
|
12
|
+
|
13
|
+
it "should encode the image to the correct format" do
|
14
|
+
image = @encoder.encode(@image, :gif)
|
15
|
+
image.should have_format('gif')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should throw :unable_to_handle if the format is not handleable" do
|
19
|
+
test_string = "I'm a string"
|
20
|
+
catch :unable_to_handle do
|
21
|
+
@encoder.encode(@image, :goofy)
|
22
|
+
test_string = "This line should not happen"
|
23
|
+
end
|
24
|
+
test_string.should == "I'm a string"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -12,11 +12,11 @@ describe Dragonfly::ExtendedTempObject do
|
|
12
12
|
describe "when configured correctly" do
|
13
13
|
|
14
14
|
before(:each) do
|
15
|
-
@analyser = mock('analyser', :
|
16
|
-
@analyser.stub!(:
|
15
|
+
@analyser = mock('analyser', :has_callable_method? => false)
|
16
|
+
@analyser.stub!(:has_callable_method?).with(:width).and_return(true)
|
17
17
|
@processor = mock('processor')
|
18
18
|
@encoder = mock('encoder')
|
19
|
-
@app = mock('app', :
|
19
|
+
@app = mock('app', :analysers => @analyser, :processor => @processor, :encoder => @encoder)
|
20
20
|
@klass = Class.new(Dragonfly::ExtendedTempObject)
|
21
21
|
@klass.app = @app
|
22
22
|
@object = @klass.new('asdf')
|
@@ -25,12 +25,12 @@ describe Dragonfly::ExtendedTempObject do
|
|
25
25
|
describe "analysis" do
|
26
26
|
|
27
27
|
it "should respond to something that the analyser responds to" do
|
28
|
-
@analyser.should_receive(:
|
28
|
+
@analyser.should_receive(:has_callable_method?).with(:some_method).and_return(true)
|
29
29
|
@object.should respond_to(:some_method)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should not respond to something that the analyser doesn't respond to" do
|
33
|
-
@analyser.should_receive(:
|
33
|
+
@analyser.should_receive(:has_callable_method?).with(:some_method).and_return(false)
|
34
34
|
@object.should_not respond_to(:some_method)
|
35
35
|
end
|
36
36
|
|
@@ -89,7 +89,7 @@ describe Dragonfly::Parameters do
|
|
89
89
|
|
90
90
|
describe "when defaults are not set" do
|
91
91
|
it "should return the standard defaults" do
|
92
|
-
parameters = @parameters_class.
|
92
|
+
parameters = @parameters_class.new_with_defaults
|
93
93
|
parameters.processing_method.should be_nil
|
94
94
|
parameters.processing_options.should == {}
|
95
95
|
parameters.format.should be_nil
|
@@ -106,15 +106,22 @@ describe Dragonfly::Parameters do
|
|
106
106
|
c.default_encoding = {:bit_rate => 24}
|
107
107
|
end
|
108
108
|
end
|
109
|
-
it "should
|
109
|
+
it "should not affect .new" do
|
110
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
|
111
118
|
parameters.processing_method.should == :resize
|
112
119
|
parameters.processing_options.should == {:scale => '0.5'}
|
113
120
|
parameters.format.should == :png
|
114
121
|
parameters.encoding.should == {:bit_rate => 24}
|
115
122
|
end
|
116
123
|
it "should return the correct parameter if set" do
|
117
|
-
parameters = @parameters_class.
|
124
|
+
parameters = @parameters_class.new_with_defaults(
|
118
125
|
:processing_method => :yo,
|
119
126
|
:processing_options => {:a => 'b'},
|
120
127
|
:format => :txt,
|
@@ -125,35 +132,13 @@ describe Dragonfly::Parameters do
|
|
125
132
|
parameters.format.should == :txt
|
126
133
|
parameters.encoding.should == {:ah => :arg}
|
127
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
|
128
138
|
end
|
129
139
|
|
130
140
|
end
|
131
141
|
|
132
|
-
describe "validate!" do
|
133
|
-
before(:each) do
|
134
|
-
@parameters = Dragonfly::Parameters.new(standard_attributes)
|
135
|
-
end
|
136
|
-
it "should not raise an error when parameters are ok" do
|
137
|
-
@parameters.validate!
|
138
|
-
end
|
139
|
-
it "should raise an error when the uid is not set" do
|
140
|
-
@parameters.uid = nil
|
141
|
-
lambda{
|
142
|
-
@parameters.validate!
|
143
|
-
}.should raise_error(Dragonfly::Parameters::InvalidParameters)
|
144
|
-
end
|
145
|
-
it "should raise an error when the format is not set" do
|
146
|
-
@parameters.format = nil
|
147
|
-
lambda{
|
148
|
-
@parameters.validate!
|
149
|
-
}.should raise_error(Dragonfly::Parameters::InvalidParameters)
|
150
|
-
end
|
151
|
-
it "should not raise an error when other parameters aren't set" do
|
152
|
-
parameters = Dragonfly::Parameters.new(:uid => 'asdf', :format => :jpg)
|
153
|
-
parameters.validate!
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
142
|
describe "shortcuts" do
|
158
143
|
|
159
144
|
before(:each) do
|
@@ -225,11 +210,15 @@ describe Dragonfly::Parameters do
|
|
225
210
|
end
|
226
211
|
|
227
212
|
describe ".from_shortcut" do
|
228
|
-
|
229
|
-
@parameters_class.add_shortcut(/^hello
|
230
|
-
{:processing_method => processing_method
|
213
|
+
before(:each) do
|
214
|
+
@parameters_class.add_shortcut(/^hello.*$/) do |processing_method, matches|
|
215
|
+
{:processing_method => processing_method}
|
231
216
|
end
|
232
|
-
@parameters_class.
|
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))
|
233
222
|
end
|
234
223
|
end
|
235
224
|
|
@@ -239,6 +228,7 @@ describe Dragonfly::Parameters do
|
|
239
228
|
|
240
229
|
before(:each) do
|
241
230
|
@parameters_class = Class.new(Dragonfly::Parameters)
|
231
|
+
@parameters_class.default_format = :tif
|
242
232
|
end
|
243
233
|
|
244
234
|
it "should be the same as 'new' if empty args" do
|