Browse files

CommandLine uses Paperclip.options[:swallow_stderr] as a default if n…

…o :swallow_stderr option is specified.

(cherry picked from commit 753b8b9fc2cb24c9006fe2e6f48d4fe57519eb7a)
  • Loading branch information...
1 parent 50a196b commit a9ac0f8608db7e296991489f99781bafe29efb8c @keithpitt keithpitt committed with jyurek Oct 6, 2010
Showing with 16 additions and 11 deletions.
  1. +1 −1 lib/paperclip/command_line.rb
  2. +15 −10 test/command_line_test.rb
View
2 lib/paperclip/command_line.rb
@@ -8,7 +8,7 @@ def initialize(binary, params = "", options = {})
@binary = binary.dup
@params = params.dup
@options = options.dup
- @swallow_stderr = @options.delete(:swallow_stderr)
+ @swallow_stderr = @options.has_key?(:swallow_stderr) ? @options.delete(:swallow_stderr) : Paperclip.options[:swallow_stderr]
@expected_outcodes = @options.delete(:expected_outcodes)
@expected_outcodes ||= [0]
end
View
25 test/command_line_test.rb
@@ -7,21 +7,22 @@ def setup
end
should "take a command and parameters and produce a shell command for bash" do
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
+ cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
assert_equal "convert a.jpg b.png", cmd.command
end
should "be able to set a path and produce commands with that path" do
Paperclip::CommandLine.path = "/opt/bin"
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
+ cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
assert_equal "/opt/bin/convert a.jpg b.png", cmd.command
end
should "be able to interpolate quoted variables into the parameters" do
cmd = Paperclip::CommandLine.new("convert",
":one :{two}",
:one => "a.jpg",
- :two => "b.png")
+ :two => "b.png",
+ :swallow_stderr => false)
assert_equal "convert 'a.jpg' 'b.png'", cmd.command
end
@@ -30,15 +31,17 @@ def setup
cmd = Paperclip::CommandLine.new("convert",
":one :{two}",
:one => "a.jpg",
- :two => "b.png")
+ :two => "b.png",
+ :swallow_stderr => false)
assert_equal 'convert "a.jpg" "b.png"', cmd.command
end
should "be able to quote and interpolate dangerous variables" do
cmd = Paperclip::CommandLine.new("convert",
":one :two",
:one => "`rm -rf`.jpg",
- :two => "ha'ha.png")
+ :two => "ha'ha.png",
+ :swallow_stderr => false)
assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
end
@@ -47,7 +50,8 @@ def setup
cmd = Paperclip::CommandLine.new("convert",
":one :two",
:one => "`rm -rf`.jpg",
- :two => "ha'ha.png")
+ :two => "ha'ha.png",
+ :swallow_stderr => false)
assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
end
@@ -80,15 +84,15 @@ def setup
end
should "run the #command it's given and return the output" do
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
+ cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
with_exitstatus_returning(0) do
assert_equal :correct_value, cmd.run
end
end
should "raise a PaperclipCommandLineError if the result code isn't expected" do
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
+ cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
with_exitstatus_returning(1) do
assert_raises(Paperclip::PaperclipCommandLineError) do
@@ -100,7 +104,8 @@ def setup
should "not raise a PaperclipCommandLineError if the result code is expected" do
cmd = Paperclip::CommandLine.new("convert",
"a.jpg b.png",
- :expected_outcodes => [0, 1])
+ :expected_outcodes => [0, 1],
+ :swallow_stderr => false)
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
with_exitstatus_returning(1) do
assert_nothing_raised do
@@ -110,7 +115,7 @@ def setup
end
should "log the command" do
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
+ cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
cmd.class.stubs(:'`')
Paperclip.expects(:log).with("convert a.jpg b.png")
cmd.run

0 comments on commit a9ac0f8

Please sign in to comment.