dragonfly 1.2.0 → 1.4.0
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 +5 -5
- data/.travis.yml +14 -6
- data/History.md +331 -319
- data/README.md +1 -1
- data/dev/rails_template.rb +35 -33
- data/dragonfly.gemspec +10 -16
- 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/job/fetch_url.rb +1 -1
- data/lib/dragonfly/model/class_methods.rb +6 -1
- data/lib/dragonfly/param_validators.rb +37 -0
- data/lib/dragonfly/response.rb +2 -2
- data/lib/dragonfly/utils.rb +1 -1
- data/lib/dragonfly/version.rb +1 -1
- data/lib/dragonfly.rb +3 -1
- data/spec/dragonfly/cookie_monster_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/model/active_record_spec.rb +62 -0
- data/spec/dragonfly/param_validators_spec.rb +89 -0
- data/spec/dragonfly_spec.rb +37 -13
- data/spec/functional/shell_commands_spec.rb +6 -9
- data/spec/spec_helper.rb +12 -14
- metadata +44 -13
- 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
@@ -0,0 +1,89 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "dragonfly/param_validators"
|
3
|
+
|
4
|
+
describe Dragonfly::ParamValidators do
|
5
|
+
include Dragonfly::ParamValidators
|
6
|
+
|
7
|
+
describe "validate!" do
|
8
|
+
it "does nothing if the parameter meets the condition" do
|
9
|
+
validate!("thing") { |t| t === "thing" }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "raises if the parameter doesn't meet the condition" do
|
13
|
+
expect {
|
14
|
+
validate!("thing") { |t| t === "ting" }
|
15
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does nothing if the parameter is nil" do
|
19
|
+
validate!(nil) { |t| t === "thing" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "validate_all!" do
|
24
|
+
it "allows passing an array of parameters to validate" do
|
25
|
+
validate_all!(["a", "b"]) { |p| /\w/ === p }
|
26
|
+
expect {
|
27
|
+
validate_all!(["a", " "]) { |p| /\w/ === p }
|
28
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "validate_all_keys!" do
|
33
|
+
it "allows passing an array of parameters to validate" do
|
34
|
+
obj = { "a" => "A", "b" => "B" }
|
35
|
+
validate_all_keys!(obj, ["a", "b"]) { |p| /\w/ === p }
|
36
|
+
expect {
|
37
|
+
validate_all_keys!(obj, ["a", "b"]) { |p| /[a-z]/ === p }
|
38
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "is_number" do
|
43
|
+
[3, 3.14, "3", "3.2"].each do |val|
|
44
|
+
it "validates #{val.inspect}" do
|
45
|
+
validate!(val, &is_number)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
["", "3 2", "hello4", {}, []].each do |val|
|
50
|
+
it "validates #{val.inspect}" do
|
51
|
+
expect {
|
52
|
+
validate!(val, &is_number)
|
53
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "is_word" do
|
59
|
+
["hello", "helLo", "HELLO"].each do |val|
|
60
|
+
it "validates #{val.inspect}" do
|
61
|
+
validate!(val, &is_word)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
["", "hel%$lo", "hel lo", "hel-lo", {}, []].each do |val|
|
66
|
+
it "validates #{val.inspect}" do
|
67
|
+
expect {
|
68
|
+
validate!(val, &is_word)
|
69
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "is_words" do
|
75
|
+
["hello there", "Hi", " What is Up "].each do |val|
|
76
|
+
it "validates #{val.inspect}" do
|
77
|
+
validate!(val, &is_words)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
["", "hel%$lo", "What's up", "hel-lo", {}, []].each do |val|
|
82
|
+
it "validates #{val.inspect}" do
|
83
|
+
expect {
|
84
|
+
validate!(val, &is_words)
|
85
|
+
}.to raise_error(Dragonfly::ParamValidators::InvalidParameter)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/spec/dragonfly_spec.rb
CHANGED
@@ -12,23 +12,47 @@ describe Dragonfly do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "logging" do
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
context "logger exists" do
|
16
|
+
before do
|
17
|
+
Dragonfly.logger = Logger.new(StringIO.new)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
it "debugs" do
|
21
|
+
Dragonfly.logger.should_receive(:debug).with(/something/)
|
22
|
+
Dragonfly.debug("something")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "warns" do
|
26
|
+
Dragonfly.logger.should_receive(:warn).with(/something/)
|
27
|
+
Dragonfly.warn("something")
|
28
|
+
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
it "shows info" do
|
31
|
+
Dragonfly.logger.should_receive(:info).with(/something/)
|
32
|
+
Dragonfly.info("something")
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
context "logger is nil" do
|
37
|
+
before do
|
38
|
+
allow_message_expectations_on_nil
|
39
|
+
Dragonfly.logger = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not call debug" do
|
43
|
+
Dragonfly.logger.should_not_receive(:debug)
|
44
|
+
Dragonfly.debug("something")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not warn" do
|
48
|
+
Dragonfly.logger.should_not_receive(:warn)
|
49
|
+
Dragonfly.warn("something")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not show info" do
|
53
|
+
Dragonfly.logger.should_not_receive(:info)
|
54
|
+
Dragonfly.info("something")
|
55
|
+
end
|
32
56
|
end
|
33
57
|
end
|
34
58
|
|
@@ -1,33 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "using the shell" do
|
4
|
-
|
5
4
|
let (:app) { test_app }
|
6
5
|
|
7
6
|
describe "shell injection" do
|
8
7
|
it "should not allow it!" do
|
9
8
|
app.configure_with(:imagemagick)
|
10
9
|
begin
|
11
|
-
app.generate(:plain, 10, 10,
|
10
|
+
app.generate(:plain, 10, 10, "white; touch tmp/stuff").apply
|
12
11
|
rescue Dragonfly::Shell::CommandFailed
|
13
12
|
end
|
14
|
-
File.exist?(
|
13
|
+
File.exist?("tmp/stuff").should be_falsey
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
describe "env variables with imagemagick" do
|
19
18
|
it "allows configuring the convert path" do
|
20
|
-
app.configure_with(:imagemagick, :convert_command =>
|
19
|
+
app.configure_with(:imagemagick, :convert_command => "/bin/convert")
|
21
20
|
app.shell.should_receive(:run).with(%r[/bin/convert], hash_including)
|
22
|
-
app.create("").thumb(
|
21
|
+
app.create("").thumb("30x30").apply
|
23
22
|
end
|
24
23
|
|
25
24
|
it "allows configuring the identify path" do
|
26
|
-
app.configure_with(:imagemagick, :identify_command =>
|
25
|
+
app.configure_with(:imagemagick, :identify_command => "/bin/identify")
|
27
26
|
app.shell.should_receive(:run).with(%r[/bin/identify], hash_including).and_return("JPG 1 1")
|
28
27
|
app.create("").width
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -2,19 +2,19 @@ require "rubygems"
|
|
2
2
|
require "bundler"
|
3
3
|
Bundler.setup(:default, :test)
|
4
4
|
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
6
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
7
|
+
require "rspec"
|
8
|
+
require "dragonfly"
|
9
|
+
require "fileutils"
|
10
|
+
require "tempfile"
|
11
|
+
require "webmock/rspec"
|
12
|
+
require "pry"
|
13
13
|
|
14
14
|
# Requires supporting files with custom matchers and macros, etc,
|
15
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
16
16
|
|
17
|
-
SAMPLES_DIR = Pathname.new(File.expand_path(
|
17
|
+
SAMPLES_DIR = Pathname.new(File.expand_path("../../samples", __FILE__))
|
18
18
|
|
19
19
|
RSpec.configure do |c|
|
20
20
|
c.include ModelHelpers
|
@@ -25,8 +25,8 @@ def todo
|
|
25
25
|
raise "TODO"
|
26
26
|
end
|
27
27
|
|
28
|
-
require
|
29
|
-
LOG_FILE =
|
28
|
+
require "logger"
|
29
|
+
LOG_FILE = "tmp/test.log"
|
30
30
|
FileUtils.rm_rf(LOG_FILE)
|
31
31
|
Dragonfly.logger = Logger.new(LOG_FILE)
|
32
32
|
|
@@ -36,7 +36,7 @@ RSpec.configure do |c|
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def test_app(name=nil)
|
39
|
+
def test_app(name = nil)
|
40
40
|
app = Dragonfly::App.instance(name)
|
41
41
|
app.datastore = Dragonfly::MemoryDataStore.new
|
42
42
|
app.secret = "test secret"
|
@@ -45,8 +45,6 @@ end
|
|
45
45
|
|
46
46
|
def test_imagemagick_app
|
47
47
|
test_app.configure do
|
48
|
-
generator :convert, Dragonfly::ImageMagick::Generators::Convert.new
|
49
|
-
processor :convert, Dragonfly::ImageMagick::Processors::Convert.new
|
50
48
|
analyser :image_properties, Dragonfly::ImageMagick::Analysers::ImageProperties.new
|
51
49
|
end
|
52
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: |-
|
98
126
|
Dragonfly is a framework that enables on-the-fly processing for any content type.
|
99
127
|
It is especially suited to image handling. Its uses range from image thumbnails to standard attachments to on-demand text generation.
|
@@ -130,12 +158,11 @@ files:
|
|
130
158
|
- lib/dragonfly/has_filename.rb
|
131
159
|
- lib/dragonfly/hash_with_css_style_keys.rb
|
132
160
|
- lib/dragonfly/image_magick/analysers/image_properties.rb
|
133
|
-
- lib/dragonfly/image_magick/
|
161
|
+
- lib/dragonfly/image_magick/commands.rb
|
134
162
|
- lib/dragonfly/image_magick/generators/plain.rb
|
135
163
|
- lib/dragonfly/image_magick/generators/plasma.rb
|
136
164
|
- lib/dragonfly/image_magick/generators/text.rb
|
137
165
|
- lib/dragonfly/image_magick/plugin.rb
|
138
|
-
- lib/dragonfly/image_magick/processors/convert.rb
|
139
166
|
- lib/dragonfly/image_magick/processors/encode.rb
|
140
167
|
- lib/dragonfly/image_magick/processors/thumb.rb
|
141
168
|
- lib/dragonfly/job.rb
|
@@ -154,6 +181,7 @@ files:
|
|
154
181
|
- lib/dragonfly/model/class_methods.rb
|
155
182
|
- lib/dragonfly/model/instance_methods.rb
|
156
183
|
- lib/dragonfly/model/validations.rb
|
184
|
+
- lib/dragonfly/param_validators.rb
|
157
185
|
- lib/dragonfly/rails/images.rb
|
158
186
|
- lib/dragonfly/railtie.rb
|
159
187
|
- lib/dragonfly/register.rb
|
@@ -192,12 +220,12 @@ files:
|
|
192
220
|
- spec/dragonfly/has_filename_spec.rb
|
193
221
|
- spec/dragonfly/hash_with_css_style_keys_spec.rb
|
194
222
|
- spec/dragonfly/image_magick/analysers/image_properties_spec.rb
|
195
|
-
- spec/dragonfly/image_magick/
|
223
|
+
- spec/dragonfly/image_magick/commands_spec.rb
|
196
224
|
- spec/dragonfly/image_magick/generators/plain_spec.rb
|
197
225
|
- spec/dragonfly/image_magick/generators/plasma_spec.rb
|
198
226
|
- spec/dragonfly/image_magick/generators/text_spec.rb
|
199
227
|
- spec/dragonfly/image_magick/plugin_spec.rb
|
200
|
-
- spec/dragonfly/image_magick/processors/
|
228
|
+
- spec/dragonfly/image_magick/processors/encode_spec.rb
|
201
229
|
- spec/dragonfly/image_magick/processors/thumb_spec.rb
|
202
230
|
- spec/dragonfly/job/fetch_file_spec.rb
|
203
231
|
- spec/dragonfly/job/fetch_spec.rb
|
@@ -208,8 +236,10 @@ files:
|
|
208
236
|
- spec/dragonfly/job_spec.rb
|
209
237
|
- spec/dragonfly/memory_data_store_spec.rb
|
210
238
|
- spec/dragonfly/middleware_spec.rb
|
239
|
+
- spec/dragonfly/model/active_record_spec.rb
|
211
240
|
- spec/dragonfly/model/model_spec.rb
|
212
241
|
- spec/dragonfly/model/validations_spec.rb
|
242
|
+
- spec/dragonfly/param_validators_spec.rb
|
213
243
|
- spec/dragonfly/register_spec.rb
|
214
244
|
- spec/dragonfly/routed_endpoint_spec.rb
|
215
245
|
- spec/dragonfly/serializer_spec.rb
|
@@ -241,7 +271,7 @@ homepage: http://github.com/markevans/dragonfly
|
|
241
271
|
licenses:
|
242
272
|
- MIT
|
243
273
|
metadata: {}
|
244
|
-
post_install_message:
|
274
|
+
post_install_message:
|
245
275
|
rdoc_options: []
|
246
276
|
require_paths:
|
247
277
|
- lib
|
@@ -256,9 +286,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
286
|
- !ruby/object:Gem::Version
|
257
287
|
version: '0'
|
258
288
|
requirements: []
|
259
|
-
|
260
|
-
|
261
|
-
signing_key:
|
289
|
+
rubygems_version: 3.2.15
|
290
|
+
signing_key:
|
262
291
|
specification_version: 4
|
263
292
|
summary: Ideal gem for handling attachments in Rails, Sinatra and Rack applications.
|
264
293
|
test_files:
|
@@ -272,12 +301,12 @@ test_files:
|
|
272
301
|
- spec/dragonfly/has_filename_spec.rb
|
273
302
|
- spec/dragonfly/hash_with_css_style_keys_spec.rb
|
274
303
|
- spec/dragonfly/image_magick/analysers/image_properties_spec.rb
|
275
|
-
- spec/dragonfly/image_magick/
|
304
|
+
- spec/dragonfly/image_magick/commands_spec.rb
|
276
305
|
- spec/dragonfly/image_magick/generators/plain_spec.rb
|
277
306
|
- spec/dragonfly/image_magick/generators/plasma_spec.rb
|
278
307
|
- spec/dragonfly/image_magick/generators/text_spec.rb
|
279
308
|
- spec/dragonfly/image_magick/plugin_spec.rb
|
280
|
-
- spec/dragonfly/image_magick/processors/
|
309
|
+
- spec/dragonfly/image_magick/processors/encode_spec.rb
|
281
310
|
- spec/dragonfly/image_magick/processors/thumb_spec.rb
|
282
311
|
- spec/dragonfly/job/fetch_file_spec.rb
|
283
312
|
- spec/dragonfly/job/fetch_spec.rb
|
@@ -288,8 +317,10 @@ test_files:
|
|
288
317
|
- spec/dragonfly/job_spec.rb
|
289
318
|
- spec/dragonfly/memory_data_store_spec.rb
|
290
319
|
- spec/dragonfly/middleware_spec.rb
|
320
|
+
- spec/dragonfly/model/active_record_spec.rb
|
291
321
|
- spec/dragonfly/model/model_spec.rb
|
292
322
|
- spec/dragonfly/model/validations_spec.rb
|
323
|
+
- spec/dragonfly/param_validators_spec.rb
|
293
324
|
- spec/dragonfly/register_spec.rb
|
294
325
|
- spec/dragonfly/routed_endpoint_spec.rb
|
295
326
|
- spec/dragonfly/serializer_spec.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Dragonfly
|
2
|
-
module ImageMagick
|
3
|
-
module Generators
|
4
|
-
class Convert
|
5
|
-
|
6
|
-
def call(content, args, format)
|
7
|
-
format = format.to_s
|
8
|
-
convert_command = content.env[:convert_command] || 'convert'
|
9
|
-
content.shell_generate :ext => format do |path|
|
10
|
-
"#{convert_command} #{args} #{path}"
|
11
|
-
end
|
12
|
-
content.add_meta('format' => format)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Dragonfly
|
2
|
-
module ImageMagick
|
3
|
-
module Processors
|
4
|
-
class Convert
|
5
|
-
|
6
|
-
def call(content, args='', opts={})
|
7
|
-
convert_command = content.env[:convert_command] || 'convert'
|
8
|
-
format = opts['format']
|
9
|
-
|
10
|
-
input_args = opts['input_args'] if opts['input_args']
|
11
|
-
delegate_string = "#{opts['delegate']}:" if opts['delegate']
|
12
|
-
frame_string = "[#{opts['frame']}]" if opts['frame']
|
13
|
-
|
14
|
-
content.shell_update :ext => format do |old_path, new_path|
|
15
|
-
"#{convert_command} #{input_args} #{delegate_string}#{old_path}#{frame_string} #{args} #{new_path}"
|
16
|
-
end
|
17
|
-
|
18
|
-
if format
|
19
|
-
content.meta['format'] = format.to_s
|
20
|
-
content.ext = format
|
21
|
-
content.meta['mime_type'] = nil # don't need it as we have ext now
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def update_url(attrs, args='', opts={})
|
26
|
-
format = opts['format']
|
27
|
-
attrs.ext = format if format
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagick::Generators::Convert do
|
4
|
-
let (:generator) { Dragonfly::ImageMagick::Generators::Convert.new }
|
5
|
-
let (:app) { test_app }
|
6
|
-
let (:image) { Dragonfly::Content.new(app) }
|
7
|
-
|
8
|
-
describe "calling convert" do
|
9
|
-
before(:each) do
|
10
|
-
generator.call(image, "-size 1x1 xc:white", 'png')
|
11
|
-
end
|
12
|
-
it {image.should have_width(1)}
|
13
|
-
it {image.should have_height(1)}
|
14
|
-
it {image.should have_format('png')}
|
15
|
-
it {image.meta.should == {'format' => 'png'}}
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagick::Processors::Convert do
|
4
|
-
|
5
|
-
def sample_content(name)
|
6
|
-
Dragonfly::Content.new(app, SAMPLES_DIR.join(name))
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:app){ test_app }
|
10
|
-
let(:image){ sample_content('beach.png') } # 280x355
|
11
|
-
let(:processor){ Dragonfly::ImageMagick::Processors::Convert.new }
|
12
|
-
|
13
|
-
it "should allow for general convert commands" do
|
14
|
-
processor.call(image, '-scale 56x71')
|
15
|
-
image.should have_width(56)
|
16
|
-
image.should have_height(71)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should allow for general convert commands with added format" do
|
20
|
-
processor.call(image, '-scale 56x71', 'format' => 'gif')
|
21
|
-
image.should have_width(56)
|
22
|
-
image.should have_height(71)
|
23
|
-
image.should have_format('gif')
|
24
|
-
image.meta['format'].should == 'gif'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should work for commands with parenthesis" do
|
28
|
-
processor.call(image, "\\( +clone -sparse-color Barycentric '0,0 black 0,%[fx:h-1] white' -function polynomial 2,-2,0.5 \\) -compose Blur -set option:compose:args 15 -composite")
|
29
|
-
image.should have_width(280)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should work for files with spaces/apostrophes in the name" do
|
33
|
-
image = Dragonfly::Content.new(app, SAMPLES_DIR.join("mevs' white pixel.png"))
|
34
|
-
processor.call(image, "-resize 2x2!")
|
35
|
-
image.should have_width(2)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "updates the url with format if given" do
|
39
|
-
url_attributes = Dragonfly::UrlAttributes.new
|
40
|
-
processor.update_url(url_attributes, '-scale 56x71', 'format' => 'gif')
|
41
|
-
url_attributes.ext.should == 'gif'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "allows converting specific frames" do
|
45
|
-
gif = sample_content('gif.gif')
|
46
|
-
processor.call(gif, '-resize 50x50')
|
47
|
-
all_frames_size = gif.size
|
48
|
-
|
49
|
-
gif = sample_content('gif.gif')
|
50
|
-
processor.call(gif, '-resize 50x50', 'frame' => 0)
|
51
|
-
one_frame_size = gif.size
|
52
|
-
|
53
|
-
one_frame_size.should < all_frames_size
|
54
|
-
end
|
55
|
-
|
56
|
-
it "accepts input arguments for convert commands" do
|
57
|
-
image2 = image.clone
|
58
|
-
processor.call(image, '')
|
59
|
-
processor.call(image2, '', 'input_args' => '-extract 50x50+10+10')
|
60
|
-
|
61
|
-
image.should_not equal_image(image2)
|
62
|
-
image2.should have_width(50)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "allows converting using specific delegates" do
|
66
|
-
expect {
|
67
|
-
processor.call(image, '', 'format' => 'jpg', 'delegate' => 'png')
|
68
|
-
}.to call_command(app.shell, %r{convert png:/[^']+?/beach\.png /[^']+?\.jpg})
|
69
|
-
end
|
70
|
-
|
71
|
-
it "maintains the mime_type meta if it exists already" do
|
72
|
-
processor.call(image, '-resize 10x')
|
73
|
-
image.meta['mime_type'].should be_nil
|
74
|
-
|
75
|
-
image.add_meta('mime_type' => 'image/png')
|
76
|
-
processor.call(image, '-resize 5x')
|
77
|
-
image.meta['mime_type'].should == 'image/png'
|
78
|
-
image.mime_type.should == 'image/png' # sanity check
|
79
|
-
end
|
80
|
-
|
81
|
-
it "doesn't maintain the mime_type meta on format change" do
|
82
|
-
image.add_meta('mime_type' => 'image/png')
|
83
|
-
processor.call(image, '', 'format' => 'gif')
|
84
|
-
image.meta['mime_type'].should be_nil
|
85
|
-
image.mime_type.should == 'image/gif' # sanity check
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|