beaucollins-paperclip 2.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +26 -0
- data/README.rdoc +172 -0
- data/Rakefile +77 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +1 -0
- data/lib/paperclip.rb +318 -0
- data/lib/paperclip/attachment.rb +404 -0
- data/lib/paperclip/callback_compatability.rb +33 -0
- data/lib/paperclip/geometry.rb +115 -0
- data/lib/paperclip/iostream.rb +58 -0
- data/lib/paperclip/matchers.rb +4 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +49 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +66 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +48 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +83 -0
- data/lib/paperclip/processor.rb +48 -0
- data/lib/paperclip/storage.rb +236 -0
- data/lib/paperclip/thumbnail.rb +70 -0
- data/lib/paperclip/upfile.rb +48 -0
- data/shoulda_macros/paperclip.rb +68 -0
- data/tasks/paperclip_tasks.rake +79 -0
- data/test/attachment_test.rb +742 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/text.txt +0 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/geometry_test.rb +168 -0
- data/test/helper.rb +82 -0
- data/test/integration_test.rb +481 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +21 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +30 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +21 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +50 -0
- data/test/paperclip_test.rb +233 -0
- data/test/processor_test.rb +10 -0
- data/test/storage_test.rb +277 -0
- data/test/thumbnail_test.rb +177 -0
- metadata +131 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class ThumbnailTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A Paperclip Tempfile" do
|
6
|
+
setup do
|
7
|
+
@tempfile = Paperclip::Tempfile.new("file.jpg")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "have its path contain a real extension" do
|
11
|
+
assert_equal ".jpg", File.extname(@tempfile.path)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be a real Tempfile" do
|
15
|
+
assert @tempfile.is_a?(::Tempfile)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Another Paperclip Tempfile" do
|
20
|
+
setup do
|
21
|
+
@tempfile = Paperclip::Tempfile.new("file")
|
22
|
+
end
|
23
|
+
|
24
|
+
should "not have an extension if not given one" do
|
25
|
+
assert_equal "", File.extname(@tempfile.path)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "still be a real Tempfile" do
|
29
|
+
assert @tempfile.is_a?(::Tempfile)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "An image" do
|
34
|
+
setup do
|
35
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
36
|
+
end
|
37
|
+
|
38
|
+
teardown { @file.close }
|
39
|
+
|
40
|
+
[["600x600>", "434x66"],
|
41
|
+
["400x400>", "400x61"],
|
42
|
+
["32x32<", "434x66"]
|
43
|
+
].each do |args|
|
44
|
+
context "being thumbnailed with a geometry of #{args[0]}" do
|
45
|
+
setup do
|
46
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
|
47
|
+
end
|
48
|
+
|
49
|
+
should "start with dimensions of 434x66" do
|
50
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
51
|
+
assert_equal "434x66", `#{cmd}`.chomp
|
52
|
+
end
|
53
|
+
|
54
|
+
should "report the correct target geometry" do
|
55
|
+
assert_equal args[0], @thumb.target_geometry.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when made" do
|
59
|
+
setup do
|
60
|
+
@thumb_result = @thumb.make
|
61
|
+
end
|
62
|
+
|
63
|
+
should "be the size we expect it to be" do
|
64
|
+
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
|
65
|
+
assert_equal args[1], `#{cmd}`.chomp
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "being thumbnailed at 100x50 with cropping" do
|
72
|
+
setup do
|
73
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
|
74
|
+
end
|
75
|
+
|
76
|
+
should "report its correct current and target geometries" do
|
77
|
+
assert_equal "100x50#", @thumb.target_geometry.to_s
|
78
|
+
assert_equal "434x66", @thumb.current_geometry.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
should "report its correct format" do
|
82
|
+
assert_nil @thumb.format
|
83
|
+
end
|
84
|
+
|
85
|
+
should "have whiny turned on by default" do
|
86
|
+
assert @thumb.whiny
|
87
|
+
end
|
88
|
+
|
89
|
+
should "have convert_options set to nil by default" do
|
90
|
+
assert_equal nil, @thumb.convert_options
|
91
|
+
end
|
92
|
+
|
93
|
+
should "send the right command to convert when sent #make" do
|
94
|
+
Paperclip.expects(:"`").with do |arg|
|
95
|
+
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
|
96
|
+
end
|
97
|
+
@thumb.make
|
98
|
+
end
|
99
|
+
|
100
|
+
should "create the thumbnail when sent #make" do
|
101
|
+
dst = @thumb.make
|
102
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "being thumbnailed with convert options set" do
|
107
|
+
setup do
|
108
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
109
|
+
:geometry => "100x50#",
|
110
|
+
:convert_options => "-strip -depth 8")
|
111
|
+
end
|
112
|
+
|
113
|
+
should "have convert_options value set" do
|
114
|
+
assert_equal "-strip -depth 8", @thumb.convert_options
|
115
|
+
end
|
116
|
+
|
117
|
+
should "send the right command to convert when sent #make" do
|
118
|
+
Paperclip.expects(:"`").with do |arg|
|
119
|
+
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"}
|
120
|
+
end
|
121
|
+
@thumb.make
|
122
|
+
end
|
123
|
+
|
124
|
+
should "create the thumbnail when sent #make" do
|
125
|
+
dst = @thumb.make
|
126
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
127
|
+
end
|
128
|
+
|
129
|
+
context "redefined to have bad convert_options setting" do
|
130
|
+
setup do
|
131
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
132
|
+
:geometry => "100x50#",
|
133
|
+
:convert_options => "-this-aint-no-option")
|
134
|
+
end
|
135
|
+
|
136
|
+
should "error when trying to create the thumbnail" do
|
137
|
+
assert_raises(Paperclip::PaperclipError) do
|
138
|
+
@thumb.make
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "A multipage PDF" do
|
146
|
+
setup do
|
147
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
|
148
|
+
end
|
149
|
+
|
150
|
+
teardown { @file.close }
|
151
|
+
|
152
|
+
should "start with two pages with dimensions 612x792" do
|
153
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
154
|
+
assert_equal "612x792"*2, `#{cmd}`.chomp
|
155
|
+
end
|
156
|
+
|
157
|
+
context "being thumbnailed at 100x100 with cropping" do
|
158
|
+
setup do
|
159
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
|
160
|
+
end
|
161
|
+
|
162
|
+
should "report its correct current and target geometries" do
|
163
|
+
assert_equal "100x100#", @thumb.target_geometry.to_s
|
164
|
+
assert_equal "612x792", @thumb.current_geometry.to_s
|
165
|
+
end
|
166
|
+
|
167
|
+
should "report its correct format" do
|
168
|
+
assert_equal :png, @thumb.format
|
169
|
+
end
|
170
|
+
|
171
|
+
should "create the thumbnail when sent #make" do
|
172
|
+
dst = @thumb.make
|
173
|
+
assert_match /100x100/, `identify "#{dst.path}"`
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beaucollins-paperclip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Yurek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: right_aws
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thoughtbot-shoulda
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description:
|
46
|
+
email: jyurek@thoughtbot.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
|
+
files:
|
54
|
+
- README.rdoc
|
55
|
+
- LICENSE
|
56
|
+
- Rakefile
|
57
|
+
- init.rb
|
58
|
+
- generators/paperclip
|
59
|
+
- generators/paperclip/paperclip_generator.rb
|
60
|
+
- generators/paperclip/templates
|
61
|
+
- generators/paperclip/templates/paperclip_migration.rb.erb
|
62
|
+
- generators/paperclip/USAGE
|
63
|
+
- lib/paperclip
|
64
|
+
- lib/paperclip/attachment.rb
|
65
|
+
- lib/paperclip/callback_compatability.rb
|
66
|
+
- lib/paperclip/geometry.rb
|
67
|
+
- lib/paperclip/iostream.rb
|
68
|
+
- lib/paperclip/matchers
|
69
|
+
- lib/paperclip/matchers/have_attached_file_matcher.rb
|
70
|
+
- lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
|
71
|
+
- lib/paperclip/matchers/validate_attachment_presence_matcher.rb
|
72
|
+
- lib/paperclip/matchers/validate_attachment_size_matcher.rb
|
73
|
+
- lib/paperclip/matchers.rb
|
74
|
+
- lib/paperclip/processor.rb
|
75
|
+
- lib/paperclip/storage.rb
|
76
|
+
- lib/paperclip/thumbnail.rb
|
77
|
+
- lib/paperclip/upfile.rb
|
78
|
+
- lib/paperclip.rb
|
79
|
+
- tasks/paperclip_tasks.rake
|
80
|
+
- test/attachment_test.rb
|
81
|
+
- test/database.yml
|
82
|
+
- test/fixtures
|
83
|
+
- test/fixtures/12k.png
|
84
|
+
- test/fixtures/50x50.png
|
85
|
+
- test/fixtures/5k.png
|
86
|
+
- test/fixtures/bad.png
|
87
|
+
- test/fixtures/text.txt
|
88
|
+
- test/fixtures/twopage.pdf
|
89
|
+
- test/geometry_test.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/integration_test.rb
|
92
|
+
- test/iostream_test.rb
|
93
|
+
- test/matchers
|
94
|
+
- test/matchers/have_attached_file_matcher_test.rb
|
95
|
+
- test/matchers/validate_attachment_content_type_matcher_test.rb
|
96
|
+
- test/matchers/validate_attachment_presence_matcher_test.rb
|
97
|
+
- test/matchers/validate_attachment_size_matcher_test.rb
|
98
|
+
- test/paperclip_test.rb
|
99
|
+
- test/processor_test.rb
|
100
|
+
- test/storage_test.rb
|
101
|
+
- test/thumbnail_test.rb
|
102
|
+
- shoulda_macros/paperclip.rb
|
103
|
+
has_rdoc: true
|
104
|
+
homepage: http://www.thoughtbot.com/projects/paperclip
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options:
|
107
|
+
- --line-numbers
|
108
|
+
- --inline-source
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: "0"
|
116
|
+
version:
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
version:
|
123
|
+
requirements:
|
124
|
+
- ImageMagick
|
125
|
+
rubyforge_project: paperclip
|
126
|
+
rubygems_version: 1.2.0
|
127
|
+
signing_key:
|
128
|
+
specification_version: 2
|
129
|
+
summary: File attachments as attributes for ActiveRecord. Forked to allow background processing.
|
130
|
+
test_files: []
|
131
|
+
|