dragonfly 1.1.4 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +14 -6
  3. data/History.md +336 -309
  4. data/README.md +1 -1
  5. data/dev/rails_template.rb +35 -33
  6. data/dragonfly.gemspec +10 -16
  7. data/lib/dragonfly.rb +3 -1
  8. data/lib/dragonfly/content.rb +21 -22
  9. data/lib/dragonfly/image_magick/commands.rb +35 -0
  10. data/lib/dragonfly/image_magick/generators/plain.rb +13 -7
  11. data/lib/dragonfly/image_magick/generators/plasma.rb +10 -6
  12. data/lib/dragonfly/image_magick/generators/text.rb +67 -58
  13. data/lib/dragonfly/image_magick/plugin.rb +26 -25
  14. data/lib/dragonfly/image_magick/processors/encode.rb +16 -5
  15. data/lib/dragonfly/image_magick/processors/thumb.rb +37 -31
  16. data/lib/dragonfly/job/fetch_url.rb +1 -1
  17. data/lib/dragonfly/model/class_methods.rb +6 -1
  18. data/lib/dragonfly/param_validators.rb +37 -0
  19. data/lib/dragonfly/response.rb +2 -2
  20. data/lib/dragonfly/shell.rb +19 -13
  21. data/lib/dragonfly/utils.rb +1 -1
  22. data/lib/dragonfly/version.rb +1 -1
  23. data/samples/white pixel.png b/data/samples/mevs' white → pixel.png +0 -0
  24. data/spec/dragonfly/content_spec.rb +3 -3
  25. data/spec/dragonfly/cookie_monster_spec.rb +2 -2
  26. data/spec/dragonfly/image_magick/commands_spec.rb +98 -0
  27. data/spec/dragonfly/image_magick/generators/plain_spec.rb +39 -13
  28. data/spec/dragonfly/image_magick/generators/plasma_spec.rb +28 -9
  29. data/spec/dragonfly/image_magick/generators/text_spec.rb +51 -20
  30. data/spec/dragonfly/image_magick/plugin_spec.rb +45 -28
  31. data/spec/dragonfly/image_magick/processors/encode_spec.rb +30 -0
  32. data/spec/dragonfly/image_magick/processors/thumb_spec.rb +46 -45
  33. data/spec/dragonfly/model/active_record_spec.rb +62 -0
  34. data/spec/dragonfly/param_validators_spec.rb +89 -0
  35. data/spec/dragonfly/shell_spec.rb +12 -10
  36. data/spec/dragonfly_spec.rb +37 -13
  37. data/spec/functional/shell_commands_spec.rb +6 -9
  38. data/spec/spec_helper.rb +12 -14
  39. metadata +45 -14
  40. data/lib/dragonfly/image_magick/generators/convert.rb +0 -19
  41. data/lib/dragonfly/image_magick/processors/convert.rb +0 -33
  42. data/spec/dragonfly/image_magick/generators/convert_spec.rb +0 -19
  43. data/spec/dragonfly/image_magick/processors/convert_spec.rb +0 -88
@@ -0,0 +1,62 @@
1
+ # jruby has problems with installing sqlite3 - don't bother with these tests for jruby
2
+ unless RUBY_PLATFORM == "java"
3
+ require "spec_helper"
4
+ require "active_record"
5
+ require "sqlite3"
6
+
7
+ # ActiveRecord specific stuff goes here (there should be very little!)
8
+ describe "ActiveRecord models" do
9
+ let! :dragonfly_app do test_app(:test_ar) end
10
+
11
+ before :all do
12
+ @connection = ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
13
+
14
+ ActiveRecord::Migration.verbose = false
15
+
16
+ ActiveRecord::Schema.define(:version => 1) do
17
+ create_table :photos do |t|
18
+ t.string :image_uid
19
+ end
20
+ end
21
+
22
+ class Photo < ActiveRecord::Base
23
+ extend Dragonfly::Model
24
+ dragonfly_accessor :image, app: :test_ar
25
+ end
26
+ end
27
+
28
+ after :all do
29
+ Photo.destroy_all
30
+ ActiveRecord::Base.remove_connection(@connection)
31
+ end
32
+
33
+ describe "destroying" do
34
+ before do
35
+ Photo.destroy_all
36
+ @photo = Photo.create(image: "some data")
37
+ end
38
+
39
+ def data_exists(uid)
40
+ !!dragonfly_app.datastore.read(uid)
41
+ end
42
+
43
+ it "should not remove the attachment if a transaction is cancelled" do
44
+ Photo.transaction do
45
+ @photo.destroy
46
+ raise ActiveRecord::Rollback
47
+ end
48
+ photo = Photo.last
49
+ expect(photo.image_uid).not_to be_nil
50
+ expect(data_exists(photo.image_uid)).to eq(true)
51
+ end
52
+
53
+ it "should remove the attachment as per usual otherwise" do
54
+ uid = @photo.image_uid
55
+ @photo.destroy
56
+ photo = Photo.last
57
+ expect(photo).to be_nil
58
+ expect(data_exists(uid)).to eq(false)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -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
@@ -22,19 +22,21 @@ describe Dragonfly::Shell do
22
22
 
