thoughtbot-paperclip 2.2.5 → 2.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paperclip/attachment.rb +18 -25
- data/lib/paperclip/storage.rb +3 -3
- data/lib/paperclip.rb +1 -1
- data/shoulda_macros/paperclip.rb +1 -1
- data/test/attachment_test.rb +0 -30
- data/test/helper.rb +0 -1
- data/test/matchers/have_attached_file_matcher_test.rb +1 -1
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +1 -1
- data/test/matchers/validate_attachment_presence_matcher_test.rb +1 -1
- data/test/matchers/validate_attachment_size_matcher_test.rb +2 -2
- metadata +5 -2
data/lib/paperclip/attachment.rb
CHANGED
@@ -191,31 +191,24 @@ module Paperclip
|
|
191
191
|
# necessary.
|
192
192
|
def self.interpolations
|
193
193
|
@interpolations ||= {
|
194
|
-
:rails_root
|
195
|
-
:rails_env
|
196
|
-
:class
|
197
|
-
|
198
|
-
|
199
|
-
:basename
|
200
|
-
|
201
|
-
|
202
|
-
:extension
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
:id
|
207
|
-
:id_partition
|
208
|
-
|
209
|
-
|
210
|
-
:attachment
|
211
|
-
:style
|
212
|
-
:relative_root => lambda do |attachment,style|
|
213
|
-
if ActionController::AbstractRequest.respond_to?(:relative_url_root)
|
214
|
-
ActionController::AbstractRequest.relative_url_root
|
215
|
-
elsif ActionController::Base.respond_to?(:relative_url_root)
|
216
|
-
ActionController::Base.relative_url_root
|
217
|
-
end
|
218
|
-
end
|
194
|
+
:rails_root => lambda{|attachment,style| RAILS_ROOT },
|
195
|
+
:rails_env => lambda{|attachment,style| RAILS_ENV },
|
196
|
+
:class => lambda do |attachment,style|
|
197
|
+
attachment.instance.class.name.underscore.pluralize
|
198
|
+
end,
|
199
|
+
:basename => lambda do |attachment,style|
|
200
|
+
attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, "")
|
201
|
+
end,
|
202
|
+
:extension => lambda do |attachment,style|
|
203
|
+
((style = attachment.styles[style]) && style[:format]) ||
|
204
|
+
File.extname(attachment.original_filename).gsub(/^\.+/, "")
|
205
|
+
end,
|
206
|
+
:id => lambda{|attachment,style| attachment.instance.id },
|
207
|
+
:id_partition => lambda do |attachment, style|
|
208
|
+
("%09d" % attachment.instance.id).scan(/\d{3}/).join("/")
|
209
|
+
end,
|
210
|
+
:attachment => lambda{|attachment,style| attachment.name.to_s.downcase.pluralize },
|
211
|
+
:style => lambda{|attachment,style| style || attachment.default_style },
|
219
212
|
}
|
220
213
|
end
|
221
214
|
|
data/lib/paperclip/storage.rb
CHANGED
@@ -206,11 +206,11 @@ module Paperclip
|
|
206
206
|
|
207
207
|
def find_credentials creds
|
208
208
|
case creds
|
209
|
-
when File
|
209
|
+
when File
|
210
210
|
YAML.load_file(creds.path)
|
211
|
-
when String
|
211
|
+
when String
|
212
212
|
YAML.load_file(creds)
|
213
|
-
when Hash
|
213
|
+
when Hash
|
214
214
|
creds
|
215
215
|
else
|
216
216
|
raise ArgumentError, "Credentials are not a path, file, or hash."
|
data/lib/paperclip.rb
CHANGED
data/shoulda_macros/paperclip.rb
CHANGED
@@ -9,6 +9,7 @@ module Paperclip
|
|
9
9
|
# you're testing (that is, UserTest is the test for the User model), and
|
10
10
|
# will load that class for testing purposes.
|
11
11
|
module Shoulda
|
12
|
+
include Matchers
|
12
13
|
# This will test whether you have defined your attachment correctly by
|
13
14
|
# checking for all the required fields exist after the definition of the
|
14
15
|
# attachment.
|
@@ -64,5 +65,4 @@ end
|
|
64
65
|
|
65
66
|
class Test::Unit::TestCase #:nodoc:
|
66
67
|
extend Paperclip::Shoulda
|
67
|
-
include Paperclip::Shoulda::Matchers
|
68
68
|
end
|
data/test/attachment_test.rb
CHANGED
@@ -106,36 +106,6 @@ class AttachmentTest < Test::Unit::TestCase
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
context "An attachment with a :relative_root interpolation" do
|
110
|
-
setup do
|
111
|
-
rebuild_model :url => ":relative_root/:id.png"
|
112
|
-
@dummy = Dummy.new
|
113
|
-
@dummy.stubs(:id).returns(1024)
|
114
|
-
@dummy.avatar = StringIO.new(".")
|
115
|
-
|
116
|
-
ActionController::Base.stubs(:respond_to?).with(:relative_url_root).returns(false)
|
117
|
-
ActionController::Base.stubs(:relative_url_root).returns("/base")
|
118
|
-
ActionController::AbstractRequest.stubs(:respond_to?).with(:relative_url_root).returns(false)
|
119
|
-
ActionController::AbstractRequest.stubs(:relative_url_root).returns("/request")
|
120
|
-
end
|
121
|
-
|
122
|
-
should "return the proper path when the path is nil" do
|
123
|
-
assert_equal "/1024.png", @dummy.avatar.url(:original, false)
|
124
|
-
end
|
125
|
-
|
126
|
-
should "return the proper path when using Rails < 2.1" do
|
127
|
-
ActionController::AbstractRequest.expects(:respond_to?).with(:relative_url_root).returns(true)
|
128
|
-
ActionController::AbstractRequest.expects(:relative_url_root).returns("/request")
|
129
|
-
assert_equal "/request/1024.png", @dummy.avatar.url(:original, false)
|
130
|
-
end
|
131
|
-
|
132
|
-
should "return the proper path when using Rails >= 2.1" do
|
133
|
-
ActionController::Base.expects(:respond_to?).with(:relative_url_root).returns(true)
|
134
|
-
ActionController::Base.expects(:relative_url_root).returns("/base")
|
135
|
-
assert_equal "/base/1024.png", @dummy.avatar.url(:original, false)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
109
|
context "An attachment with :convert_options" do
|
140
110
|
setup do
|
141
111
|
rebuild_model :styles => {
|
data/test/helper.rb
CHANGED
@@ -5,7 +5,7 @@ class HaveAttachedFileMatcherTest < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
@dummy_class = reset_class "Dummy"
|
7
7
|
reset_table "dummies"
|
8
|
-
@matcher = have_attached_file(:avatar)
|
8
|
+
@matcher = self.class.have_attached_file(:avatar)
|
9
9
|
end
|
10
10
|
|
11
11
|
should "reject a class with no attachment" do
|
@@ -8,7 +8,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
@dummy_class = reset_class "Dummy"
|
10
10
|
@dummy_class.has_attached_file :avatar
|
11
|
-
@matcher = validate_attachment_content_type(:avatar).
|
11
|
+
@matcher = self.class.validate_attachment_content_type(:avatar).
|
12
12
|
allowing(%w(image/png image/jpeg)).
|
13
13
|
rejecting(%w(audio/mp3 application/octet-stream))
|
14
14
|
end
|
@@ -6,7 +6,7 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
|
|
6
6
|
reset_table("dummies"){|d| d.string :avatar_file_name }
|
7
7
|
@dummy_class = reset_class "Dummy"
|
8
8
|
@dummy_class.has_attached_file :avatar
|
9
|
-
@matcher = validate_attachment_presence(:avatar)
|
9
|
+
@matcher = self.class.validate_attachment_presence(:avatar)
|
10
10
|
end
|
11
11
|
|
12
12
|
should "reject a class with no validation" do
|
@@ -11,7 +11,7 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context "of limited size" do
|
14
|
-
setup{ @matcher = validate_attachment_size(:avatar).in(256..1024) }
|
14
|
+
setup{ @matcher = self.class.validate_attachment_size(:avatar).in(256..1024) }
|
15
15
|
|
16
16
|
should "reject a class with no validation" do
|
17
17
|
assert_rejects @matcher, @dummy_class
|
@@ -34,7 +34,7 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context "validates_attachment_size with infinite range" do
|
37
|
-
setup{ @matcher = validate_attachment_size(:avatar) }
|
37
|
+
setup{ @matcher = self.class.validate_attachment_size(:avatar) }
|
38
38
|
|
39
39
|
should "accept a class with an upper limit" do
|
40
40
|
@dummy_class.validates_attachment_size :avatar, :less_than => 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thoughtbot-paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Yurek
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-17 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: right_aws
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -23,6 +24,7 @@ dependencies:
|
|
23
24
|
version:
|
24
25
|
- !ruby/object:Gem::Dependency
|
25
26
|
name: thoughtbot-shoulda
|
27
|
+
type: :development
|
26
28
|
version_requirement:
|
27
29
|
version_requirements: !ruby/object:Gem::Requirement
|
28
30
|
requirements:
|
@@ -32,6 +34,7 @@ dependencies:
|
|
32
34
|
version:
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
36
|
name: mocha
|
37
|
+
type: :development
|
35
38
|
version_requirement:
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|