paperclip-cloudfiles 2.3.2 → 2.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +10 -3
- data/Rakefile +8 -4
- data/generators/paperclip/USAGE +2 -2
- data/generators/paperclip/paperclip_generator.rb +8 -8
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +31 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip/attachment.rb +38 -18
- data/lib/paperclip/command_line.rb +80 -0
- data/lib/paperclip/geometry.rb +7 -7
- data/lib/paperclip/interpolations.rb +8 -2
- data/lib/paperclip/iostream.rb +11 -25
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +3 -3
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +0 -1
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +0 -1
- data/lib/paperclip/processor.rb +15 -6
- data/lib/paperclip/railtie.rb +24 -0
- data/lib/paperclip/storage/cloud_files.rb +131 -0
- data/lib/paperclip/storage/filesystem.rb +73 -0
- data/lib/paperclip/storage/s3.rb +192 -0
- data/lib/paperclip/storage.rb +3 -371
- data/lib/paperclip/style.rb +11 -11
- data/lib/paperclip/thumbnail.rb +16 -15
- data/lib/paperclip/upfile.rb +5 -3
- data/lib/paperclip/version.rb +3 -0
- data/lib/paperclip.rb +78 -92
- data/lib/tasks/paperclip.rake +72 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +1 -2
- data/test/attachment_test.rb +74 -28
- data/test/command_line_test.rb +133 -0
- data/test/geometry_test.rb +2 -2
- data/test/helper.rb +22 -24
- data/test/integration_test.rb +10 -11
- data/test/interpolations_test.rb +7 -4
- data/test/iostream_test.rb +6 -13
- data/test/matchers/have_attached_file_matcher_test.rb +1 -1
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +11 -1
- data/test/matchers/validate_attachment_presence_matcher_test.rb +1 -1
- data/test/matchers/validate_attachment_size_matcher_test.rb +1 -1
- data/test/paperclip_test.rb +54 -80
- data/test/processor_test.rb +1 -1
- data/test/storage_test.rb +32 -12
- data/test/style_test.rb +17 -17
- data/test/thumbnail_test.rb +18 -18
- data/test/upfile_test.rb +1 -1
- metadata +58 -31
- data/tasks/paperclip_tasks.rake +0 -79
@@ -0,0 +1,133 @@
|
|
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 "take a command and parameters and produce a shell command for bash" do
|
10
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
11
|
+
assert_equal "convert a.jpg b.png", cmd.command
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be able to set a path and produce commands with that path" do
|
15
|
+
Paperclip::CommandLine.path = "/opt/bin"
|
16
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
17
|
+
assert_equal "/opt/bin/convert a.jpg b.png", cmd.command
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be able to interpolate quoted variables into the parameters" do
|
21
|
+
cmd = Paperclip::CommandLine.new("convert",
|
22
|
+
":one :{two}",
|
23
|
+
:one => "a.jpg",
|
24
|
+
:two => "b.png",
|
25
|
+
:swallow_stderr => false)
|
26
|
+
assert_equal "convert 'a.jpg' 'b.png'", cmd.command
|
27
|
+
end
|
28
|
+
|
29
|
+
should "quote command line options differently if we're on windows" do
|
30
|
+
File.stubs(:exist?).with("/dev/null").returns(false)
|
31
|
+
cmd = Paperclip::CommandLine.new("convert",
|
32
|
+
":one :{two}",
|
33
|
+
:one => "a.jpg",
|
34
|
+
:two => "b.png",
|
35
|
+
:swallow_stderr => false)
|
36
|
+
assert_equal 'convert "a.jpg" "b.png"', cmd.command
|
37
|
+
end
|
38
|
+
|
39
|
+
should "be able to quote and interpolate dangerous variables" do
|
40
|
+
cmd = Paperclip::CommandLine.new("convert",
|
41
|
+
":one :two",
|
42
|
+
:one => "`rm -rf`.jpg",
|
43
|
+
:two => "ha'ha.png",
|
44
|
+
:swallow_stderr => false)
|
45
|
+
assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
|
46
|
+
end
|
47
|
+
|
48
|
+
should "be able to quote and interpolate dangerous variables even on windows" do
|
49
|
+
File.stubs(:exist?).with("/dev/null").returns(false)
|
50
|
+
cmd = Paperclip::CommandLine.new("convert",
|
51
|
+
":one :two",
|
52
|
+
:one => "`rm -rf`.jpg",
|
53
|
+
:two => "ha'ha.png",
|
54
|
+
:swallow_stderr => false)
|
55
|
+
assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
|
56
|
+
end
|
57
|
+
|
58
|
+
should "add redirection to get rid of stderr in bash" do
|
59
|
+
File.stubs(:exist?).with("/dev/null").returns(true)
|
60
|
+
cmd = Paperclip::CommandLine.new("convert",
|
61
|
+
"a.jpg b.png",
|
62
|
+
:swallow_stderr => true)
|
63
|
+
|
64
|
+
assert_equal "convert a.jpg b.png 2>/dev/null", cmd.command
|
65
|
+
end
|
66
|
+
|
67
|
+
should "add redirection to get rid of stderr in cmd.exe" do
|
68
|
+
File.stubs(:exist?).with("/dev/null").returns(false)
|
69
|
+
cmd = Paperclip::CommandLine.new("convert",
|
70
|
+
"a.jpg b.png",
|
71
|
+
:swallow_stderr => true)
|
72
|
+
|
73
|
+
assert_equal "convert a.jpg b.png 2>NUL", cmd.command
|
74
|
+
end
|
75
|
+
|
76
|
+
should "raise if trying to interpolate :swallow_stderr or :expected_outcodes" do
|
77
|
+
cmd = Paperclip::CommandLine.new("convert",
|
78
|
+
":swallow_stderr :expected_outcodes",
|
79
|
+
:swallow_stderr => false,
|
80
|
+
:expected_outcodes => [0, 1])
|
81
|
+
assert_raise(Paperclip::PaperclipCommandLineError) do
|
82
|
+
cmd.command
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
should "run the #command it's given and return the output" do
|
87
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
88
|
+
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
|
89
|
+
with_exitstatus_returning(0) do
|
90
|
+
assert_equal :correct_value, cmd.run
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
should "raise a PaperclipCommandLineError if the result code isn't expected" do
|
95
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
96
|
+
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
|
97
|
+
with_exitstatus_returning(1) do
|
98
|
+
assert_raises(Paperclip::PaperclipCommandLineError) do
|
99
|
+
cmd.run
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
should "not raise a PaperclipCommandLineError if the result code is expected" do
|
105
|
+
cmd = Paperclip::CommandLine.new("convert",
|
106
|
+
"a.jpg b.png",
|
107
|
+
:expected_outcodes => [0, 1],
|
108
|
+
:swallow_stderr => false)
|
109
|
+
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
|
110
|
+
with_exitstatus_returning(1) do
|
111
|
+
assert_nothing_raised do
|
112
|
+
cmd.run
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
should "log the command" do
|
118
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
119
|
+
cmd.class.stubs(:'`')
|
120
|
+
Paperclip.expects(:log).with("convert a.jpg b.png")
|
121
|
+
cmd.run
|
122
|
+
end
|
123
|
+
|
124
|
+
should "detect that the system is unix or windows based on presence of /dev/null" do
|
125
|
+
File.stubs(:exist?).returns(true)
|
126
|
+
assert Paperclip::CommandLine.unix?
|
127
|
+
end
|
128
|
+
|
129
|
+
should "detect that the system is not unix or windows based on absence of /dev/null" do
|
130
|
+
File.stubs(:exist?).returns(false)
|
131
|
+
assert ! Paperclip::CommandLine.unix?
|
132
|
+
end
|
133
|
+
end
|
data/test/geometry_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test/helper'
|
1
|
+
require './test/helper'
|
2
2
|
|
3
3
|
class GeometryTest < Test::Unit::TestCase
|
4
4
|
context "Paperclip::Geometry" do
|
@@ -65,7 +65,7 @@ class GeometryTest < Test::Unit::TestCase
|
|
65
65
|
assert_equal "123x456#{mod}", @geo.to_s
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
|
70
70
|
should "ensure the modifier #{mod.inspect} is preserved with no height" do
|
71
71
|
assert @geo = Paperclip::Geometry.parse("123x#{mod}")
|
data/test/helper.rb
CHANGED
@@ -8,27 +8,13 @@ require 'test/unit'
|
|
8
8
|
require 'shoulda'
|
9
9
|
require 'mocha'
|
10
10
|
|
11
|
-
case ENV['RAILS_VERSION']
|
12
|
-
when '2.1' then
|
13
|
-
gem 'activerecord', '~>2.1.0'
|
14
|
-
gem 'activesupport', '~>2.1.0'
|
15
|
-
gem 'actionpack', '~>2.1.0'
|
16
|
-
when '3.0' then
|
17
|
-
gem 'activerecord', '~>3.0.0'
|
18
|
-
gem 'activesupport', '~>3.0.0'
|
19
|
-
gem 'actionpack', '~>3.0.0'
|
20
|
-
else
|
21
|
-
gem 'activerecord', '~>2.3.0'
|
22
|
-
gem 'activesupport', '~>2.3.0'
|
23
|
-
gem 'actionpack', '~>2.3.0'
|
24
|
-
end
|
25
|
-
|
26
11
|
require 'active_record'
|
27
12
|
require 'active_record/version'
|
28
13
|
require 'active_support'
|
29
|
-
require 'action_pack'
|
30
14
|
|
31
|
-
puts "Testing
|
15
|
+
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
|
16
|
+
|
17
|
+
`ruby -e 'exit 0'` # Prime $? with a value.
|
32
18
|
|
33
19
|
begin
|
34
20
|
require 'ruby-debug'
|
@@ -58,18 +44,18 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
|
|
58
44
|
|
59
45
|
require File.join(ROOT, 'lib', 'paperclip.rb')
|
60
46
|
|
61
|
-
require 'shoulda_macros/paperclip'
|
47
|
+
require './shoulda_macros/paperclip'
|
62
48
|
|
63
|
-
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
49
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
64
50
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
65
|
-
ActiveRecord::Base.logger =
|
51
|
+
ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
|
66
52
|
ActiveRecord::Base.establish_connection(config['test'])
|
67
53
|
|
68
54
|
def reset_class class_name
|
69
|
-
ActiveRecord::Base.send(:include, Paperclip)
|
55
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
70
56
|
Object.send(:remove_const, class_name) rescue nil
|
71
57
|
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
|
72
|
-
klass.class_eval{ include Paperclip }
|
58
|
+
klass.class_eval{ include Paperclip::Glue }
|
73
59
|
klass
|
74
60
|
end
|
75
61
|
|
@@ -89,16 +75,17 @@ def rebuild_model options = {}
|
|
89
75
|
table.column :avatar_content_type, :string
|
90
76
|
table.column :avatar_file_size, :integer
|
91
77
|
table.column :avatar_updated_at, :datetime
|
78
|
+
table.column :avatar_fingerprint, :string
|
92
79
|
end
|
93
80
|
rebuild_class options
|
94
81
|
end
|
95
82
|
|
96
83
|
def rebuild_class options = {}
|
97
|
-
ActiveRecord::Base.send(:include, Paperclip)
|
84
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
98
85
|
Object.send(:remove_const, "Dummy") rescue nil
|
99
86
|
Object.const_set("Dummy", Class.new(ActiveRecord::Base))
|
100
87
|
Dummy.class_eval do
|
101
|
-
include Paperclip
|
88
|
+
include Paperclip::Glue
|
102
89
|
has_attached_file :avatar, options
|
103
90
|
end
|
104
91
|
end
|
@@ -108,6 +95,7 @@ class FakeModel
|
|
108
95
|
:avatar_file_size,
|
109
96
|
:avatar_last_updated,
|
110
97
|
:avatar_content_type,
|
98
|
+
:avatar_fingerprint,
|
111
99
|
:id
|
112
100
|
|
113
101
|
def errors
|
@@ -149,3 +137,13 @@ def should_reject_dummy_class
|
|
149
137
|
assert_rejects @matcher, @dummy_class.new
|
150
138
|
end
|
151
139
|
end
|
140
|
+
|
141
|
+
def with_exitstatus_returning(code)
|
142
|
+
saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
|
143
|
+
begin
|
144
|
+
`ruby -e 'exit #{code.to_i}'`
|
145
|
+
yield
|
146
|
+
ensure
|
147
|
+
`ruby -e 'exit #{saved_exitstatus.to_i}'`
|
148
|
+
end
|
149
|
+
end
|
data/test/integration_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test/helper'
|
1
|
+
require './test/helper'
|
2
2
|
|
3
3
|
class IntegrationTest < Test::Unit::TestCase
|
4
4
|
context "Many models at once" do
|
@@ -9,7 +9,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
9
9
|
Dummy.create! :avatar => @file
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
should "not exceed the open file limit" do
|
14
14
|
assert_nothing_raised do
|
15
15
|
dummies = Dummy.find(:all)
|
@@ -157,7 +157,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
context "A model with no convert_options setting" do
|
162
162
|
setup do
|
163
163
|
rebuild_model :styles => { :large => "300x300>",
|
@@ -168,7 +168,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
168
168
|
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
|
169
169
|
@dummy = Dummy.new
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
should "have its definition return nil when asked about convert_options" do
|
173
173
|
assert ! Dummy.attachment_definitions[:avatar][:convert_options]
|
174
174
|
end
|
@@ -189,7 +189,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
context "A model with a filesystem attachment" do
|
194
194
|
setup do
|
195
195
|
rebuild_model :styles => { :large => "300x300>",
|
@@ -204,7 +204,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
204
204
|
@bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"), 'rb')
|
205
205
|
|
206
206
|
assert @dummy.avatar = @file
|
207
|
-
assert @dummy.valid
|
207
|
+
assert @dummy.valid?, @dummy.errors.full_messages.join(", ")
|
208
208
|
assert @dummy.save
|
209
209
|
end
|
210
210
|
|
@@ -281,7 +281,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
281
281
|
Dummy.validates_attachment_presence :avatar
|
282
282
|
@d2 = Dummy.find(@dummy.id)
|
283
283
|
@d2.avatar = @file
|
284
|
-
assert @d2.valid?, @d2.errors.full_messages.inspect
|
284
|
+
assert @d2.valid?, @d2.errors.full_messages.inspect
|
285
285
|
@d2.avatar = @bad_file
|
286
286
|
assert ! @d2.valid?
|
287
287
|
end
|
@@ -294,7 +294,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
294
294
|
@dummy.reload
|
295
295
|
assert_equal "5k.png", @dummy.avatar_file_name
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
298
|
context "that is assigned its file from another Paperclip attachment" do
|
299
299
|
setup do
|
300
300
|
@dummy2 = Dummy.new
|
@@ -302,7 +302,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
302
302
|
assert @dummy2.avatar = @file2
|
303
303
|
@dummy2.save
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
should "work when assigned a file" do
|
307
307
|
assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
|
308
308
|
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
|
@@ -312,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
312
312
|
assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
|
313
313
|
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
|
314
314
|
end
|
315
|
-
end
|
315
|
+
end
|
316
316
|
|
317
317
|
end
|
318
318
|
|
@@ -363,7 +363,6 @@ class IntegrationTest < Test::Unit::TestCase
|
|
363
363
|
:thumb => ["32x32#", :gif] },
|
364
364
|
:storage => :s3,
|
365
365
|
:whiny_thumbnails => true,
|
366
|
-
# :s3_options => {:logger => Logger.new(StringIO.new)},
|
367
366
|
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml")),
|
368
367
|
:default_style => :medium,
|
369
368
|
:bucket => ENV['S3_TEST_BUCKET'],
|
data/test/interpolations_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test/helper'
|
1
|
+
require './test/helper'
|
2
2
|
|
3
3
|
class InterpolationsTest < Test::Unit::TestCase
|
4
4
|
should "return all methods but the infrastructure when sent #all" do
|
@@ -82,14 +82,17 @@ class InterpolationsTest < Test::Unit::TestCase
|
|
82
82
|
|
83
83
|
should "reinterpolate :url" do
|
84
84
|
attachment = mock
|
85
|
-
attachment.expects(:options).returns({:url => ":id"})
|
86
85
|
attachment.expects(:url).with(:style, false).returns("1234")
|
87
86
|
assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
|
88
87
|
end
|
89
88
|
|
90
89
|
should "raise if infinite loop detcted reinterpolating :url" do
|
91
|
-
attachment =
|
92
|
-
|
90
|
+
attachment = Object.new
|
91
|
+
class << attachment
|
92
|
+
def url(*args)
|
93
|
+
Paperclip::Interpolations.url(self, :style)
|
94
|
+
end
|
95
|
+
end
|
93
96
|
assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
|
94
97
|
end
|
95
98
|
|
data/test/iostream_test.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
|
-
require 'test/helper'
|
1
|
+
require './test/helper'
|
2
2
|
|
3
3
|
class IOStreamTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "be included in IO, File, Tempfile, and StringIO" do
|
6
|
-
[IO, File, Tempfile, StringIO].each do |klass|
|
7
|
-
assert klass.included_modules.include?(IOStream), "Not in #{klass}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
4
|
+
include IOStream
|
12
5
|
context "A file" do
|
13
6
|
setup do
|
14
7
|
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
@@ -21,7 +14,7 @@ class IOStreamTest < Test::Unit::TestCase
|
|
21
14
|
context "and given a String" do
|
22
15
|
setup do
|
23
16
|
FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
|
24
|
-
assert @result = @file
|
17
|
+
assert @result = stream_to(@file, File.join(ROOT, 'tmp', 'iostream.string.test'))
|
25
18
|
end
|
26
19
|
|
27
20
|
should "return a File" do
|
@@ -38,7 +31,7 @@ class IOStreamTest < Test::Unit::TestCase
|
|
38
31
|
setup do
|
39
32
|
tempfile = Tempfile.new('iostream.test')
|
40
33
|
tempfile.binmode
|
41
|
-
assert @result = @file
|
34
|
+
assert @result = stream_to(@file, tempfile)
|
42
35
|
end
|
43
36
|
|
44
37
|
should "return a Tempfile" do
|
@@ -53,9 +46,9 @@ class IOStreamTest < Test::Unit::TestCase
|
|
53
46
|
|
54
47
|
end
|
55
48
|
|
56
|
-
context "that is
|
49
|
+
context "that is converted #to_tempfile" do
|
57
50
|
setup do
|
58
|
-
assert @tempfile = @file
|
51
|
+
assert @tempfile = to_tempfile(@file)
|
59
52
|
end
|
60
53
|
|
61
54
|
should "convert it to a Paperclip Tempfile" do
|
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'test/helper'
|
1
|
+
require './test/helper'
|
2
2
|
|
3
3
|
class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
4
4
|
context "validate_attachment_content_type" do
|
5
5
|
setup do
|
6
6
|
reset_table("dummies") do |d|
|
7
|
+
d.string :title
|
7
8
|
d.string :avatar_file_name
|
8
9
|
d.string :avatar_content_type
|
9
10
|
end
|
@@ -33,5 +34,14 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
33
34
|
|
34
35
|
should_accept_dummy_class
|
35
36
|
end
|
37
|
+
|
38
|
+
context "given a class with other validations but matching types" do
|
39
|
+
setup do
|
40
|
+
@dummy_class.validates_presence_of :title
|
41
|
+
@dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
|
42
|
+
end
|
43
|
+
|
44
|
+
should_accept_dummy_class
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
data/test/paperclip_test.rb
CHANGED
@@ -1,95 +1,62 @@
|
|
1
|
-
require 'test/helper'
|
1
|
+
require './test/helper'
|
2
2
|
|
3
3
|
class PaperclipTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "Calling Paperclip.run with #{path} specified" do
|
6
|
-
setup do
|
7
|
-
Paperclip.options[:image_magick_path] = nil
|
8
|
-
Paperclip.options[:command_path] = nil
|
9
|
-
Paperclip.options[path] = "/usr/bin"
|
10
|
-
end
|
11
|
-
|
12
|
-
should "return the expected path for path_for_command" do
|
13
|
-
assert_equal "/usr/bin/convert", Paperclip.path_for_command("convert")
|
14
|
-
end
|
15
|
-
|
16
|
-
should "execute the right command" do
|
17
|
-
Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
|
18
|
-
Paperclip.expects(:bit_bucket).returns("/dev/null")
|
19
|
-
Paperclip.expects(:"`").with("/usr/bin/convert 'one.jpg' 'two.jpg' 2>/dev/null")
|
20
|
-
Paperclip.run("convert", "one.jpg", "two.jpg")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "Calling Paperclip.run with no path specified" do
|
4
|
+
context "Calling Paperclip.run" do
|
26
5
|
setup do
|
27
6
|
Paperclip.options[:image_magick_path] = nil
|
28
7
|
Paperclip.options[:command_path] = nil
|
8
|
+
Paperclip::CommandLine.stubs(:'`')
|
29
9
|
end
|
30
10
|
|
31
|
-
should "
|
32
|
-
|
11
|
+
should "execute the right command with :image_magick_path" do
|
12
|
+
Paperclip.options[:image_magick_path] = "/usr/bin"
|
13
|
+
Paperclip.expects(:log).with(includes('[DEPRECATION]'))
|
14
|
+
Paperclip.expects(:log).with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
|
15
|
+
Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
|
16
|
+
Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
|
33
17
|
end
|
34
18
|
|
35
|
-
should "execute the right command" do
|
36
|
-
Paperclip.
|
37
|
-
Paperclip.expects(:
|
38
|
-
Paperclip.
|
39
|
-
Paperclip.run("convert", "one.jpg", "two.jpg")
|
19
|
+
should "execute the right command with :command_path" do
|
20
|
+
Paperclip.options[:command_path] = "/usr/bin"
|
21
|
+
Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
|
22
|
+
Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
|
40
23
|
end
|
41
|
-
end
|
42
24
|
|
43
|
-
|
44
|
-
|
45
|
-
Paperclip.
|
46
|
-
Paperclip.options[:command_path] = nil
|
47
|
-
Paperclip.stubs(:bit_bucket).returns("/dev/null")
|
48
|
-
Paperclip.expects(:log).with("this 'is the command' 2>/dev/null")
|
49
|
-
Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null")
|
50
|
-
Paperclip.options[:log_command] = true
|
51
|
-
Paperclip.run("this","is the command")
|
25
|
+
should "execute the right command with no path" do
|
26
|
+
Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{convert ['"]one.jpg['"] ['"]two.jpg['"]}))
|
27
|
+
Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
|
52
28
|
end
|
53
29
|
|
54
|
-
should "
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
Paperclip.options[:log_command] = false
|
61
|
-
Paperclip.run("this","is the command")
|
30
|
+
should "tell you the command isn't there if the shell returns 127" do
|
31
|
+
with_exitstatus_returning(127) do
|
32
|
+
assert_raises(Paperclip::CommandNotFoundError) do
|
33
|
+
Paperclip.run("command")
|
34
|
+
end
|
35
|
+
end
|
62
36
|
end
|
63
|
-
end
|
64
37
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Paperclip.options[:swallow_stderr] = false
|
70
|
-
Paperclip.expects(:"`").with(%q[this 'is' 'jack'\''s' '`command`' 'line!'])
|
71
|
-
Paperclip.run("this", "is", "jack's", "`command`", "line!")
|
72
|
-
end
|
73
|
-
|
74
|
-
context "Paperclip.bit_bucket" do
|
75
|
-
context "on systems without /dev/null" do
|
76
|
-
setup do
|
77
|
-
File.expects(:exists?).with("/dev/null").returns(false)
|
78
|
-
end
|
79
|
-
|
80
|
-
should "return 'NUL'" do
|
81
|
-
assert_equal "NUL", Paperclip.bit_bucket
|
38
|
+
should "tell you the command isn't there if an ENOENT is raised" do
|
39
|
+
assert_raises(Paperclip::CommandNotFoundError) do
|
40
|
+
Paperclip::CommandLine.stubs(:"`").raises(Errno::ENOENT)
|
41
|
+
Paperclip.run("command")
|
82
42
|
end
|
83
43
|
end
|
44
|
+
end
|
84
45
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
46
|
+
context "Paperclip.each_instance_with_attachment" do
|
47
|
+
setup do
|
48
|
+
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
|
49
|
+
d1 = Dummy.create(:avatar => @file)
|
50
|
+
d2 = Dummy.create
|
51
|
+
d3 = Dummy.create(:avatar => @file)
|
52
|
+
@expected = [d1, d3]
|
53
|
+
end
|
54
|
+
should "yield every instance of a model that has an attachment" do
|
55
|
+
actual = []
|
56
|
+
Paperclip.each_instance_with_attachment("Dummy", "avatar") do |instance|
|
57
|
+
actual << instance
|
92
58
|
end
|
59
|
+
assert_same_elements @expected, actual
|
93
60
|
end
|
94
61
|
end
|
95
62
|
|
@@ -132,7 +99,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
132
99
|
should "not assign the avatar on mass-set" do
|
133
100
|
@dummy.attributes = { :other => "I'm set!",
|
134
101
|
:avatar => @file }
|
135
|
-
|
102
|
+
|
136
103
|
assert_equal "I'm set!", @dummy.other
|
137
104
|
assert ! @dummy.avatar?
|
138
105
|
end
|
@@ -140,7 +107,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
140
107
|
should "still allow assigment on normal set" do
|
141
108
|
@dummy.other = "I'm set!"
|
142
109
|
@dummy.avatar = @file
|
143
|
-
|
110
|
+
|
144
111
|
assert_equal "I'm set!", @dummy.other
|
145
112
|
assert @dummy.avatar?
|
146
113
|
end
|
@@ -243,9 +210,16 @@ class PaperclipTest < Test::Unit::TestCase
|
|
243
210
|
end
|
244
211
|
end
|
245
212
|
|
213
|
+
should "not have Attachment in the ActiveRecord::Base namespace" do
|
214
|
+
assert_raises(NameError) do
|
215
|
+
ActiveRecord::Base::Attachment
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
246
219
|
def self.should_validate validation, options, valid_file, invalid_file
|
247
220
|
context "with #{validation} validation and #{options.inspect} options" do
|
248
221
|
setup do
|
222
|
+
rebuild_class
|
249
223
|
Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
|
250
224
|
@dummy = Dummy.new
|
251
225
|
end
|
@@ -260,7 +234,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
260
234
|
end
|
261
235
|
else
|
262
236
|
should "not have an error on the attachment" do
|
263
|
-
assert @dummy.errors
|
237
|
+
assert @dummy.errors.blank?, @dummy.errors.full_messages.join(", ")
|
264
238
|
end
|
265
239
|
end
|
266
240
|
end
|
@@ -295,10 +269,10 @@ class PaperclipTest < Test::Unit::TestCase
|
|
295
269
|
validation, options, valid_file, invalid_file = args
|
296
270
|
valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb")
|
297
271
|
invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb")
|
298
|
-
|
272
|
+
|
299
273
|
should_validate validation, options, valid_file, invalid_file
|
300
274
|
end
|
301
|
-
|
275
|
+
|
302
276
|
context "with size validation and less_than 10240 option" do
|
303
277
|
context "and assigned an invalid file" do
|
304
278
|
setup do
|
@@ -307,9 +281,9 @@ class PaperclipTest < Test::Unit::TestCase
|
|
307
281
|
@dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb")
|
308
282
|
@dummy.valid?
|
309
283
|
end
|
310
|
-
|
284
|
+
|
311
285
|
should "have a file size min/max error message" do
|
312
|
-
assert @dummy.errors[:avatar_file_size].any?{|
|
286
|
+
assert [@dummy.errors[:avatar_file_size]].flatten.any?{|error| error =~ %r/between 0 and 10240 bytes/ }
|
313
287
|
end
|
314
288
|
end
|
315
289
|
end
|
data/test/processor_test.rb
CHANGED