paperclip-v2_7-patched-ruby-1_8_6 2.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +14 -0
  4. data/Appraisals +20 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE +26 -0
  8. data/NEWS +69 -0
  9. data/README.md +444 -0
  10. data/Rakefile +41 -0
  11. data/cucumber/paperclip_steps.rb +6 -0
  12. data/features/basic_integration.feature +48 -0
  13. data/features/rake_tasks.feature +68 -0
  14. data/features/step_definitions/attachment_steps.rb +65 -0
  15. data/features/step_definitions/html_steps.rb +15 -0
  16. data/features/step_definitions/rails_steps.rb +193 -0
  17. data/features/step_definitions/s3_steps.rb +14 -0
  18. data/features/step_definitions/web_steps.rb +209 -0
  19. data/features/support/env.rb +8 -0
  20. data/features/support/fakeweb.rb +3 -0
  21. data/features/support/fixtures/.boot_config.rb.swo +0 -0
  22. data/features/support/fixtures/boot_config.txt +15 -0
  23. data/features/support/fixtures/gemfile.txt +5 -0
  24. data/features/support/fixtures/preinitializer.txt +20 -0
  25. data/features/support/paths.rb +28 -0
  26. data/features/support/rails.rb +46 -0
  27. data/features/support/selectors.rb +19 -0
  28. data/gemfiles/rails2.gemfile +9 -0
  29. data/gemfiles/rails3.gemfile +9 -0
  30. data/gemfiles/rails3_1.gemfile +9 -0
  31. data/gemfiles/rails3_2.gemfile +9 -0
  32. data/generators/paperclip/USAGE +5 -0
  33. data/generators/paperclip/paperclip_generator.rb +27 -0
  34. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  35. data/init.rb +4 -0
  36. data/lib/generators/paperclip/USAGE +8 -0
  37. data/lib/generators/paperclip/paperclip_generator.rb +33 -0
  38. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  39. data/lib/paperclip.rb +493 -0
  40. data/lib/paperclip/attachment.rb +491 -0
  41. data/lib/paperclip/attachment_options.rb +10 -0
  42. data/lib/paperclip/callback_compatibility.rb +61 -0
  43. data/lib/paperclip/geometry.rb +120 -0
  44. data/lib/paperclip/interpolations.rb +174 -0
  45. data/lib/paperclip/iostream.rb +45 -0
  46. data/lib/paperclip/matchers.rb +64 -0
  47. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  48. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
  49. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  50. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  51. data/lib/paperclip/missing_attachment_styles.rb +87 -0
  52. data/lib/paperclip/processor.rb +58 -0
  53. data/lib/paperclip/railtie.rb +35 -0
  54. data/lib/paperclip/schema.rb +39 -0
  55. data/lib/paperclip/storage.rb +3 -0
  56. data/lib/paperclip/storage/filesystem.rb +81 -0
  57. data/lib/paperclip/storage/fog.rb +191 -0
  58. data/lib/paperclip/storage/s3.rb +351 -0
  59. data/lib/paperclip/style.rb +103 -0
  60. data/lib/paperclip/thumbnail.rb +105 -0
  61. data/lib/paperclip/upfile.rb +64 -0
  62. data/lib/paperclip/url_generator.rb +64 -0
  63. data/lib/paperclip/version.rb +3 -0
  64. data/lib/tasks/paperclip.rake +101 -0
  65. data/paperclip.gemspec +41 -0
  66. data/rails/init.rb +2 -0
  67. data/shoulda_macros/paperclip.rb +124 -0
  68. data/test/attachment_options_test.rb +40 -0
  69. data/test/attachment_test.rb +1211 -0
  70. data/test/database.yml +4 -0
  71. data/test/fixtures/12k.png +0 -0
  72. data/test/fixtures/50x50.png +0 -0
  73. data/test/fixtures/5k.png +0 -0
  74. data/test/fixtures/animated.gif +0 -0
  75. data/test/fixtures/bad.png +1 -0
  76. data/test/fixtures/fog.yml +8 -0
  77. data/test/fixtures/s3.yml +8 -0
  78. data/test/fixtures/spaced file.png +0 -0
  79. data/test/fixtures/text.txt +1 -0
  80. data/test/fixtures/twopage.pdf +0 -0
  81. data/test/fixtures/uppercase.PNG +0 -0
  82. data/test/geometry_test.rb +206 -0
  83. data/test/helper.rb +181 -0
  84. data/test/integration_test.rb +652 -0
  85. data/test/interpolations_test.rb +219 -0
  86. data/test/iostream_test.rb +71 -0
  87. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  88. data/test/matchers/validate_attachment_content_type_matcher_test.rb +110 -0
  89. data/test/matchers/validate_attachment_presence_matcher_test.rb +47 -0
  90. data/test/matchers/validate_attachment_size_matcher_test.rb +72 -0
  91. data/test/paperclip_missing_attachment_styles_test.rb +96 -0
  92. data/test/paperclip_test.rb +409 -0
  93. data/test/processor_test.rb +10 -0
  94. data/test/schema_test.rb +98 -0
  95. data/test/storage/filesystem_test.rb +62 -0
  96. data/test/storage/fog_test.rb +280 -0
  97. data/test/storage/s3_live_test.rb +138 -0
  98. data/test/storage/s3_test.rb +1093 -0
  99. data/test/style_test.rb +215 -0
  100. data/test/support/mock_attachment.rb +22 -0
  101. data/test/support/mock_interpolator.rb +24 -0
  102. data/test/support/mock_model.rb +2 -0
  103. data/test/support/mock_url_generator_builder.rb +27 -0
  104. data/test/thumbnail_test.rb +396 -0
  105. data/test/upfile_test.rb +53 -0
  106. data/test/url_generator_test.rb +187 -0
  107. metadata +374 -0
