Commit a9ac0f86 by Keith Pitt Committed by Jon Yurek

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

CommandLine uses Paperclip.options[:swallow_stderr] as a default if no :swallow_stderr option is specified.
(cherry picked from commit 753b8b9fc2cb24c9006fe2e6f48d4fe57519eb7a)
parent 50a196b4
...@@ -8,7 +8,7 @@ module Paperclip ...@@ -8,7 +8,7 @@ module Paperclip
@binary = binary.dup @binary = binary.dup
@params = params.dup @params = params.dup
@options = options.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 = @options.delete(:expected_outcodes)
@expected_outcodes ||= [0] @expected_outcodes ||= [0]
end end
......
...@@ -7,13 +7,13 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -7,13 +7,13 @@ class CommandLineTest < Test::Unit::TestCase
end end
should "take a command and parameters and produce a shell command for bash" do 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 assert_equal "convert a.jpg b.png", cmd.command
end end
should "be able to set a path and produce commands with that path" do should "be able to set a path and produce commands with that path" do
Paperclip::CommandLine.path = "/opt/bin" 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 assert_equal "/opt/bin/convert a.jpg b.png", cmd.command
end end
...@@ -21,7 +21,8 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -21,7 +21,8 @@ class CommandLineTest < Test::Unit::TestCase
cmd = Paperclip::CommandLine.new("convert", cmd = Paperclip::CommandLine.new("convert",
":one :{two}", ":one :{two}",
:one => "a.jpg", :one => "a.jpg",
:two => "b.png") :two => "b.png",
:swallow_stderr => false)
assert_equal "convert 'a.jpg' 'b.png'", cmd.command assert_equal "convert 'a.jpg' 'b.png'", cmd.command
end end
...@@ -30,7 +31,8 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -30,7 +31,8 @@ class CommandLineTest < Test::Unit::TestCase
cmd = Paperclip::CommandLine.new("convert", cmd = Paperclip::CommandLine.new("convert",
":one :{two}", ":one :{two}",
:one => "a.jpg", :one => "a.jpg",
:two => "b.png") :two => "b.png",
:swallow_stderr => false)
assert_equal 'convert "a.jpg" "b.png"', cmd.command assert_equal 'convert "a.jpg" "b.png"', cmd.command
end end
...@@ -38,7 +40,8 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -38,7 +40,8 @@ class CommandLineTest < Test::Unit::TestCase
cmd = Paperclip::CommandLine.new("convert", cmd = Paperclip::CommandLine.new("convert",
":one :two", ":one :two",
:one => "`rm -rf`.jpg", :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 assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
end end
...@@ -47,7 +50,8 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -47,7 +50,8 @@ class CommandLineTest < Test::Unit::TestCase
cmd = Paperclip::CommandLine.new("convert", cmd = Paperclip::CommandLine.new("convert",
":one :two", ":one :two",
:one => "`rm -rf`.jpg", :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 assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
end end
...@@ -80,7 +84,7 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -80,7 +84,7 @@ class CommandLineTest < Test::Unit::TestCase
end end
should "run the #command it's given and return the output" do 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) cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
with_exitstatus_returning(0) do with_exitstatus_returning(0) do
assert_equal :correct_value, cmd.run assert_equal :correct_value, cmd.run
...@@ -88,7 +92,7 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -88,7 +92,7 @@ class CommandLineTest < Test::Unit::TestCase
end end
should "raise a PaperclipCommandLineError if the result code isn't expected" do 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) cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
with_exitstatus_returning(1) do with_exitstatus_returning(1) do
assert_raises(Paperclip::PaperclipCommandLineError) do assert_raises(Paperclip::PaperclipCommandLineError) do
...@@ -100,7 +104,8 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -100,7 +104,8 @@ class CommandLineTest < Test::Unit::TestCase
should "not raise a PaperclipCommandLineError if the result code is expected" do should "not raise a PaperclipCommandLineError if the result code is expected" do
cmd = Paperclip::CommandLine.new("convert", cmd = Paperclip::CommandLine.new("convert",
"a.jpg b.png", "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) cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
with_exitstatus_returning(1) do with_exitstatus_returning(1) do
assert_nothing_raised do assert_nothing_raised do
...@@ -110,7 +115,7 @@ class CommandLineTest < Test::Unit::TestCase ...@@ -110,7 +115,7 @@ class CommandLineTest < Test::Unit::TestCase
end end
should "log the command" do 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(:'`') cmd.class.stubs(:'`')
Paperclip.expects(:log).with("convert a.jpg b.png") Paperclip.expects(:log).with("convert a.jpg b.png")
cmd.run cmd.run
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment