dragonfly 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/History.md +16 -0
- data/README.md +5 -1
- data/dev/test.ru +1 -1
- data/dragonfly.gemspec +2 -1
- data/lib/dragonfly/content.rb +17 -18
- data/lib/dragonfly/image_magick/commands.rb +35 -0
- data/lib/dragonfly/image_magick/generators/plain.rb +13 -7
- data/lib/dragonfly/image_magick/generators/plasma.rb +10 -6
- data/lib/dragonfly/image_magick/generators/text.rb +67 -58
- data/lib/dragonfly/image_magick/plugin.rb +26 -25
- data/lib/dragonfly/image_magick/processors/encode.rb +16 -5
- data/lib/dragonfly/image_magick/processors/thumb.rb +37 -31
- data/lib/dragonfly/middleware.rb +2 -1
- data/lib/dragonfly/param_validators.rb +37 -0
- data/lib/dragonfly/response.rb +11 -11
- data/lib/dragonfly/routed_endpoint.rb +1 -1
- data/lib/dragonfly/server.rb +7 -7
- data/lib/dragonfly/version.rb +1 -1
- data/spec/dragonfly/app_spec.rb +1 -1
- data/spec/dragonfly/configurable_spec.rb +4 -4
- data/spec/dragonfly/content_spec.rb +1 -1
- data/spec/dragonfly/file_data_store_spec.rb +2 -2
- data/spec/dragonfly/image_magick/commands_spec.rb +98 -0
- data/spec/dragonfly/image_magick/generators/plain_spec.rb +39 -13
- data/spec/dragonfly/image_magick/generators/plasma_spec.rb +28 -9
- data/spec/dragonfly/image_magick/generators/text_spec.rb +51 -20
- data/spec/dragonfly/image_magick/plugin_spec.rb +45 -28
- data/spec/dragonfly/image_magick/processors/encode_spec.rb +30 -0
- data/spec/dragonfly/image_magick/processors/thumb_spec.rb +46 -45
- data/spec/dragonfly/job/fetch_url_spec.rb +1 -1
- data/spec/dragonfly/job_endpoint_spec.rb +26 -26
- data/spec/dragonfly/middleware_spec.rb +15 -6
- data/spec/dragonfly/model/active_record_spec.rb +2 -2
- data/spec/dragonfly/model/model_spec.rb +1 -1
- data/spec/dragonfly/param_validators_spec.rb +89 -0
- data/spec/dragonfly/server_spec.rb +4 -4
- data/spec/dragonfly/temp_object_spec.rb +5 -5
- data/spec/functional/shell_commands_spec.rb +6 -9
- data/spec/functional/to_response_spec.rb +2 -2
- data/spec/functional/urls_spec.rb +1 -1
- data/spec/spec_helper.rb +18 -14
- data/spec/support/image_matchers.rb +1 -1
- metadata +27 -12
- data/lib/dragonfly/image_magick/generators/convert.rb +0 -19
- data/lib/dragonfly/image_magick/processors/convert.rb +0 -33
- data/spec/dragonfly/image_magick/generators/convert_spec.rb +0 -19
- data/spec/dragonfly/image_magick/processors/convert_spec.rb +0 -88
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Dragonfly::ImageMagick::Generators::Text do
|
4
4
|
let (:generator) { Dragonfly::ImageMagick::Generators::Text.new }
|
@@ -7,62 +7,62 @@ describe Dragonfly::ImageMagick::Generators::Text do
|
|
7
7
|
|
8
8
|
describe "creating a text image" do
|
9
9
|
before(:each) do
|
10
|
-
generator.call(image, "mmm",
|
10
|
+
generator.call(image, "mmm", "font_size" => 12)
|
11
11
|
end
|
12
|
-
it {image.should have_width(20..40)} # approximate
|
13
|
-
it {image.should have_height(10..20)}
|
14
|
-
it {image.should have_format(
|
15
|
-
it {image.meta.should == {
|
12
|
+
it { image.should have_width(20..40) } # approximate
|
13
|
+
it { image.should have_height(10..20) }
|
14
|
+
it { image.should have_format("png") }
|
15
|
+
it { image.meta.should == { "format" => "png", "name" => "text.png" } }
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "specifying the format" do
|
19
19
|
before(:each) do
|
20
|
-
generator.call(image, "mmm",
|
20
|
+
generator.call(image, "mmm", "format" => "gif")
|
21
21
|
end
|
22
|
-
it {image.should have_format(
|
23
|
-
it {image.meta.should == {
|
22
|
+
it { image.should have_format("gif") }
|
23
|
+
it { image.meta.should == { "format" => "gif", "name" => "text.gif" } }
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "padding" do
|
27
27
|
before(:each) do
|
28
28
|
image_without_padding = image.clone
|
29
|
-
generator.call(image_without_padding, "mmm",
|
29
|
+
generator.call(image_without_padding, "mmm", "font_size" => 12)
|
30
30
|
@width = image_properties(image_without_padding)[:width].to_i
|
31
31
|
@height = image_properties(image_without_padding)[:height].to_i
|
32
32
|
end
|
33
33
|
it "1 number shortcut" do
|
34
|
-
generator.call(image, "mmm",
|
34
|
+
generator.call(image, "mmm", "padding" => "10")
|
35
35
|
image.should have_width(@width + 20)
|
36
36
|
image.should have_height(@height + 20)
|
37
37
|
end
|
38
38
|
it "2 numbers shortcut" do
|
39
|
-
generator.call(image, "mmm",
|
39
|
+
generator.call(image, "mmm", "padding" => "10 5")
|
40
40
|
image.should have_width(@width + 10)
|
41
41
|
image.should have_height(@height + 20)
|
42
42
|
end
|
43
43
|
it "3 numbers shortcut" do
|
44
|
-
generator.call(image, "mmm",
|
44
|
+
generator.call(image, "mmm", "padding" => "10 5 8")
|
45
45
|
image.should have_width(@width + 10)
|
46
46
|
image.should have_height(@height + 18)
|
47
47
|
end
|
48
48
|
it "4 numbers shortcut" do
|
49
|
-
generator.call(image, "mmm",
|
49
|
+
generator.call(image, "mmm", "padding" => "1 2 3 4")
|
50
50
|
image.should have_width(@width + 6)
|
51
51
|
image.should have_height(@height + 4)
|
52
52
|
end
|
53
53
|
it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
|
54
|
-
generator.call(image, "mmm",
|
54
|
+
generator.call(image, "mmm", "padding" => "10", "padding-left" => 9)
|
55
55
|
image.should have_width(@width + 19)
|
56
56
|
image.should have_height(@height + 20)
|
57
57
|
end
|
58
58
|
it "should ignore 'px' suffixes" do
|
59
|
-
generator.call(image, "mmm",
|
59
|
+
generator.call(image, "mmm", "padding" => "1px 2px 3px 4px")
|
60
60
|
image.should have_width(@width + 6)
|
61
61
|
image.should have_height(@height + 4)
|
62
62
|
end
|
63
63
|
it "bad padding string" do
|
64
|
-
lambda{
|
65
|
-
generator.call(image, "mmm",
|
64
|
+
lambda {
|
65
|
+
generator.call(image, "mmm", "padding" => "1 2 3 4 5")
|
66
66
|
}.should raise_error(ArgumentError)
|
67
67
|
end
|
68
68
|
end
|
@@ -70,8 +70,39 @@ describe Dragonfly::ImageMagick::Generators::Text do
|
|
70
70
|
describe "urls" do
|
71
71
|
it "updates the url" do
|
72
72
|
url_attributes = Dragonfly::UrlAttributes.new
|
73
|
-
generator.update_url(url_attributes, "mmm",
|
74
|
-
url_attributes.name.should ==
|
73
|
+
generator.update_url(url_attributes, "mmm", "format" => "gif")
|
74
|
+
url_attributes.name.should == "text.gif"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "param validations" do
|
79
|
+
{
|
80
|
+
"font" => "Times New Roman -write bad.png",
|
81
|
+
"font_family" => "Times New Roman -write bad.png",
|
82
|
+
"color" => "rgb(255, 34, 55) -write bad.png",
|
83
|
+
"background_color" => "rgb(255, 52, 55) -write bad.png",
|
84
|
+
"stroke_color" => "rgb(255, 52, 55) -write bad.png",
|
85
|
+
"format" => "png -write bad.png",
|
86
|
+
}.each do |opt, value|
|
87
|
+
it "validates bad opts like #{opt} = '#{value}'" do
|
88
|
+
expect {
|
89
|
+
generator.call(image, "some text", opt => value)
|
90
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
["rgb(33,33,33)", "rgba(33,33,33,0.5)", "rgb(33.5,33.5,33.5)", "#fff", "#efefef", "blue"].each do |colour|
|
95
|
+
it "allows #{colour.inspect} as a colour specification" do
|
96
|
+
generator.call(image, "mmm", "color" => colour)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
["rgb(33, 33, 33)", "something else", "blue:", "f#ff"].each do |colour|
|
101
|
+
it "disallows #{colour.inspect} as a colour specification" do
|
102
|
+
expect {
|
103
|
+
generator.call(image, "mmm", "color" => colour)
|
104
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
105
|
+
end
|
75
106
|
end
|
76
107
|
end
|
77
108
|
end
|
@@ -1,25 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "a configured imagemagick app" do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:image){ app.fetch_file(SAMPLES_DIR.join('beach.png')) }
|
4
|
+
let(:app) { test_app.configure_with(:imagemagick) }
|
5
|
+
let(:image) { app.fetch_file(SAMPLES_DIR.join("beach.png")) }
|
7
6
|
|
8
7
|
describe "env variables" do
|
9
|
-
let(:app){ test_app }
|
8
|
+
let(:app) { test_app }
|
10
9
|
|
11
10
|
it "allows setting the convert command" do
|
12
11
|
app.configure do
|
13
|
-
plugin :imagemagick, :convert_command =>
|
12
|
+
plugin :imagemagick, :convert_command => "/bin/convert"
|
14
13
|
end
|
15
|
-
app.env[:convert_command].should ==
|
14
|
+
app.env[:convert_command].should == "/bin/convert"
|
16
15
|
end
|
17
16
|
|
18
17
|
it "allows setting the identify command" do
|
19
18
|
app.configure do
|
20
|
-
plugin :imagemagick, :identify_command =>
|
19
|
+
plugin :imagemagick, :identify_command => "/bin/identify"
|
21
20
|
end
|
22
|
-
app.env[:identify_command].should ==
|
21
|
+
app.env[:identify_command].should == "/bin/identify"
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
@@ -33,7 +32,7 @@ describe "a configured imagemagick app" do
|
|
33
32
|
end
|
34
33
|
|
35
34
|
it "should return the aspect ratio" do
|
36
|
-
image.aspect_ratio.should == (280.0/355.0)
|
35
|
+
image.aspect_ratio.should == (280.0 / 355.0)
|
37
36
|
end
|
38
37
|
|
39
38
|
it "should say if it's portrait" do
|
@@ -60,39 +59,39 @@ describe "a configured imagemagick app" do
|
|
60
59
|
end
|
61
60
|
|
62
61
|
it "should return false for pdfs" do
|
63
|
-
image.encode(
|
64
|
-
end unless ENV[
|
62
|
+
image.encode("pdf").image?.should be_falsey
|
63
|
+
end unless ENV["SKIP_FLAKY_TESTS"]
|
65
64
|
end
|
66
65
|
|
67
66
|
describe "processors that change the url" do
|
68
67
|
before do
|
69
|
-
app.configure{ url_format
|
68
|
+
app.configure { url_format "/:name" }
|
70
69
|
end
|
71
70
|
|
72
|
-
describe "
|
71
|
+
describe "thumb" do
|
73
72
|
it "sanity check with format" do
|
74
|
-
thumb = image.
|
73
|
+
thumb = image.thumb("1x1!", "format" => "jpg")
|
75
74
|
thumb.url.should =~ /^\/beach\.jpg\?.*job=\w+/
|
76
75
|
thumb.width.should == 1
|
77
|
-
thumb.format.should ==
|
78
|
-
thumb.meta[
|
76
|
+
thumb.format.should == "jpeg"
|
77
|
+
thumb.meta["format"].should == "jpg"
|
79
78
|
end
|
80
79
|
|
81
80
|
it "sanity check without format" do
|
82
|
-
thumb = image.
|
81
|
+
thumb = image.thumb("1x1!")
|
83
82
|
thumb.url.should =~ /^\/beach\.png\?.*job=\w+/
|
84
83
|
thumb.width.should == 1
|
85
|
-
thumb.format.should ==
|
86
|
-
thumb.meta[
|
84
|
+
thumb.format.should == "png"
|
85
|
+
thumb.meta["format"].should be_nil
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
describe "encode" do
|
91
90
|
it "sanity check" do
|
92
|
-
thumb = image.encode(
|
91
|
+
thumb = image.encode("jpg")
|
93
92
|
thumb.url.should =~ /^\/beach\.jpg\?.*job=\w+/
|
94
|
-
thumb.format.should ==
|
95
|
-
thumb.meta[
|
93
|
+
thumb.format.should == "jpeg"
|
94
|
+
thumb.meta["format"].should == "jpg"
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
@@ -100,13 +99,13 @@ describe "a configured imagemagick app" do
|
|
100
99
|
describe "other processors" do
|
101
100
|
describe "encode" do
|
102
101
|
it "should encode the image to the correct format" do
|
103
|
-
image.encode!(
|
104
|
-
image.format.should ==
|
102
|
+
image.encode!("gif")
|
103
|
+
image.format.should == "gif"
|
105
104
|
end
|
106
105
|
|
107
106
|
it "should allow for extra args" do
|
108
|
-
image.encode!(
|
109
|
-
image.format.should ==
|
107
|
+
image.encode!("jpg", "-quality 1")
|
108
|
+
image.format.should == "jpeg"
|
110
109
|
image.size.should < 2000
|
111
110
|
end
|
112
111
|
end
|
@@ -117,8 +116,13 @@ describe "a configured imagemagick app" do
|
|
117
116
|
image.width.should == 355
|
118
117
|
image.height.should == 280
|
119
118
|
end
|
120
|
-
end
|
121
119
|
|
120
|
+
it "disallows bad parameters" do
|
121
|
+
expect {
|
122
|
+
image.rotate!("90 -write bad.png").apply
|
123
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
124
|
+
end
|
125
|
+
end
|
122
126
|
end
|
123
127
|
|
124
128
|
describe "identify" do
|
@@ -128,4 +132,17 @@ describe "a configured imagemagick app" do
|
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
135
|
+
describe "deprecated convert commands" do
|
136
|
+
it "raises a deprecated message if using the convert processor" do
|
137
|
+
expect {
|
138
|
+
image.convert!("into something").apply
|
139
|
+
}.to raise_error(/deprecated/i)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "raises a deprecated message if using the convert generator" do
|
143
|
+
expect {
|
144
|
+
image.generate!(:convert, "into something").apply
|
145
|
+
}.to raise_error(/deprecated/i)
|
146
|
+
end
|
147
|
+
end
|
131
148
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Dragonfly::ImageMagick::Processors::Encode do
|
4
|
+
let (:app) { test_imagemagick_app }
|
5
|
+
let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join("beach.png")) } # 280x355
|
6
|
+
let (:processor) { Dragonfly::ImageMagick::Processors::Encode.new }
|
7
|
+
|
8
|
+
it "encodes to a different format" do
|
9
|
+
processor.call(image, "jpeg")
|
10
|
+
image.should have_format("jpeg")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "param validations" do
|
14
|
+
it "validates the format param" do
|
15
|
+
expect {
|
16
|
+
processor.call(image, "jpeg -write bad.png")
|
17
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "allows good args" do
|
21
|
+
processor.call(image, "jpeg", "-quality 10")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "disallows bad args" do
|
25
|
+
expect {
|
26
|
+
processor.call(image, "jpeg", "-write bad.png")
|
27
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,88 +1,80 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "ostruct"
|
3
3
|
|
4
4
|
describe Dragonfly::ImageMagick::Processors::Thumb do
|
5
|
-
|
6
5
|
let (:app) { test_imagemagick_app }
|
7
|
-
let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join(
|
6
|
+
let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join("beach.png")) } # 280x355
|
8
7
|
let (:processor) { Dragonfly::ImageMagick::Processors::Thumb.new }
|
9
8
|
|
10
9
|
it "raises an error if an unrecognized string is given" do
|
11
|
-
expect{
|
12
|
-
processor.call(image,
|
10
|
+
expect {
|
11
|
+
processor.call(image, "30x40#ne!")
|
13
12
|
}.to raise_error(ArgumentError)
|
14
13
|
end
|
15
14
|
|
16
15
|
describe "resizing" do
|
17
|
-
|
18
16
|
it "works with xNN" do
|
19
|
-
processor.call(image,
|
17
|
+
processor.call(image, "x30")
|
20
18
|
image.should have_width(24)
|
21
19
|
image.should have_height(30)
|
22
20
|
end
|
23
21
|
|
24
22
|
it "works with NNx" do
|
25
|
-
processor.call(image,
|
23
|
+
processor.call(image, "30x")
|
26
24
|
image.should have_width(30)
|
27
25
|
image.should have_height(38)
|
28
26
|
end
|
29
27
|
|
30
28
|
it "works with NNxNN" do
|
31
|
-
processor.call(image,
|
29
|
+
processor.call(image, "30x30")
|
32
30
|
image.should have_width(24)
|
33
31
|
image.should have_height(30)
|
34
32
|
end
|
35
33
|
|
36
34
|
it "works with NNxNN!" do
|
37
|
-
processor.call(image,
|
35
|
+
processor.call(image, "30x30!")
|
38
36
|
image.should have_width(30)
|
39
37
|
image.should have_height(30)
|
40
38
|
end
|
41
39
|
|
42
40
|
it "works with NNxNN%" do
|
43
|
-
processor.call(image,
|
41
|
+
processor.call(image, "25x50%")
|
44
42
|
image.should have_width(70)
|
45
43
|
image.should have_height(178)
|
46
44
|
end
|
47
45
|
|
48
46
|
describe "NNxNN>" do
|
49
|
-
|
50
47
|
it "doesn't resize if the image is smaller than specified" do
|
51
|
-
processor.call(image,
|
48
|
+
processor.call(image, "1000x1000>")
|
52
49
|
image.should have_width(280)
|
53
50
|
image.should have_height(355)
|
54
51
|
end
|
55
52
|
|
56
53
|
it "resizes if the image is larger than specified" do
|
57
|
-
processor.call(image,
|
54
|
+
processor.call(image, "30x30>")
|
58
55
|
image.should have_width(24)
|
59
56
|
image.should have_height(30)
|
60
57
|
end
|
61
|
-
|
62
58
|
end
|
63
59
|
|
64
60
|
describe "NNxNN<" do
|
65
|
-
|
66
61
|
it "doesn't resize if the image is larger than specified" do
|
67
|
-
processor.call(image,
|
62
|
+
processor.call(image, "10x10<")
|
68
63
|
image.should have_width(280)
|
69
64
|
image.should have_height(355)
|
70
65
|
end
|
71
66
|
|
72
67
|
it "resizes if the image is smaller than specified" do
|
73
|
-
processor.call(image,
|
68
|
+
processor.call(image, "400x400<")
|
74
69
|
image.should have_width(315)
|
75
70
|
image.should have_height(400)
|
76
71
|
end
|
77
|
-
|
78
72
|
end
|
79
|
-
|
80
73
|
end
|
81
74
|
|
82
75
|
describe "cropping" do # Difficult to test here other than dimensions
|
83
|
-
|
84
76
|
it "crops" do
|
85
|
-
processor.call(image,
|
77
|
+
processor.call(image, "10x20+30+30")
|
86
78
|
image.should have_width(10)
|
87
79
|
image.should have_height(20)
|
88
80
|
end
|
@@ -90,11 +82,11 @@ describe Dragonfly::ImageMagick::Processors::Thumb do
|
|
90
82
|
it "crops with gravity" do
|
91
83
|
image2 = image.clone
|
92
84
|
|
93
|
-
processor.call(image,
|
85
|
+
processor.call(image, "10x8nw")
|
94
86
|
image.should have_width(10)
|
95
87
|
image.should have_height(8)
|
96
88
|
|
97
|
-
processor.call(image2,
|
89
|
+
processor.call(image2, "10x8se")
|
98
90
|
image2.should have_width(10)
|
99
91
|
image2.should have_height(8)
|
100
92
|
|
@@ -103,77 +95,86 @@ describe Dragonfly::ImageMagick::Processors::Thumb do
|
|
103
95
|
|
104
96
|
it "raises if given both gravity and offset" do
|
105
97
|
expect {
|
106
|
-
processor.call(image,
|
98
|
+
processor.call(image, "100x100+10+10se")
|
107
99
|
}.to raise_error(ArgumentError)
|
108
100
|
end
|
109
101
|
|
110
102
|
it "works when the crop area is outside the image" do
|
111
|
-
processor.call(image,
|
103
|
+
processor.call(image, "100x100+250+300")
|
112
104
|
image.should have_width(30)
|
113
105
|
image.should have_height(55)
|
114
106
|
end
|
115
107
|
|
116
108
|
it "crops twice in a row correctly" do
|
117
|
-
processor.call(image,
|
118
|
-
processor.call(image,
|
109
|
+
processor.call(image, "100x100+10+10")
|
110
|
+
processor.call(image, "50x50+0+0")
|
119
111
|
image.should have_width(50)
|
120
112
|
image.should have_height(50)
|
121
113
|
end
|
122
|
-
|
123
114
|
end
|
124
115
|
|
125
116
|
describe "resize_and_crop" do
|
126
|
-
|
127
117
|
it "crops to the correct dimensions" do
|
128
|
-
processor.call(image,
|
118
|
+
processor.call(image, "100x100#")
|
129
119
|
image.should have_width(100)
|
130
120
|
image.should have_height(100)
|
131
121
|
end
|
132
122
|
|
133
123
|
it "resizes before cropping" do
|
134
124
|
image2 = image.clone
|
135
|
-
processor.call(image,
|
136
|
-
processor.call(image2,
|
125
|
+
processor.call(image, "100x100#")
|
126
|
+
processor.call(image2, "100x100c")
|
137
127
|
image2.should_not equal_image(image)
|
138
128
|
end
|
139
129
|
|
140
130
|
it "works with gravity" do
|
141
131
|
image2 = image.clone
|
142
|
-
processor.call(image,
|
143
|
-
processor.call(image,
|
132
|
+
processor.call(image, "10x10#nw")
|
133
|
+
processor.call(image, "10x10#se")
|
144
134
|
image2.should_not equal_image(image)
|
145
135
|
end
|
146
|
-
|
147
136
|
end
|
148
137
|
|
149
138
|
describe "format" do
|
150
139
|
let (:url_attributes) { OpenStruct.new }
|
151
140
|
|
152
141
|
it "changes the format if passed in" do
|
153
|
-
processor.call(image,
|
154
|
-
image.should have_format(
|
142
|
+
processor.call(image, "2x2", "format" => "jpeg")
|
143
|
+
image.should have_format("jpeg")
|
155
144
|
end
|
156
145
|
|
157
146
|
it "doesn't change the format if not passed in" do
|
158
|
-
processor.call(image,
|
159
|
-
image.should have_format(
|
147
|
+
processor.call(image, "2x2")
|
148
|
+
image.should have_format("png")
|
160
149
|
end
|
161
150
|
|
162
151
|
it "updates the url ext if passed in" do
|
163
|
-
processor.update_url(url_attributes,
|
164
|
-
url_attributes.ext.should ==
|
152
|
+
processor.update_url(url_attributes, "2x2", "format" => "png")
|
153
|
+
url_attributes.ext.should == "png"
|
165
154
|
end
|
166
155
|
|
167
156
|
it "doesn't update the url ext if not passed in" do
|
168
|
-
processor.update_url(url_attributes,
|
157
|
+
processor.update_url(url_attributes, "2x2")
|
169
158
|
url_attributes.ext.should be_nil
|
170
159
|
end
|
171
160
|
end
|
172
161
|
|
173
162
|
describe "args_for_geometry" do
|
174
163
|
it "returns the convert arguments used for a given geometry" do
|
175
|
-
expect(processor.args_for_geometry(
|
164
|
+
expect(processor.args_for_geometry("30x40")).to eq("-resize 30x40")
|
176
165
|
end
|
177
166
|
end
|
178
167
|
|
168
|
+
describe "param validations" do
|
169
|
+
{
|
170
|
+
"format" => "png -write bad.png",
|
171
|
+
"frame" => "0] -write bad.png [",
|
172
|
+
}.each do |opt, value|
|
173
|
+
it "validates bad opts like #{opt} = '#{value}'" do
|
174
|
+
expect {
|
175
|
+
processor.call(image, "30x30", opt => value)
|
176
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
179
180
|
end
|
@@ -21,7 +21,7 @@ describe Dragonfly::Job::FetchUrl do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should set the mime_type when returned by the request" do
|
24
|
-
stub_request(:get, %r{http://thing\.com.*}).to_return(:body => '<ok />', :headers => {'
|
24
|
+
stub_request(:get, %r{http://thing\.com.*}).to_return(:body => '<ok />', :headers => {'content-type' => 'text/html'})
|
25
25
|
expect(job.fetch_url('http://place.com').mime_type).to eq('application/octet-stream')
|
26
26
|
expect(job.fetch_url('http://thing.com').mime_type).to eq('text/html')
|
27
27
|
end
|
@@ -50,22 +50,22 @@ describe Dragonfly::JobEndpoint do
|
|
50
50
|
it "should return a correct response to a successful GET request" do
|
51
51
|
response = make_request(@job)
|
52
52
|
response.status.should == 200
|
53
|
-
response['
|
54
|
-
response['
|
55
|
-
response['
|
56
|
-
response['
|
57
|
-
response['
|
53
|
+
response['etag'].should =~ /^"\w+"$/
|
54
|
+
response['cache-control'].should == "public, max-age=31536000"
|
55
|
+
response['content-type'].should == 'text/plain'
|
56
|
+
response['content-length'].should == '6'
|
57
|
+
response['content-disposition'].should == 'filename="gung.txt"'
|
58
58
|
response.body.should == 'GUNGLE'
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return the correct headers and no content to a successful HEAD request" do
|
62
62
|
response = make_request(@job, :method => :head)
|
63
63
|
response.status.should == 200
|
64
|
-
response['
|
65
|
-
response['
|
66
|
-
response['
|
67
|
-
response['
|
68
|
-
response['
|
64
|
+
response['etag'].should =~ /^"\w+"$/
|
65
|
+
response['cache-control'].should == "public, max-age=31536000"
|
66
|
+
response['content-type'].should == 'text/plain'
|
67
|
+
response['content-length'].should == '6'
|
68
|
+
response['content-disposition'].should == 'filename="gung.txt"'
|
69
69
|
response.body.should == ''
|
70
70
|
end
|
71
71
|
|
@@ -74,8 +74,8 @@ describe Dragonfly::JobEndpoint do
|
|
74
74
|
it "should return a 405 error for a #{method} request" do
|
75
75
|
response = make_request(@job, :method => method)
|
76
76
|
response.status.should == 405
|
77
|
-
response['
|
78
|
-
response['
|
77
|
+
response['allow'].should == "GET, HEAD"
|
78
|
+
response['content-type'].should == 'text/plain'
|
79
79
|
response.body.should == "method not allowed"
|
80
80
|
end
|
81
81
|
|
@@ -102,12 +102,12 @@ describe Dragonfly::JobEndpoint do
|
|
102
102
|
|
103
103
|
it "doesn't encode utf8 characters" do
|
104
104
|
response = make_request(@job)
|
105
|
-
response['
|
105
|
+
response['content-disposition'].should == 'filename="güng.txt"'
|
106
106
|
end
|
107
107
|
|
108
108
|
it "does encode them if the request is from IE" do
|
109
109
|
response = make_request(@job, 'HTTP_USER_AGENT' => "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; el-GR)")
|
110
|
-
response['
|
110
|
+
response['content-disposition'].should == 'filename="g%C3%BCng.txt"'
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -121,7 +121,7 @@ describe Dragonfly::JobEndpoint do
|
|
121
121
|
describe "ETag" do
|
122
122
|
it "should return an ETag" do
|
123
123
|
response = make_request(@job)
|
124
|
-
response.headers['
|
124
|
+
response.headers['etag'].should =~ /^"\w+"$/
|
125
125
|
end
|
126
126
|
|
127
127
|
[
|
@@ -134,8 +134,8 @@ describe Dragonfly::JobEndpoint do
|
|
134
134
|
@job.should_receive(:signature).at_least(:once).and_return('dingle')
|
135
135
|
response = make_request(@job, 'HTTP_IF_NONE_MATCH' => header)
|
136
136
|
response.status.should == 304
|
137
|
-
response['
|
138
|
-
response['
|
137
|
+
response['etag'].should == '"dingle"'
|
138
|
+
response['cache-control'].should == "public, max-age=31536000"
|
139
139
|
response.body.should be_empty
|
140
140
|
end
|
141
141
|
end
|
@@ -151,25 +151,25 @@ describe Dragonfly::JobEndpoint do
|
|
151
151
|
@app.configure{ response_header 'This-is', 'brill' }
|
152
152
|
end
|
153
153
|
it "should allow specifying custom headers" do
|
154
|
-
make_request(@job).headers['
|
154
|
+
make_request(@job).headers['this-is'].should == 'brill'
|
155
155
|
end
|
156
156
|
it "should not interfere with other headers" do
|
157
|
-
make_request(@job).headers['
|
157
|
+
make_request(@job).headers['content-length'].should == '6'
|
158
158
|
end
|
159
159
|
it "should allow overridding other headers" do
|
160
|
-
@app.response_headers['
|
161
|
-
make_request(@job).headers['
|
160
|
+
@app.response_headers['cache-control'] = 'try me'
|
161
|
+
make_request(@job).headers['cache-control'].should == 'try me'
|
162
162
|
end
|
163
163
|
it "should allow giving a proc" do
|
164
|
-
@app.response_headers['
|
165
|
-
[job.basename.reverse.upcase, request['a'], headers['
|
164
|
+
@app.response_headers['cache-control'] = proc{|job, request, headers|
|
165
|
+
[job.basename.reverse.upcase, request.params['a'], headers['cache-control'].chars.first].join(',')
|
166
166
|
}
|
167
167
|
response = make_request(@job, 'QUERY_STRING' => 'a=egg')
|
168
|
-
response['
|
168
|
+
response['cache-control'].should == 'GNUG,egg,p'
|
169
169
|
end
|
170
170
|
it "should allow removing by setting to nil" do
|
171
|
-
@app.response_headers['
|
172
|
-
make_request(@job).headers.should_not have_key('
|
171
|
+
@app.response_headers['cache-control'] = nil
|
172
|
+
make_request(@job).headers.should_not have_key('cache-control')
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|