Skip to content

Commit a9ac0f8

Browse files
keithpittJon Yurek
authored and
Jon Yurek
committed
CommandLine uses Paperclip.options[:swallow_stderr] as a default if no :swallow_stderr option is specified.
(cherry picked from commit 753b8b9fc2cb24c9006fe2e6f48d4fe57519eb7a)
1 parent 50a196b commit a9ac0f8

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/paperclip/command_line.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(binary, params = "", options = {})
88
@binary = binary.dup
99
@params = params.dup
1010
@options = options.dup
11-
@swallow_stderr = @options.delete(:swallow_stderr)
11+
@swallow_stderr = @options.has_key?(:swallow_stderr) ? @options.delete(:swallow_stderr) : Paperclip.options[:swallow_stderr]
1212
@expected_outcodes = @options.delete(:expected_outcodes)
1313
@expected_outcodes ||= [0]
1414
end

test/command_line_test.rb

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ def setup
77
end
88

99
should "take a command and parameters and produce a shell command for bash" do
10-
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
10+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
1111
assert_equal "convert a.jpg b.png", cmd.command
1212
end
1313

1414
should "be able to set a path and produce commands with that path" do
1515
Paperclip::CommandLine.path = "/opt/bin"
16-
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
16+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
1717
assert_equal "/opt/bin/convert a.jpg b.png", cmd.command
1818
end
1919

2020
should "be able to interpolate quoted variables into the parameters" do
2121
cmd = Paperclip::CommandLine.new("convert",
2222
":one :{two}",
2323
:one => "a.jpg",
24-
:two => "b.png")
24+
:two => "b.png",
25+
:swallow_stderr => false)
2526
assert_equal "convert 'a.jpg' 'b.png'", cmd.command
2627
end
2728

@@ -30,15 +31,17 @@ def setup
3031
cmd = Paperclip::CommandLine.new("convert",
3132
":one :{two}",
3233
:one => "a.jpg",
33-
:two => "b.png")
34+
:two => "b.png",
35+
:swallow_stderr => false)
3436
assert_equal 'convert "a.jpg" "b.png"', cmd.command
3537
end
3638

3739
should "be able to quote and interpolate dangerous variables" do
3840
cmd = Paperclip::CommandLine.new("convert",
3941
":one :two",
4042
:one => "`rm -rf`.jpg",
41-
:two => "ha'ha.png")
43+
:two => "ha'ha.png",
44+
:swallow_stderr => false)
4245
assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
4346
end
4447

@@ -47,7 +50,8 @@ def setup
4750
cmd = Paperclip::CommandLine.new("convert",
4851
":one :two",
4952
:one => "`rm -rf`.jpg",
50-
:two => "ha'ha.png")
53+
:two => "ha'ha.png",
54+
:swallow_stderr => false)
5155
assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
5256
end
5357

@@ -80,15 +84,15 @@ def setup
8084
end
8185

8286
should "run the #command it's given and return the output" do
83-
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
87+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
8488
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
8589
with_exitstatus_returning(0) do
8690
assert_equal :correct_value, cmd.run
8791
end
8892
end
8993

9094
should "raise a PaperclipCommandLineError if the result code isn't expected" do
91-
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
95+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
9296
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
9397
with_exitstatus_returning(1) do
9498
assert_raises(Paperclip::PaperclipCommandLineError) do
@@ -100,7 +104,8 @@ def setup
100104
should "not raise a PaperclipCommandLineError if the result code is expected" do
101105
cmd = Paperclip::CommandLine.new("convert",
102106
"a.jpg b.png",
103-
:expected_outcodes => [0, 1])
107+
:expected_outcodes => [0, 1],
108+
:swallow_stderr => false)
104109
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
105110
with_exitstatus_returning(1) do
106111
assert_nothing_raised do
@@ -110,7 +115,7 @@ def setup
110115
end
111116

112117
should "log the command" do
113-
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png")
118+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
114119
cmd.class.stubs(:'`')
115120
Paperclip.expects(:log).with("convert a.jpg b.png")
116121
cmd.run

0 commit comments

Comments
 (0)