@@ -0,0 +1,219 @@
1
+ require './test/helper'
2
+
3
+ class InterpolationsTest < Test::Unit::TestCase
4
+ should "return all methods but the infrastructure when sent #all" do
5
+ methods = Paperclip::Interpolations.all
6
+ assert ! methods.include?(:[])
7
+ assert ! methods.include?(:[]=)
8
+ assert ! methods.include?(:all)
9
+ methods.each do |m|
10
+ assert Paperclip::Interpolations.respond_to?(m)
11
+ end
12
+ end
13
+
14
+ should "return the Rails.root" do
15
+ assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style)
16
+ end
17
+
18
+ should "return the Rails.env" do
19
+ assert_equal Rails.env, Paperclip::Interpolations.rails_env(:attachment, :style)
20
+ end
21
+
22
+ should "return the class of the Interpolations module when called with no params" do
23
+ assert_equal Module, Paperclip::Interpolations.class
24
+ end
25
+
26
+ should "return the class of the instance" do
27
+ attachment = mock
28
+ attachment.expects(:instance).returns(attachment)
29
+ attachment.expects(:class).returns("Thing")
30
+ assert_equal "things", Paperclip::Interpolations.class(attachment, :style)
31
+ end
32
+
33
+ should "return the basename of the file" do
34
+ attachment = mock
35
+ attachment.expects(:original_filename).returns("one.jpg").times(2)
36
+ assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
37
+ end
38
+
39
+ should "return the extension of the file" do
40
+ attachment = mock
41
+ attachment.expects(:original_filename).returns("one.jpg")
42
+ attachment.expects(:styles).returns({})
43
+ assert_equal "jpg", Paperclip::Interpolations.extension(attachment, :style)
44
+ end
45
+
46
+ should "return the extension of the file as the format if defined in the style" do
47
+ attachment = mock
48
+ attachment.expects(:original_filename).never
49
+ attachment.expects(:styles).twice.returns({:style => {:format => "png"}})
50
+
51
+ [:style, 'style'].each do |style|
52
+ assert_equal "png", Paperclip::Interpolations.extension(attachment, style)
53
+ end
54
+ end
55
+
56
+ should "return the extension of the file based on the content type" do
57
+ attachment = mock
58
+ attachment.expects(:content_type).returns('image/jpeg')
59
+ interpolations = Paperclip::Interpolations
60
+ interpolations.expects(:extension).returns('random')
61
+ assert_equal "jpeg", interpolations.content_type_extension(attachment, :style)
62
+ end
63
+
64
+ should "return the original extension of the file if it matches a content type extension" do
65
+ attachment = mock
66
+ attachment.expects(:content_type).returns('image/jpeg')
67
+ interpolations = Paperclip::Interpolations
68
+ interpolations.expects(:extension).returns('jpe')
69
+ assert_equal "jpe", interpolations.content_type_extension(attachment, :style)
70
+ end
71
+
72
+ should "return the latter half of the content type of the extension if no match found" do
73
+ attachment = mock
74
+ attachment.expects(:content_type).at_least_once().returns('not/found')
75
+ interpolations = Paperclip::Interpolations
76
+ interpolations.expects(:extension).returns('random')
77
+ assert_equal "found", interpolations.content_type_extension(attachment, :style)
78
+ end
79
+
80
+ should "return the #to_param of the attachment" do
81
+ attachment = mock
82
+ attachment.expects(:to_param).returns("23-awesome")
83
+ attachment.expects(:instance).returns(attachment)
84
+ assert_equal "23-awesome", Paperclip::Interpolations.param(attachment, :style)
85
+ end
86
+
87
+ should "return the id of the attachment" do
88
+ attachment = mock
89
+ attachment.expects(:id).returns(23)
90
+ attachment.expects(:instance).returns(attachment)
91
+ assert_equal 23, Paperclip::Interpolations.id(attachment, :style)
92
+ end
93
+
94
+ should "return nil for attachments to new records" do
95
+ attachment = mock
96
+ attachment.expects(:id).returns(nil)
97
+ attachment.expects(:instance).returns(attachment)
98
+ assert_nil Paperclip::Interpolations.id(attachment, :style)
99
+ end
100
+
101
+ should "return the partitioned id of the attachment when the id is an integer" do
102
+ attachment = mock
103
+ attachment.expects(:id).returns(23)
104
+ attachment.expects(:instance).returns(attachment)
105
+ assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
106
+ end
107
+
108
+ should "return the partitioned id of the attachment when the id is a string" do
109
+ attachment = mock
110
+ attachment.expects(:id).returns("32fnj23oio2f")
111
+ attachment.expects(:instance).returns(attachment)
112
+ assert_equal "32f/nj2/3oi", Paperclip::Interpolations.id_partition(attachment, :style)
113
+ end
114
+
115
+ should "return nil for the partitioned id of an attachment to a new record (when the id is nil)" do
116
+ attachment = mock
117
+ attachment.expects(:id).returns(nil)
118
+ attachment.expects(:instance).returns(attachment)
119
+ assert_nil Paperclip::Interpolations.id_partition(attachment, :style)
120
+ end
121
+
122
+ should "return the name of the attachment" do
123
+ attachment = mock
124
+ attachment.expects(:name).returns("file")
125
+ assert_equal "files", Paperclip::Interpolations.attachment(attachment, :style)
126
+ end
127
+
128
+ should "return the style" do
129
+ assert_equal :style, Paperclip::Interpolations.style(:attachment, :style)
130
+ end
131
+
132
+ should "return the default style" do
133
+ attachment = mock
134
+ attachment.expects(:default_style).returns(:default_style)
135
+ assert_equal :default_style, Paperclip::Interpolations.style(attachment, nil)
136
+ end
137
+
138
+ should "reinterpolate :url" do
139
+ attachment = mock
140
+ attachment.expects(:url).with(:style, :timestamp => false, :escape => false).returns("1234")
141
+ assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
142
+ end
143
+
144
+ should "raise if infinite loop detcted reinterpolating :url" do
145
+ attachment = Object.new
146
+ class << attachment
147
+ def url(*args)
148
+ Paperclip::Interpolations.url(self, :style)
149
+ end
150
+ end
151
+ assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
152
+ end
153
+
154
+ should "return the filename as basename.extension" do
155
+ attachment = mock
156
+ attachment.expects(:styles).returns({})
157
+ attachment.expects(:original_filename).returns("one.jpg").times(3)
158
+ assert_equal "one.jpg", Paperclip::Interpolations.filename(attachment, :style)
159
+ end
160
+
161
+ should "return the filename as basename.extension when format supplied" do
162
+ attachment = mock
163
+ attachment.expects(:styles).returns({:style => {:format => :png}})
164
+ attachment.expects(:original_filename).returns("one.jpg").times(2)
165
+ assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style)
166
+ end
167
+
168
+ should "return the filename as basename when extension is blank" do
169
+ attachment = mock
170
+ attachment.stubs(:styles).returns({})
171
+ attachment.stubs(:original_filename).returns("one")
172
+ assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
173
+ end
174
+
175
+ should "return the basename when the extension contains regexp special characters" do
176
+ attachment = mock
177
+ attachment.stubs(:styles).returns({})
178
+ attachment.stubs(:original_filename).returns("one.ab)")
179
+ assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
180
+ end
181
+
182
+ should "return the timestamp" do
183
+ now = Time.now
184
+ zone = 'UTC'
185
+ attachment = mock
186
+ attachment.expects(:instance_read).with(:updated_at).returns(now)
187
+ attachment.expects(:time_zone).returns(zone)
188
+ assert_equal now.in_time_zone(zone).to_s, Paperclip::Interpolations.timestamp(attachment, :style)
189
+ end
190
+
191
+ should "return updated_at" do
192
+ attachment = mock
193
+ seconds_since_epoch = 1234567890
194
+ attachment.expects(:updated_at).returns(seconds_since_epoch)
195
+ assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style)
196
+ end
197
+
198
+ should "return attachment's hash when passing both arguments" do
199
+ attachment = mock
200
+ fake_hash = "a_wicked_secure_hash"
201
+ attachment.expects(:hash_key).returns(fake_hash)
202
+ assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style)
203
+ end
204
+
205
+ should "return Object#hash when passing no argument" do
206
+ attachment = mock
207
+ fake_hash = "a_wicked_secure_hash"
208
+ attachment.expects(:hash_key).never.returns(fake_hash)
209
+ assert_not_equal fake_hash, Paperclip::Interpolations.hash
210
+ end
211
+
212
+ should "call all expected interpolations with the given arguments" do
213
+ Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234)
214
+ Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
215
+ Paperclip::Interpolations.expects(:notreal).never
216
+ value = Paperclip::Interpolations.interpolate(":notreal/:id/:attachment", :attachment, :style)
217
+ assert_equal ":notreal/1234/attachments", value
218
+ end
219
+ end
@@ -0,0 +1,71 @@
1
+ require './test/helper'
2
+
3
+ class IOStreamTest < Test::Unit::TestCase
4
+ include IOStream
5
+ context "A file" do
6
+ setup do
7
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
8
+ end
9
+
10
+ teardown { @file.close }
11
+
12
+ context "that is sent #stream_to" do
13
+
14
+ context "and given a String" do
15
+ setup do
16
+ FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
17
+ assert @result = stream_to(@file, File.join(ROOT, 'tmp', 'iostream.string.test'))
18
+ end
19
+
20
+ should "return a File" do
21
+ assert @result.is_a?(File)
22
+ end
23
+
24
+ should "contain the same data as the original file" do
25
+ @file.rewind; @result.rewind
26
+ assert_equal @file.read, @result.read
27
+ end
28
+ end
29
+
30
+ context "and given a Tempfile" do
31
+ setup do
32
+ tempfile = Tempfile.new('iostream.test')
33
+ tempfile.binmode
34
+ assert @result = stream_to(@file, tempfile)
35
+ end
36
+
37
+ should "return a Tempfile" do
38
+ assert @result.is_a?(Tempfile)
39
+ end
40
+
41
+ should "contain the same data as the original file" do
42
+ @file.rewind; @result.rewind
43
+ assert_equal @file.read, @result.read
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ context "that is converted #to_tempfile" do
50
+ setup do
51
+ assert @tempfile = to_tempfile(@file)
52
+ end
53
+
54
+ should "convert it to a Paperclip Tempfile" do
55
+ assert @tempfile.is_a?(Paperclip::Tempfile)
56
+ end
57
+
58
+ should "have the name be based on the original_filename" do
59
+ name = File.basename(@file.path)
60
+ extension = File.extname(name)
61
+ basename = File.basename(name, extension)
62
+ assert_match %r[^stream.*?#{Regexp.quote(extension)}], File.basename(@tempfile.path)
63
+ end
64
+
65
+ should "have the Tempfile contain the same data as the file" do
66
+ @file.rewind; @tempfile.rewind
67
+ assert_equal @file.read, @tempfile.read
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,24 @@
1
+ require './test/helper'
2
+
3
+ class HaveAttachedFileMatcherTest < Test::Unit::TestCase
4
+ context "have_attached_file" do
5
+ setup do
6
+ @dummy_class = reset_class "Dummy"
7
+ reset_table "dummies"
8
+ @matcher = self.class.have_attached_file(:avatar)
9
+ end
10
+
11
+ context "given a class with no attachment" do
12
+ should_reject_dummy_class
13
+ end
14
+
15
+ context "given a class with an attachment" do
16
+ setup do
17
+ modify_table("dummies"){|d| d.string :avatar_file_name }
18
+ @dummy_class.has_attached_file :avatar
19
+ end
20
+
21
+ should_accept_dummy_class
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,110 @@
1
+ require './test/helper'
2
+
3
+ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
4
+ context "validate_attachment_content_type" do
5
+ setup do
6
+ reset_table("dummies") do |d|
7
+ d.string :title
8
+ d.string :avatar_file_name
9
+ d.string :avatar_content_type
10
+ end
11
+ @dummy_class = reset_class "Dummy"
12
+ @dummy_class.has_attached_file :avatar
13
+ @matcher = self.class.validate_attachment_content_type(:avatar).
14
+ allowing(%w(image/png image/jpeg)).
15
+ rejecting(%w(audio/mp3 application/octet-stream))
16
+ end
17
+
18
+ context "given a class with no validation" do
19
+ should_reject_dummy_class
20
+ end
21
+
22
+ context "given a class with a validation that doesn't match" do
23
+ setup do
24
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
25
+ end
26
+
27
+ should_reject_dummy_class
28
+ end
29
+
30
+ context "given a class with a matching validation" do
31
+ setup do
32
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
33
+ end
34
+
35
+ should_accept_dummy_class
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
46
+
47
+ context "given a class that matches and a matcher that only specifies 'allowing'" do
48
+ setup do
49
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
50
+ @matcher = self.class.validate_attachment_content_type(:avatar).
51
+ allowing(%w(image/png image/jpeg))
52
+ end
53
+
54
+ should_accept_dummy_class
55
+ end
56
+
57
+ context "given a class that does not match and a matcher that only specifies 'allowing'" do
58
+ setup do
59
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
60
+ @matcher = self.class.validate_attachment_content_type(:avatar).
61
+ allowing(%w(image/png image/jpeg))
62
+ end
63
+
64
+ should_reject_dummy_class
65
+ end
66
+
67
+ context "given a class that matches and a matcher that only specifies 'rejecting'" do
68
+ setup do
69
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
70
+ @matcher = self.class.validate_attachment_content_type(:avatar).
71
+ rejecting(%w(audio/mp3 application/octet-stream))
72
+ end
73
+
74
+ should_accept_dummy_class
75
+ end
76
+
77
+ context "given a class that does not match and a matcher that only specifies 'rejecting'" do
78
+ setup do
79
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
80
+ @matcher = self.class.validate_attachment_content_type(:avatar).
81
+ rejecting(%w(audio/mp3 application/octet-stream))
82
+ end
83
+
84
+ should_reject_dummy_class
85
+ end
86
+
87
+ context "using an :if to control the validation" do
88
+ setup do
89
+ @dummy_class.class_eval do
90
+ validates_attachment_content_type :avatar, :content_type => %r{image/*} , :if => :go
91
+ attr_accessor :go
92
+ end
93
+ @matcher = self.class.validate_attachment_content_type(:avatar).
94
+ allowing(%w(image/png image/jpeg)).
95
+ rejecting(%w(audio/mp3 application/octet-stream))
96
+ @dummy = @dummy_class.new
97
+ end
98
+
99
+ should "run the validation if the control is true" do
100
+ @dummy.go = true
101
+ assert_accepts @matcher, @dummy
102
+ end
103
+
104
+ should "not run the validation if the control is false" do
105
+ @dummy.go = false
106
+ assert_rejects @matcher, @dummy
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,47 @@
1
+ require './test/helper'
2
+
3
+ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
4
+ context "validate_attachment_presence" do
5
+ setup do
6
+ reset_table("dummies") do |d|
7
+ d.string :avatar_file_name
8
+ end
9
+ @dummy_class = reset_class "Dummy"
10
+ @dummy_class.has_attached_file :avatar
11
+ @matcher = self.class.validate_attachment_presence(:avatar)
12
+ end
13
+
14
+ context "given a class with no validation" do
15
+ should_reject_dummy_class
16
+ end
17
+
18
+ context "given a class with a matching validation" do
19
+ setup do
20
+ @dummy_class.validates_attachment_presence :avatar
21
+ end
22
+
23
+ should_accept_dummy_class
24
+ end
25
+
26
+ context "using an :if to control the validation" do
27
+ setup do
28
+ @dummy_class.class_eval do
29
+ validates_attachment_presence :avatar, :if => :go
30
+ attr_accessor :go
31
+ end
32
+ @dummy = @dummy_class.new
33
+ @dummy.avatar = nil
34
+ end
35
+
36
+ should "run the validation if the control is true" do
37
+ @dummy.go = true
38
+ assert_accepts @matcher, @dummy
39
+ end
40
+
41
+ should "not run the validation if the control is false" do
42
+ @dummy.go = false
43
+ assert_rejects @matcher, @dummy
44
+ end
45
+ end
46
+ end
47
+ end