paperclip 2.3.11 → 2.3.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

@@ -1,138 +0,0 @@
1
- require './test/helper'
2
-
3
- class CommandLineTest < Test::Unit::TestCase
4
- def setup
5
- Paperclip::CommandLine.path = nil
6
- File.stubs(:exist?).with("/dev/null").returns(true)
7
- end
8
-
9
- should "allow colons in parameters" do
10
- cmd = Paperclip::CommandLine.new("convert", "'a.jpg' -resize 175x220> -size 175x220 xc:black +swap -gravity center -composite 'b.jpg'", :swallow_stderr => false)
11
- assert_equal "convert 'a.jpg' -resize 175x220> -size 175x220 xc:black +swap -gravity center -composite 'b.jpg'", cmd.command
12
- end
13
-
14
- should "take a command and parameters and produce a shell command for bash" do
15
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
16
- assert_equal "convert a.jpg b.png", cmd.command
17
- end
18
-
19
- should "be able to set a path and produce commands with that path" do
20
- Paperclip::CommandLine.path = "/opt/bin"
21
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
22
- assert_equal "/opt/bin/convert a.jpg b.png", cmd.command
23
- end
24
-
25
- should "be able to interpolate quoted variables into the parameters" do
26
- cmd = Paperclip::CommandLine.new("convert",
27
- ":one :{two}",
28
- :one => "a.jpg",
29
- :two => "b.png",
30
- :swallow_stderr => false)
31
- assert_equal "convert 'a.jpg' 'b.png'", cmd.command
32
- end
33
-
34
- should "quote command line options differently if we're on windows" do
35
- File.stubs(:exist?).with("/dev/null").returns(false)
36
- cmd = Paperclip::CommandLine.new("convert",
37
- ":one :{two}",
38
- :one => "a.jpg",
39
- :two => "b.png",
40
- :swallow_stderr => false)
41
- assert_equal 'convert "a.jpg" "b.png"', cmd.command
42
- end
43
-
44
- should "be able to quote and interpolate dangerous variables" do
45
- cmd = Paperclip::CommandLine.new("convert",
46
- ":one :two",
47
- :one => "`rm -rf`.jpg",
48
- :two => "ha'ha.png",
49
- :swallow_stderr => false)
50
- assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
51
- end
52
-
53
- should "be able to quote and interpolate dangerous variables even on windows" do
54
- File.stubs(:exist?).with("/dev/null").returns(false)
55
- cmd = Paperclip::CommandLine.new("convert",
56
- ":one :two",
57
- :one => "`rm -rf`.jpg",
58
- :two => "ha'ha.png",
59
- :swallow_stderr => false)
60
- assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
61
- end
62
-
63
- should "add redirection to get rid of stderr in bash" do
64
- File.stubs(:exist?).with("/dev/null").returns(true)
65
- cmd = Paperclip::CommandLine.new("convert",
66
- "a.jpg b.png",
67
- :swallow_stderr => true)
68
-
69
- assert_equal "convert a.jpg b.png 2>/dev/null", cmd.command
70
- end
71
-
72
- should "add redirection to get rid of stderr in cmd.exe" do
73
- File.stubs(:exist?).with("/dev/null").returns(false)
74
- cmd = Paperclip::CommandLine.new("convert",
75
- "a.jpg b.png",
76
- :swallow_stderr => true)
77
-
78
- assert_equal "convert a.jpg b.png 2>NUL", cmd.command
79
- end
80
-
81
- should "raise if trying to interpolate :swallow_stderr or :expected_outcodes" do
82
- cmd = Paperclip::CommandLine.new("convert",
83
- ":swallow_stderr :expected_outcodes",
84
- :swallow_stderr => false,
85
- :expected_outcodes => [0, 1])
86
- assert_raise(Paperclip::PaperclipCommandLineError) do
87
- cmd.command
88
- end
89
- end
90
-
91
- should "run the #command it's given and return the output" do
92
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
93
- cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
94
- with_exitstatus_returning(0) do
95
- assert_equal :correct_value, cmd.run
96
- end
97
- end
98
-
99
- should "raise a PaperclipCommandLineError if the result code isn't expected" do
100
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
101
- cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
102
- with_exitstatus_returning(1) do
103
- assert_raises(Paperclip::PaperclipCommandLineError) do
104
- cmd.run
105
- end
106
- end
107
- end
108
-
109
- should "not raise a PaperclipCommandLineError if the result code is expected" do
110
- cmd = Paperclip::CommandLine.new("convert",
111
- "a.jpg b.png",
112
- :expected_outcodes => [0, 1],
113
- :swallow_stderr => false)
114
- cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
115
- with_exitstatus_returning(1) do
116
- assert_nothing_raised do
117
- cmd.run
118
- end
119
- end
120
- end
121
-
122
- should "log the command" do
123
- cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
124
- cmd.class.stubs(:'`')
125
- Paperclip.expects(:log).with("convert a.jpg b.png")
126
- cmd.run
127
- end
128
-
129
- should "detect that the system is unix or windows based on presence of /dev/null" do
130
- File.stubs(:exist?).returns(true)
131
- assert Paperclip::CommandLine.unix?
132
- end
133
-
134
- should "detect that the system is not unix or windows based on absence of /dev/null" do
135
- File.stubs(:exist?).returns(false)
136
- assert ! Paperclip::CommandLine.unix?
137
- end
138
- end