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,10 @@
1
+ require './test/helper'
2
+
3
+ class ProcessorTest < Test::Unit::TestCase
4
+ should "instantiate and call #make when sent #make to the class" do
5
+ processor = mock
6
+ processor.expects(:make).with()
7
+ Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
8
+ Paperclip::Processor.make(:one, :two, :three)
9
+ end
10
+ end
@@ -0,0 +1,98 @@
1
+ require './test/helper'
2
+ require 'paperclip/schema'
3
+
4
+ class MockSchema
5
+ include Paperclip::Schema
6
+
7
+ def initialize(table_name = nil)
8
+ @table_name = table_name
9
+ @columns = {}
10
+ @deleted_columns = []
11
+ end
12
+
13
+ def column(name, type)
14
+ @columns[name] = type
15
+ end
16
+
17
+ def remove_column(table_name, column_name)
18
+ return if @table_name && @table_name != table_name
19
+ @columns.delete(column_name)
20
+ @deleted_columns.push(column_name)
21
+ end
22
+
23
+ def has_column?(column_name)
24
+ @columns.key?(column_name)
25
+ end
26
+
27
+ def deleted_column?(column_name)
28
+ @deleted_columns.include?(column_name)
29
+ end
30
+
31
+ def type_of(column_name)
32
+ @columns[column_name]
33
+ end
34
+ end
35
+
36
+ class SchemaTest < Test::Unit::TestCase
37
+ context "Migrating up" do
38
+ setup do
39
+ @schema = MockSchema.new
40
+ @schema.has_attached_file :avatar
41
+ end
42
+
43
+ should "create the file_name column" do
44
+ assert @schema.has_column?(:avatar_file_name)
45
+ end
46
+
47
+ should "create the content_type column" do
48
+ assert @schema.has_column?(:avatar_content_type)
49
+ end
50
+
51
+ should "create the file_size column" do
52
+ assert @schema.has_column?(:avatar_file_size)
53
+ end
54
+
55
+ should "create the updated_at column" do
56
+ assert @schema.has_column?(:avatar_updated_at)
57
+ end
58
+
59
+ should "make the file_name column a string" do
60
+ assert_equal :string, @schema.type_of(:avatar_file_name)
61
+ end
62
+
63
+ should "make the content_type column a string" do
64
+ assert_equal :string, @schema.type_of(:avatar_content_type)
65
+ end
66
+
67
+ should "make the file_size column an integer" do
68
+ assert_equal :integer, @schema.type_of(:avatar_file_size)
69
+ end
70
+
71
+ should "make the updated_at column a datetime" do
72
+ assert_equal :datetime, @schema.type_of(:avatar_updated_at)
73
+ end
74
+ end
75
+
76
+ context "Migrating down" do
77
+ setup do
78
+ @schema = MockSchema.new(:users)
79
+ @schema.drop_attached_file :users, :avatar
80
+ end
81
+
82
+ should "remove the file_name column" do
83
+ assert @schema.deleted_column?(:avatar_file_name)
84
+ end
85
+
86
+ should "remove the content_type column" do
87
+ assert @schema.deleted_column?(:avatar_content_type)
88
+ end
89
+
90
+ should "remove the file_size column" do
91
+ assert @schema.deleted_column?(:avatar_file_size)
92
+ end
93
+
94
+ should "remove the updated_at column" do
95
+ assert @schema.deleted_column?(:avatar_updated_at)
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,62 @@
1
+ require './test/helper'
2
+
3
+ class FileSystemTest < Test::Unit::TestCase
4
+ context "Filesystem" do
5
+ setup do
6
+ rebuild_model :styles => { :thumbnail => "25x25#" }
7
+ @dummy = Dummy.create!
8
+
9
+ @dummy.avatar = File.open(fixture_file('5k.png'))
10
+ end
11
+
12
+ should "allow file assignment" do
13
+ assert @dummy.save
14
+ end
15
+
16
+ should "store the original" do
17
+ @dummy.save
18
+ assert File.exists?(@dummy.avatar.path)
19
+ end
20
+
21
+ should "store the thumbnail" do
22
+ @dummy.save
23
+ assert File.exists?(@dummy.avatar.path(:thumbnail))
24
+ end
25
+
26
+ should "clean up file objects" do
27
+ File.stubs(:exist?).returns(true)
28
+ Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
29
+ Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
30
+
31
+ @dummy.save!
32
+ end
33
+
34
+ should "always be rewound when returning from #to_file" do
35
+ assert_equal 0, @dummy.avatar.to_file.pos
36
+ @dummy.avatar.to_file.seek(10)
37
+ assert_equal 0, @dummy.avatar.to_file.pos
38
+ end
39
+
40
+ context "with file that has space in file name" do
41
+ setup do
42
+ rebuild_model :styles => { :thumbnail => "25x25#" }
43
+ @dummy = Dummy.create!
44
+
45
+ @dummy.avatar = File.open(fixture_file('spaced file.png'))
46
+ @dummy.save
47
+ end
48
+
49
+ should "store the file" do
50
+ assert File.exists?(@dummy.avatar.path)
51
+ end
52
+
53
+ should "return a replaced version for path" do
54
+ assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
55
+ end
56
+
57
+ should "return a replaced version for url" do
58
+ assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,280 @@
1
+ require './test/helper'
2
+ require 'fog'
3
+
4
+ Fog.mock!
5
+
6
+ class FogTest < Test::Unit::TestCase
7
+ context "" do
8
+
9
+ context "with credentials provided in a path string" do
10
+ setup do
11
+ rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
12
+ :storage => :fog,
13
+ :url => '/:attachment/:filename',
14
+ :fog_directory => "paperclip",
15
+ :fog_credentials => fixture_file('fog.yml')
16
+ @dummy = Dummy.new
17
+ @dummy.avatar = File.new(fixture_file('5k.png'), 'rb')
18
+ end
19
+
20
+ should "have the proper information loading credentials from a file" do
21
+ assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
22
+ end
23
+ end
24
+
25
+ context "with credentials provided in a File object" do
26
+ setup do
27
+ rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
28
+ :storage => :fog,
29
+ :url => '/:attachment/:filename',
30
+ :fog_directory => "paperclip",
31
+ :fog_credentials => File.open(fixture_file('fog.yml'))
32
+ @dummy = Dummy.new
33
+ @dummy.avatar = File.new(fixture_file('5k.png'), 'rb')
34
+ end
35
+
36
+ should "have the proper information loading credentials from a file" do
37
+ assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
38
+ end
39
+ end
40
+
41
+ context "with default values for path and url" do
42
+ setup do
43
+ rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
44
+ :storage => :fog,
45
+ :url => '/:attachment/:filename',
46
+ :fog_directory => "paperclip",
47
+ :fog_credentials => {
48
+ :provider => 'AWS',
49
+ :aws_access_key_id => 'AWS_ID',
50
+ :aws_secret_access_key => 'AWS_SECRET'
51
+ }
52
+ @dummy = Dummy.new
53
+ @dummy.avatar = File.new(fixture_file('5k.png'), 'rb')
54
+ end
55
+ should "be able to interpolate the path without blowing up" do
56
+ assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../public/avatars/5k.png")),
57
+ @dummy.avatar.path
58
+ end
59
+
60
+ should "clean up file objects" do
61
+ File.stubs(:exist?).returns(true)
62
+ Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
63
+ Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
64
+
65
+ @dummy.save!
66
+ end
67
+ end
68
+
69
+ setup do
70
+ @fog_directory = 'papercliptests'
71
+
72
+ @credentials = {
73
+ :provider => 'AWS',
74
+ :aws_access_key_id => 'ID',
75
+ :aws_secret_access_key => 'SECRET'
76
+ }
77
+
78
+ @connection = Fog::Storage.new(@credentials)
79
+ @connection.directories.create(
80
+ :key => @fog_directory
81
+ )
82
+
83
+ @options = {
84
+ :fog_directory => @fog_directory,
85
+ :fog_credentials => @credentials,
86
+ :fog_host => nil,
87
+ :fog_file => {:cache_control => 1234},
88
+ :path => ":attachment/:basename.:extension",
89
+ :storage => :fog
90
+ }
91
+
92
+ rebuild_model(@options)
93
+ end
94
+
95
+ should "be extended by the Fog module" do
96
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog)
97
+ end
98
+
99
+ context "when assigned" do
100
+ setup do
101
+ @file = File.new(fixture_file('5k.png'), 'rb')
102
+ @dummy = Dummy.new
103
+ @dummy.avatar = @file
104
+ end
105
+
106
+ teardown do
107
+ @file.close
108
+ directory = @connection.directories.new(:key => @fog_directory)
109
+ directory.files.each {|file| file.destroy}
110
+ directory.destroy
111
+ end
112
+
113
+ should "always be rewound when returning from #to_file" do
114
+ assert_equal 0, @dummy.avatar.to_file.pos
115
+ @dummy.avatar.to_file.seek(10)
116
+ assert_equal 0, @dummy.avatar.to_file.pos
117
+ end
118
+
119
+ should "pass the content type to the Fog::Storage::AWS::Files instance" do
120
+ Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
121
+ hash[:content_type]
122
+ end
123
+ @dummy.save
124
+ end
125
+
126
+ context "without a bucket" do
127
+ setup do
128
+ @connection.directories.get(@fog_directory).destroy
129
+ end
130
+
131
+ should "create the bucket" do
132
+ assert @dummy.save
133
+ assert @connection.directories.get(@fog_directory)
134
+ end
135
+ end
136
+
137
+ context "with a bucket" do
138
+ should "succeed" do
139
+ assert @dummy.save
140
+ end
141
+ end
142
+
143
+ context "without a fog_host" do
144
+ setup do
145
+ rebuild_model(@options.merge(:fog_host => nil))
146
+ @dummy = Dummy.new
147
+ @dummy.avatar = StringIO.new('.')
148
+ @dummy.save
149
+ end
150
+
151
+ should "provide a public url" do
152
+ assert !@dummy.avatar.url.nil?
153
+ end
154
+ end
155
+
156
+ context "with a fog_host" do
157
+ setup do
158
+ rebuild_model(@options.merge(:fog_host => 'http://example.com'))
159
+ @dummy = Dummy.new
160
+ @dummy.avatar = StringIO.new('.')
161
+ @dummy.save
162
+ end
163
+
164
+ should "provide a public url" do
165
+ assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/stringio\.txt\?\d*$/
166
+ end
167
+ end
168
+
169
+ context "with a fog_host that includes a wildcard placeholder" do
170
+ setup do
171
+ rebuild_model(
172
+ :fog_directory => @fog_directory,
173
+ :fog_credentials => @credentials,
174
+ :fog_host => 'http://img%d.example.com',
175
+ :path => ":attachment/:basename.:extension",
176
+ :storage => :fog
177
+ )
178
+ @dummy = Dummy.new
179
+ @dummy.avatar = StringIO.new('.')
180
+ @dummy.save
181
+ end
182
+
183
+ should "provide a public url" do
184
+ assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/stringio\.txt\?\d*$/
185
+ end
186
+ end
187
+
188
+ context "with fog_public set to false" do
189
+ setup do
190
+ rebuild_model(@options.merge(:fog_public => false))
191
+ @dummy = Dummy.new
192
+ @dummy.avatar = StringIO.new('.')
193
+ @dummy.save
194
+ end
195
+
196
+ should 'set the @fog_public instance variable to false' do
197
+ assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
198
+ assert_equal false, @dummy.avatar.fog_public
199
+ end
200
+ end
201
+
202
+ context "with a valid bucket name for a subdomain" do
203
+ should "provide an url in subdomain style" do
204
+ assert_match /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url
205
+ end
206
+ end
207
+
208
+ context "with an invalid bucket name for a subdomain" do
209
+ setup do
210
+ rebuild_model(@options.merge(:fog_directory => "this_is_invalid"))
211
+ @dummy = Dummy.new
212
+ @dummy.avatar = @file
213
+ @dummy.save
214
+ end
215
+
216
+ should "not match the bucket-subdomain restrictions" do
217
+ invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
218
+ invalid_subdomains.each do |name|
219
+ assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name
220
+ end
221
+ end
222
+
223
+ should "provide an url in folder style" do
224
+ assert_match /^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url
225
+ end
226
+
227
+ end
228
+
229
+ context "with a proc for a bucket name evaluating a model method" do
230
+ setup do
231
+ @dynamic_fog_directory = 'dynamicpaperclip'
232
+ rebuild_model(@options.merge(:fog_directory => lambda { |attachment| attachment.instance.bucket_name }))
233
+ @dummy = Dummy.new
234
+ @dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
235
+ @dummy.avatar = @file
236
+ @dummy.save
237
+ end
238
+
239
+ should "have created the bucket" do
240
+ assert @connection.directories.get(@dynamic_fog_directory).inspect
241
+ end
242
+
243
+ end
244
+
245
+ context "with a proc for the fog_host evaluating a model method" do
246
+ setup do
247
+ rebuild_model(@options.merge(:fog_host => lambda { |attachment| attachment.instance.fog_host }))
248
+ @dummy = Dummy.new
249
+ @dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
250
+ @dummy.avatar = @file
251
+ @dummy.save
252
+ end
253
+
254
+ should "provide a public url" do
255
+ assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
256
+ end
257
+ end
258
+
259
+ context "with a proc for the fog_credentials evaluating a model method" do
260
+ setup do
261
+ @dynamic_fog_credentials = {
262
+ :provider => 'AWS',
263
+ :aws_access_key_id => 'DYNAMIC_ID',
264
+ :aws_secret_access_key => 'DYNAMIC_SECRET'
265
+ }
266
+ rebuild_model(@options.merge(:fog_credentials => lambda { |attachment| attachment.instance.fog_credentials }))
267
+ @dummy = Dummy.new
268
+ @dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
269
+ @dummy.avatar = @file
270
+ @dummy.save
271
+ end
272
+
273
+ should "provide a public url" do
274
+ assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
275
+ end
276
+ end
277
+ end
278
+
279
+ end
280
+ end