23
23
  unless Dragonfly.running_on_windows?
24
24
 
25
+ # NOTE: every \\ translates to a single \ on the command line
25
26
  describe "escaping args" do
26
27
  {
27
- %q(hello) => %q('hello'),
28
- %q("hello") => %q('hello'),
29
- %q('hello') => %q('hello'),
30
- %q(he\'llo) => %q('he'\''llo'),
31
- %q('he'\''llo') => %q('he'\''llo'),
32
- %q("he'llo") => %q('he'\''llo'),
33
- %q(hel$(lo)) => %q('hel$(lo)'),
34
- %q(hel\$(lo)) => %q('hel$(lo)'),
35
- %q('hel\$(lo)') => %q('hel\$(lo)')
28
+ %q(hello there) => %q(hello there),
29
+ %q('hello' 'there') => %q(hello there),
30
+ %q(he\\'llo there) => %q(he\\'llo there),
31
+ %q(he\\ llo there) => %q(he\\ llo there),
32
+ %q("he'llo" there) => %q(he\\'llo there),
33
+ %q('he'\\''llo' there) => %q(he\\'llo there),
34
+ %q(hel$(lo) there) => %q(hel\\$\\(lo\\) there),
35
+ %q(hel\\$(lo) > there) => %q(hel\\$\\(lo\\) \\> there),
36
+ %q('hel$(lo) > there') => %q(hel\\$\\(lo\\)\\ \\>\\ there),
37
+ %q(hello -there) => %q(hello -there),
36
38
  }.each do |args, escaped_args|
37
- it "should escape #{args.inspect} -> #{escaped_args.inspect}" do
39
+ it "should escape #{args} -> #{escaped_args}" do
38
40
  shell.escape_args(args).should == escaped_args
39
41
  end
40
42
  end
@@ -12,23 +12,47 @@ describe Dragonfly do
12
12
  end
13
13
 
14
14
  describe "logging" do
15
- before do
16
- Dragonfly.logger = Logger.new(StringIO.new)
17
- end
15
+ context "logger exists" do
16
+ before do
17
+ Dragonfly.logger = Logger.new(StringIO.new)
18
+ end
18
19
 
19
- it "debugs" do
20
- Dragonfly.logger.should_receive(:debug).with(/something/)
21
- Dragonfly.debug("something")
22
- end
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
- it "warns" do
25
- Dragonfly.logger.should_receive(:warn).with(/something/)
26
- Dragonfly.warn("something")
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
- it "shows info" do
30
- Dragonfly.logger.should_receive(:info).with(/something/)
31
- Dragonfly.info("something")
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 'spec_helper'
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, 'white').convert("-resize 5x5 ; touch tmp/stuff").apply
10
+ app.generate(:plain, 10, 10, "white; touch tmp/stuff").apply
12
11
  rescue Dragonfly::Shell::CommandFailed
13
12
  end
14
- File.exist?('tmp/stuff').should be_falsey
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 => '/bin/convert')
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('30x30').apply
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 => '/bin/identify')
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__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'rspec'
8
- require 'dragonfly'
9
- require 'fileutils'
10
- require 'tempfile'
11
- require 'webmock/rspec'
12
- require 'pry'
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('../../samples', __FILE__))
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 'logger'
29
- LOG_FILE = 'tmp/test.log'
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.1.4
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: 2017-12-31 00:00:00.000000000 Z
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/generators/convert.rb
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
@@ -178,10 +206,10 @@ files:
178
206
  - samples/beach.png
179
207
  - samples/egg.png
180
208
  - samples/gif.gif
209
+ - samples/mevs' white pixel.png
181
210
  - samples/round.gif
182
211
  - samples/sample.docx
183
212
  - samples/taj.jpg
184
- - samples/white pixel.png
185
213
  - spec/dragonfly/app_spec.rb
186
214
  - spec/dragonfly/configurable_spec.rb
187
215
  - spec/dragonfly/content_spec.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/generators/convert_spec.rb
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/convert_spec.rb
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
- rubyforge_project:
260
- rubygems_version: 2.6.7
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/generators/convert_spec.rb
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/convert_spec.rb
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