pothoven-attachment_fu 3.2.6 → 3.2.7
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/CHANGELOG +6 -0
- data/lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb +7 -7
- data/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +12 -12
- data/lib/technoweenie/attachment_fu/backends/s3_backend.rb +13 -13
- data/lib/technoweenie/attachment_fu.rb +1 -1
- metadata +17 -41
- data/Rakefile +0 -22
- data/install.rb +0 -7
- data/test/backends/db_file_test.rb +0 -16
- data/test/backends/file_system_test.rb +0 -143
- data/test/backends/remote/cloudfiles_test.rb +0 -102
- data/test/backends/remote/s3_test.rb +0 -119
- data/test/base_attachment_tests.rb +0 -77
- data/test/basic_test.rb +0 -120
- data/test/database.yml +0 -18
- data/test/extra_attachment_test.rb +0 -67
- data/test/fixtures/attachment.rb +0 -304
- data/test/fixtures/files/fake/rails.png +0 -0
- data/test/fixtures/files/foo.txt +0 -1
- data/test/fixtures/files/rails.jpg +0 -0
- data/test/fixtures/files/rails.png +0 -0
- data/test/geometry_test.rb +0 -114
- data/test/processors/core_image_test.rb +0 -58
- data/test/processors/gd2_test.rb +0 -51
- data/test/processors/image_science_test.rb +0 -54
- data/test/processors/mini_magick_test.rb +0 -122
- data/test/processors/rmagick_test.rb +0 -272
- data/test/schema.rb +0 -136
- data/test/test_helper.rb +0 -180
- data/test/validation_test.rb +0 -55
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
* Apr 10, 2013 *
|
2
|
+
* Ruby 2 compatibility fix
|
3
|
+
* Removed some lingering occurrences of RAILS_ROOT
|
4
|
+
* clean up of gemspec file
|
5
|
+
* no longer package unnecessary files like the test files
|
6
|
+
|
1
7
|
* Mar 12, 2013 *
|
2
8
|
* Pull in changes from https://github.com/aalong/attachment_fu to use Ruby 1.9.2 Tempfile naming strategy to fix conflicts with Sprockets (see https://github.com/aalong/attachment_fu/commit/938ec3b8597fbf82b1de8c98de12c4688463450a)
|
3
9
|
|
@@ -9,15 +9,15 @@ module Technoweenie # :nodoc:
|
|
9
9
|
#
|
10
10
|
# == Requirements
|
11
11
|
#
|
12
|
-
# Requires the {Cloud Files Gem}[http://www.mosso.com/cloudfiles.jsp] by Rackspace
|
12
|
+
# Requires the {Cloud Files Gem}[http://www.mosso.com/cloudfiles.jsp] by Rackspace
|
13
13
|
#
|
14
14
|
# == Configuration
|
15
15
|
#
|
16
|
-
# Configuration is done via <tt>
|
16
|
+
# Configuration is done via <tt>Rails.root.to_s/config/rackspace_cloudfiles.yml</tt> and is loaded according to the <tt>RAILS_ENV</tt>.
|
17
17
|
# The minimum connection options that you must specify are a container name, your Mosso login name and your Mosso API key.
|
18
|
-
# You can sign up for Cloud Files and get access keys by visiting https://www.mosso.com/buy.htm
|
18
|
+
# You can sign up for Cloud Files and get access keys by visiting https://www.mosso.com/buy.htm
|
19
19
|
#
|
20
|
-
# Example configuration (
|
20
|
+
# Example configuration (Rails.root.to_s/config/rackspace_cloudfiles.yml)
|
21
21
|
#
|
22
22
|
# development:
|
23
23
|
# container_name: appname_development
|
@@ -36,7 +36,7 @@ module Technoweenie # :nodoc:
|
|
36
36
|
#
|
37
37
|
# You can change the location of the config path by passing a full path to the :cloudfiles_config_path option.
|
38
38
|
#
|
39
|
-
# has_attachment :storage => :cloud_files, :cloudfiles_config_path => (
|
39
|
+
# has_attachment :storage => :cloud_files, :cloudfiles_config_path => (Rails.root.to_s + '/config/mosso.yml')
|
40
40
|
#
|
41
41
|
# === Required configuration parameters
|
42
42
|
#
|
@@ -116,7 +116,7 @@ module Technoweenie # :nodoc:
|
|
116
116
|
end
|
117
117
|
|
118
118
|
begin
|
119
|
-
@@cloudfiles_config_path = base.attachment_options[:cloudfiles_config_path] || (
|
119
|
+
@@cloudfiles_config_path = base.attachment_options[:cloudfiles_config_path] || (Rails.root.to_s + '/config/rackspace_cloudfiles.yml')
|
120
120
|
@@cloudfiles_config = @@cloudfiles_config = YAML.load(ERB.new(File.read(@@cloudfiles_config_path)).result)[RAILS_ENV].symbolize_keys
|
121
121
|
rescue
|
122
122
|
#raise ConfigFileNotFoundError.new('File %s not found' % @@cloudfiles_config_path)
|
@@ -125,7 +125,7 @@ module Technoweenie # :nodoc:
|
|
125
125
|
@@container_name = @@cloudfiles_config[:container_name]
|
126
126
|
@@cf = CloudFiles::Connection.new(@@cloudfiles_config[:username], @@cloudfiles_config[:api_key])
|
127
127
|
@@container = @@cf.container(@@container_name)
|
128
|
-
|
128
|
+
|
129
129
|
base.before_update :rename_file
|
130
130
|
end
|
131
131
|
|
@@ -9,12 +9,12 @@ module Technoweenie # :nodoc:
|
|
9
9
|
def self.included(base) #:nodoc:
|
10
10
|
base.before_update :rename_file
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# Gets the full path to the filename in this format:
|
14
14
|
#
|
15
15
|
# # This assumes a model name like MyModel
|
16
|
-
# # public/#{table_name} is the default filesystem path
|
17
|
-
#
|
16
|
+
# # public/#{table_name} is the default filesystem path
|
17
|
+
# #{Rails.root}/public/my_models/5/blah.jpg
|
18
18
|
#
|
19
19
|
# Overwrite this method in your model to customize the filename.
|
20
20
|
# The optional thumbnail argument will output the thumbnail's filename.
|
@@ -22,17 +22,17 @@ module Technoweenie # :nodoc:
|
|
22
22
|
file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s
|
23
23
|
Rails.root.join( file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Used as the base path that #public_filename strips off full_filename to create the public path
|
27
27
|
def base_path
|
28
28
|
@base_path ||= Rails.root.join('public').to_s
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# The attachment ID used in the full path of a file
|
32
32
|
def attachment_path_id
|
33
33
|
((respond_to?(:parent_id) && parent_id) || id) || 0
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Partitions the given path into an array of path components.
|
37
37
|
#
|
38
38
|
# For example, given an <tt>*args</tt> of ["foo", "bar"], it will return
|
@@ -42,10 +42,10 @@ module Technoweenie # :nodoc:
|
|
42
42
|
# hashing the string value of the id with SHA-512, and splitting the result
|
43
43
|
# into 4 components. If the id a 128-bit UUID (as set by :uuid_primary_key => true)
|
44
44
|
# then it will be split into 2 components.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# To turn this off entirely, set :partition => false.
|
47
47
|
def partitioned_path(*args)
|
48
|
-
if respond_to?(:attachment_options) && attachment_options[:partition] == false
|
48
|
+
if respond_to?(:attachment_options) && attachment_options[:partition] == false
|
49
49
|
args
|
50
50
|
elsif attachment_options[:uuid_primary_key]
|
51
51
|
# Primary key is a 128-bit UUID in hex format. Split it into 2 components.
|
@@ -65,13 +65,13 @@ module Technoweenie # :nodoc:
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
# Gets the public path to the file
|
70
70
|
# The optional thumbnail argument will output the thumbnail's filename.
|
71
71
|
def public_filename(thumbnail = nil)
|
72
72
|
full_filename(thumbnail).gsub %r(^#{Regexp.escape(base_path)}), ''
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def filename=(value)
|
76
76
|
@old_filename = full_filename unless filename.nil? || @old_filename
|
77
77
|
write_attribute :filename, sanitize_filename(value)
|
@@ -104,7 +104,7 @@ module Technoweenie # :nodoc:
|
|
104
104
|
@old_filename = nil
|
105
105
|
true
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# Saves the file to the file system
|
109
109
|
def save_to_storage
|
110
110
|
if save_attachment?
|
@@ -116,7 +116,7 @@ module Technoweenie # :nodoc:
|
|
116
116
|
@old_filename = nil
|
117
117
|
true
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def current_data
|
121
121
|
File.file?(full_filename) ? File.read(full_filename) : nil
|
122
122
|
end
|
@@ -12,7 +12,7 @@ module Technoweenie # :nodoc:
|
|
12
12
|
#
|
13
13
|
# == Configuration
|
14
14
|
#
|
15
|
-
# Configuration is done via <tt
|
15
|
+
# Configuration is done via <tt>#{Rails.root}/config/amazon_s3.yml</tt> and is loaded according to the <tt>RAILS_ENV</tt>.
|
16
16
|
# The minimum connection options that you must specify are a bucket name, your access key id and your secret access key.
|
17
17
|
# If you don't already have your access keys, all you need to sign up for the S3 service is an account at Amazon.
|
18
18
|
# You can sign up for S3 and get access keys by visiting http://aws.amazon.com/s3.
|
@@ -20,7 +20,7 @@ module Technoweenie # :nodoc:
|
|
20
20
|
# If you wish to use Amazon CloudFront to serve the files, you can also specify a distibution domain for the bucket.
|
21
21
|
# To read more about CloudFront, visit http://aws.amazon.com/cloudfront
|
22
22
|
#
|
23
|
-
# Example configuration (
|
23
|
+
# Example configuration (#{Rails.root}/config/amazon_s3.yml)
|
24
24
|
#
|
25
25
|
# development:
|
26
26
|
# bucket_name: appname_development
|
@@ -42,7 +42,7 @@ module Technoweenie # :nodoc:
|
|
42
42
|
#
|
43
43
|
# You can change the location of the config path by passing a full path to the :s3_config_path option.
|
44
44
|
#
|
45
|
-
# has_attachment :storage => :s3, :s3_config_path => (
|
45
|
+
# has_attachment :storage => :s3, :s3_config_path => (#{Rails.root} + '/config/s3.yml')
|
46
46
|
#
|
47
47
|
# === Required configuration parameters
|
48
48
|
#
|
@@ -158,9 +158,9 @@ module Technoweenie # :nodoc:
|
|
158
158
|
#
|
159
159
|
# Niether <tt>base_path</tt> or <tt>full_filename</tt> include the bucket name as part of the path.
|
160
160
|
# You can retrieve the bucket name using the <tt>bucket_name</tt> method.
|
161
|
-
#
|
161
|
+
#
|
162
162
|
# === Accessing CloudFront URLs
|
163
|
-
#
|
163
|
+
#
|
164
164
|
# You can get an object's CloudFront URL using the cloudfront_url accessor. Using the example from above:
|
165
165
|
# @postcard.cloudfront_url # => http://XXXX.cloudfront.net/photos/1/mexico.jpg
|
166
166
|
#
|
@@ -183,7 +183,7 @@ module Technoweenie # :nodoc:
|
|
183
183
|
end
|
184
184
|
|
185
185
|
begin
|
186
|
-
@@s3_config_path = base.attachment_options[:s3_config_path] || (
|
186
|
+
@@s3_config_path = base.attachment_options[:s3_config_path] || (Rails.root.to_s + '/config/amazon_s3.yml')
|
187
187
|
@@s3_config = @@s3_config = YAML.load(ERB.new(File.read(@@s3_config_path)).result)[RAILS_ENV].symbolize_keys
|
188
188
|
#rescue
|
189
189
|
# raise ConfigFileNotFoundError.new('File %s not found' % @@s3_config_path)
|
@@ -216,7 +216,7 @@ module Technoweenie # :nodoc:
|
|
216
216
|
def self.port_string
|
217
217
|
@port_string ||= (s3_config[:port].nil? || s3_config[:port] == (s3_config[:use_ssl] ? 443 : 80)) ? '' : ":#{s3_config[:port]}"
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def self.distribution_domain
|
221
221
|
@distribution_domain = s3_config[:distribution_domain]
|
222
222
|
end
|
@@ -233,7 +233,7 @@ module Technoweenie # :nodoc:
|
|
233
233
|
def s3_port_string
|
234
234
|
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
def cloudfront_distribution_domain
|
238
238
|
Technoweenie::AttachmentFu::Backends::S3Backend.distribution_domain
|
239
239
|
end
|
@@ -269,26 +269,26 @@ module Technoweenie # :nodoc:
|
|
269
269
|
#
|
270
270
|
# The resulting url is in the form: <tt>http(s)://:server/:bucket_name/:table_name/:id/:file</tt> where
|
271
271
|
# the <tt>:server</tt> variable defaults to <tt>AWS::S3 URL::DEFAULT_HOST</tt> (s3.amazonaws.com) and can be
|
272
|
-
# set using the configuration parameters in <tt
|
272
|
+
# set using the configuration parameters in <tt>#{Rails.root}/config/amazon_s3.yml</tt>.
|
273
273
|
#
|
274
274
|
# The optional thumbnail argument will output the thumbnail's filename (if any).
|
275
275
|
def s3_url(thumbnail = nil)
|
276
276
|
File.join(s3_protocol + s3_hostname + s3_port_string, bucket_name, full_filename(thumbnail))
|
277
277
|
end
|
278
|
-
|
278
|
+
|
279
279
|
# All public objects are accessible via a GET request to CloudFront. You can generate a
|
280
280
|
# url for an object using the cloudfront_url method.
|
281
281
|
#
|
282
282
|
# @photo.cloudfront_url
|
283
283
|
#
|
284
284
|
# The resulting url is in the form: <tt>http://:distribution_domain/:table_name/:id/:file</tt> using
|
285
|
-
# the <tt>:distribution_domain</tt> variable set in the configuration parameters in <tt
|
285
|
+
# the <tt>:distribution_domain</tt> variable set in the configuration parameters in <tt>#{Rails.root}/config/amazon_s3.yml</tt>.
|
286
286
|
#
|
287
287
|
# The optional thumbnail argument will output the thumbnail's filename (if any).
|
288
288
|
def cloudfront_url(thumbnail = nil)
|
289
289
|
"http://" + cloudfront_distribution_domain + "/" + full_filename(thumbnail)
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
def public_filename(*args)
|
293
293
|
if attachment_options[:cloudfront]
|
294
294
|
cloudfront_url(args)
|
@@ -347,7 +347,7 @@ module Technoweenie # :nodoc:
|
|
347
347
|
def s3_port_string
|
348
348
|
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
|
349
349
|
end
|
350
|
-
|
350
|
+
|
351
351
|
def cloudfront_distribution_domain
|
352
352
|
Technoweenie::AttachmentFu::Backends::S3Backend.distribution_domain
|
353
353
|
end
|
@@ -474,7 +474,7 @@ module Technoweenie # :nodoc:
|
|
474
474
|
# Cleans up after processing. Thumbnails are created, the attachment is stored to the backend, and the temp_paths are cleared.
|
475
475
|
def after_process_attachment
|
476
476
|
if @saved_attachment
|
477
|
-
if respond_to?(:process_attachment_with_processing) && thumbnailable? && !attachment_options[:thumbnails].blank? && parent_id.nil?
|
477
|
+
if respond_to?(:process_attachment_with_processing, true) && thumbnailable? && !attachment_options[:thumbnails].blank? && parent_id.nil?
|
478
478
|
temp_file = temp_path || create_temp_file
|
479
479
|
attachment_options[:thumbnails].each { |suffix, size|
|
480
480
|
if size.is_a?(Symbol)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pothoven-attachment_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: This is a fork of Rick Olson’s attachment_fu adding Ruby 1.9 and Rails
|
16
16
|
3.2 support as well as some other enhancements.
|
@@ -20,54 +20,30 @@ extensions: []
|
|
20
20
|
extra_rdoc_files:
|
21
21
|
- README
|
22
22
|
files:
|
23
|
-
- CHANGELOG
|
24
|
-
- LICENSE
|
25
|
-
- README
|
26
|
-
- Rakefile
|
27
|
-
- install.rb
|
28
|
-
- amazon_s3.yml.tpl
|
29
|
-
- rackspace_cloudfiles.yml.tpl
|
30
23
|
- lib/geometry.rb
|
31
24
|
- lib/pothoven-attachment_fu.rb
|
32
|
-
- lib/technoweenie/attachment_fu
|
33
|
-
- lib/technoweenie/attachment_fu/backends/db_file_backend.rb
|
34
|
-
- lib/technoweenie/attachment_fu/backends/file_system_backend.rb
|
35
|
-
- lib/technoweenie/attachment_fu/backends/s3_backend.rb
|
36
|
-
- lib/technoweenie/attachment_fu/processors/core_image_processor.rb
|
25
|
+
- lib/technoweenie/attachment_fu.rb
|
37
26
|
- lib/technoweenie/attachment_fu/processors/gd2_processor.rb
|
38
|
-
- lib/technoweenie/attachment_fu/processors/image_science_processor.rb
|
39
27
|
- lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb
|
40
28
|
- lib/technoweenie/attachment_fu/processors/rmagick_processor.rb
|
41
|
-
- lib/technoweenie/attachment_fu.rb
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
- test/schema.rb
|
48
|
-
- test/test_helper.rb
|
49
|
-
- test/validation_test.rb
|
50
|
-
- test/backends/db_file_test.rb
|
51
|
-
- test/backends/file_system_test.rb
|
52
|
-
- test/backends/remote/cloudfiles_test.rb
|
53
|
-
- test/backends/remote/s3_test.rb
|
54
|
-
- test/fixtures/attachment.rb
|
55
|
-
- test/fixtures/files/foo.txt
|
56
|
-
- test/fixtures/files/rails.jpg
|
57
|
-
- test/fixtures/files/rails.png
|
58
|
-
- test/fixtures/files/fake/rails.png
|
59
|
-
- test/processors/core_image_test.rb
|
60
|
-
- test/processors/gd2_test.rb
|
61
|
-
- test/processors/image_science_test.rb
|
62
|
-
- test/processors/mini_magick_test.rb
|
63
|
-
- test/processors/rmagick_test.rb
|
29
|
+
- lib/technoweenie/attachment_fu/processors/core_image_processor.rb
|
30
|
+
- lib/technoweenie/attachment_fu/processors/image_science_processor.rb
|
31
|
+
- lib/technoweenie/attachment_fu/backends/s3_backend.rb
|
32
|
+
- lib/technoweenie/attachment_fu/backends/file_system_backend.rb
|
33
|
+
- lib/technoweenie/attachment_fu/backends/db_file_backend.rb
|
34
|
+
- lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb
|
64
35
|
- vendor/red_artisan/core_image/processor.rb
|
65
36
|
- vendor/red_artisan/core_image/filters/color.rb
|
66
|
-
- vendor/red_artisan/core_image/filters/effects.rb
|
67
|
-
- vendor/red_artisan/core_image/filters/perspective.rb
|
68
37
|
- vendor/red_artisan/core_image/filters/quality.rb
|
69
|
-
- vendor/red_artisan/core_image/filters/scale.rb
|
70
38
|
- vendor/red_artisan/core_image/filters/watermark.rb
|
39
|
+
- vendor/red_artisan/core_image/filters/scale.rb
|
40
|
+
- vendor/red_artisan/core_image/filters/effects.rb
|
41
|
+
- vendor/red_artisan/core_image/filters/perspective.rb
|
42
|
+
- CHANGELOG
|
43
|
+
- LICENSE
|
44
|
+
- README
|
45
|
+
- amazon_s3.yml.tpl
|
46
|
+
- rackspace_cloudfiles.yml.tpl
|
71
47
|
homepage: http://github.com/pothoven/attachment_fu
|
72
48
|
licenses: []
|
73
49
|
post_install_message:
|
data/Rakefile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the attachment_fu plugin.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Generate documentation for the attachment_fu plugin.'
|
16
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
-
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = 'ActsAsAttachment'
|
19
|
-
rdoc.options << '--line-numbers --inline-source'
|
20
|
-
rdoc.rdoc_files.include('README')
|
21
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
-
end
|
data/install.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
s3_config = File.dirname(__FILE__) + '/../../../config/amazon_s3.yml'
|
4
|
-
FileUtils.cp File.dirname(__FILE__) + '/amazon_s3.yml.tpl', s3_config unless File.exist?(s3_config)
|
5
|
-
cloudfiles_config = File.dirname(__FILE__) + '/../../../config/rackspace_cloudfiles.yml'
|
6
|
-
FileUtils.cp File.dirname(__FILE__) + '/rackspace_cloudfiles.yml.tpl', cloudfiles_config unless File.exist?(cloudfiles_config)
|
7
|
-
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
|
2
|
-
|
3
|
-
class DbFileTest < Test::Unit::TestCase
|
4
|
-
include BaseAttachmentTests
|
5
|
-
attachment_model Attachment
|
6
|
-
|
7
|
-
def test_should_call_after_attachment_saved(klass = Attachment)
|
8
|
-
attachment_model.saves = 0
|
9
|
-
assert_created do
|
10
|
-
upload_file :filename => '/files/rails.png'
|
11
|
-
end
|
12
|
-
assert_equal 1, attachment_model.saves
|
13
|
-
end
|
14
|
-
|
15
|
-
test_against_subclass :test_should_call_after_attachment_saved, Attachment
|
16
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
|
2
|
-
require 'digest/sha2'
|
3
|
-
|
4
|
-
class FileSystemTest < Test::Unit::TestCase
|
5
|
-
include BaseAttachmentTests
|
6
|
-
attachment_model FileAttachment
|
7
|
-
|
8
|
-
def test_filesystem_size_for_file_attachment(klass = FileAttachment)
|
9
|
-
attachment_model klass
|
10
|
-
assert_created 1 do
|
11
|
-
attachment = upload_file :filename => '/files/rails.png'
|
12
|
-
assert_equal attachment.size, File.open(attachment.full_filename).stat.size
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
test_against_subclass :test_filesystem_size_for_file_attachment, FileAttachment
|
17
|
-
|
18
|
-
def test_should_not_overwrite_file_attachment(klass = FileAttachment)
|
19
|
-
attachment_model klass
|
20
|
-
assert_created 2 do
|
21
|
-
real = upload_file :filename => '/files/rails.png'
|
22
|
-
assert_valid real
|
23
|
-
assert !real.new_record?, real.errors.full_messages.join("\n")
|
24
|
-
assert !real.size.zero?
|
25
|
-
|
26
|
-
fake = upload_file :filename => '/files/fake/rails.png'
|
27
|
-
assert_valid fake
|
28
|
-
assert !fake.size.zero?
|
29
|
-
|
30
|
-
assert_not_equal File.open(real.full_filename).stat.size, File.open(fake.full_filename).stat.size
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
test_against_subclass :test_should_not_overwrite_file_attachment, FileAttachment
|
35
|
-
|
36
|
-
def test_should_store_file_attachment_in_filesystem(klass = FileAttachment)
|
37
|
-
attachment_model klass
|
38
|
-
attachment = nil
|
39
|
-
assert_created do
|
40
|
-
attachment = upload_file :filename => '/files/rails.png'
|
41
|
-
assert_valid attachment
|
42
|
-
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
|
43
|
-
end
|
44
|
-
attachment
|
45
|
-
end
|
46
|
-
|
47
|
-
test_against_subclass :test_should_store_file_attachment_in_filesystem, FileAttachment
|
48
|
-
|
49
|
-
def test_should_delete_old_file_when_updating(klass = FileAttachment)
|
50
|
-
attachment_model klass
|
51
|
-
attachment = upload_file :filename => '/files/rails.png'
|
52
|
-
old_filename = attachment.full_filename
|
53
|
-
assert_not_created do
|
54
|
-
use_temp_file 'files/rails.png' do |file|
|
55
|
-
attachment.filename = 'rails2.png'
|
56
|
-
attachment.temp_paths.unshift File.join(FIXTURE_PATH, file)
|
57
|
-
attachment.save!
|
58
|
-
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
|
59
|
-
assert !File.exists?(old_filename), "#{old_filename} still exists"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
test_against_subclass :test_should_delete_old_file_when_updating, FileAttachment
|
65
|
-
|
66
|
-
def test_should_delete_old_file_when_renaming(klass = FileAttachment)
|
67
|
-
attachment_model klass
|
68
|
-
attachment = upload_file :filename => '/files/rails.png'
|
69
|
-
old_filename = attachment.full_filename
|
70
|
-
assert_not_created do
|
71
|
-
attachment.filename = 'rails2.png'
|
72
|
-
attachment.save
|
73
|
-
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
|
74
|
-
assert !File.exists?(old_filename), "#{old_filename} still exists"
|
75
|
-
assert !attachment.reload.size.zero?
|
76
|
-
assert_equal 'rails2.png', attachment.filename
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
test_against_subclass :test_should_delete_old_file_when_renaming, FileAttachment
|
81
|
-
|
82
|
-
def test_path_partitioning_works_on_integer_id(klass = FileAttachment)
|
83
|
-
attachment_model klass
|
84
|
-
|
85
|
-
# Create a random attachment object, doesn't matter what.
|
86
|
-
attachment = upload_file :filename => '/files/rails.png'
|
87
|
-
old_id = attachment.id
|
88
|
-
attachment.id = 1
|
89
|
-
|
90
|
-
begin
|
91
|
-
assert_equal ["0000", "0001", "bar.txt"], attachment.send(:partitioned_path, "bar.txt")
|
92
|
-
ensure
|
93
|
-
attachment.id = old_id
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
test_against_subclass :test_path_partitioning_works_on_integer_id, FileAttachment
|
98
|
-
|
99
|
-
def test_path_partitioning_with_string_id_works_by_generating_hash(klass = FileAttachmentWithStringId)
|
100
|
-
attachment_model klass
|
101
|
-
|
102
|
-
# Create a random attachment object, doesn't matter what.
|
103
|
-
attachment = upload_file :filename => '/files/rails.png'
|
104
|
-
old_id = attachment.id
|
105
|
-
attachment.id = "hello world some long string"
|
106
|
-
hash = Digest::SHA512.hexdigest("hello world some long string")
|
107
|
-
|
108
|
-
begin
|
109
|
-
assert_equal [
|
110
|
-
hash[0..31],
|
111
|
-
hash[32..63],
|
112
|
-
hash[64..95],
|
113
|
-
hash[96..127],
|
114
|
-
"bar.txt"
|
115
|
-
], attachment.send(:partitioned_path, "bar.txt")
|
116
|
-
ensure
|
117
|
-
attachment.id = old_id
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
test_against_subclass :test_path_partitioning_with_string_id_works_by_generating_hash, FileAttachmentWithStringId
|
122
|
-
|
123
|
-
def test_path_partition_string_id_hashing_is_turned_off_if_id_is_uuid(klass = FileAttachmentWithUuid)
|
124
|
-
attachment_model klass
|
125
|
-
|
126
|
-
# Create a random attachment object, doesn't matter what.
|
127
|
-
attachment = upload_file :filename => '/files/rails.png'
|
128
|
-
old_id = attachment.id
|
129
|
-
attachment.id = "0c0743b698483569dc65909a8cdb3bf9"
|
130
|
-
|
131
|
-
begin
|
132
|
-
assert_equal [
|
133
|
-
"0c0743b698483569",
|
134
|
-
"dc65909a8cdb3bf9",
|
135
|
-
"bar.txt"
|
136
|
-
], attachment.send(:partitioned_path, "bar.txt")
|
137
|
-
ensure
|
138
|
-
attachment.id = old_id
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
test_against_subclass :test_path_partition_string_id_hashing_is_turned_off_if_id_is_uuid, FileAttachmentWithUuid
|
143
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
2
|
-
require 'net/http'
|
3
|
-
|
4
|
-
class CloudfilesTest < Test::Unit::TestCase
|
5
|
-
def self.test_CloudFiles?
|
6
|
-
true unless ENV["TEST_CLOUDFILES"] == "false"
|
7
|
-
end
|
8
|
-
|
9
|
-
if test_CloudFiles? && File.exist?(File.join(File.dirname(__FILE__), '../../rackspace_cloudfiles.yml'))
|
10
|
-
include BaseAttachmentTests
|
11
|
-
attachment_model CloudFilesAttachment
|
12
|
-
|
13
|
-
def test_should_create_correct_container_name(klass = CloudFilesAttachment)
|
14
|
-
attachment_model klass
|
15
|
-
attachment = upload_file :filename => '/files/rails.png'
|
16
|
-
assert_equal attachment.cloudfiles_config[:container_name], attachment.container_name
|
17
|
-
end
|
18
|
-
|
19
|
-
test_against_subclass :test_should_create_correct_container_name, CloudFilesAttachment
|
20
|
-
|
21
|
-
def test_should_create_default_path_prefix(klass = CloudFilesAttachment)
|
22
|
-
attachment_model klass
|
23
|
-
attachment = upload_file :filename => '/files/rails.png'
|
24
|
-
assert_equal File.join(attachment_model.table_name, attachment.attachment_path_id), attachment.base_path
|
25
|
-
end
|
26
|
-
|
27
|
-
test_against_subclass :test_should_create_default_path_prefix, CloudFilesAttachment
|
28
|
-
|
29
|
-
def test_should_create_custom_path_prefix(klass = CloudFilesWithPathPrefixAttachment)
|
30
|
-
attachment_model klass
|
31
|
-
attachment = upload_file :filename => '/files/rails.png'
|
32
|
-
assert_equal File.join('some/custom/path/prefix', attachment.attachment_path_id), attachment.base_path
|
33
|
-
end
|
34
|
-
|
35
|
-
test_against_subclass :test_should_create_custom_path_prefix, CloudFilesWithPathPrefixAttachment
|
36
|
-
|
37
|
-
|
38
|
-
def test_should_create_valid_url(klass = CloudFilesAttachment)
|
39
|
-
attachment_model klass
|
40
|
-
attachment = upload_file :filename => '/files/rails.png'
|
41
|
-
assert_match(%r!http://cdn.cloudfiles.mosso.com/(.*?)/cloud_files_attachments/1/rails.png!, attachment.cloudfiles_url)
|
42
|
-
end
|
43
|
-
|
44
|
-
test_against_subclass :test_should_create_valid_url, CloudFilesAttachment
|
45
|
-
|
46
|
-
def test_should_save_attachment(klass = CloudFilesAttachment)
|
47
|
-
attachment_model klass
|
48
|
-
assert_created do
|
49
|
-
attachment = upload_file :filename => '/files/rails.png'
|
50
|
-
assert_valid attachment
|
51
|
-
assert attachment.image?
|
52
|
-
assert !attachment.size.zero?
|
53
|
-
assert_kind_of Net::HTTPOK, http_response_for(attachment.cloudfiles_url)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
test_against_subclass :test_should_save_attachment, CloudFilesAttachment
|
58
|
-
|
59
|
-
def test_should_delete_attachment_from_cloud_files_when_attachment_record_destroyed(klass = CloudFilesAttachment)
|
60
|
-
attachment_model klass
|
61
|
-
attachment = upload_file :filename => '/files/rails.png'
|
62
|
-
|
63
|
-
urls = [attachment.cloudfiles_url] + attachment.thumbnails.collect(&:cloudfiles_url)
|
64
|
-
|
65
|
-
urls.each {|url| assert_kind_of Net::HTTPOK, http_response_for(url) }
|
66
|
-
attachment.destroy
|
67
|
-
urls.each do |url|
|
68
|
-
begin
|
69
|
-
http_response_for(url)
|
70
|
-
rescue Net::HTTPForbidden, Net::HTTPNotFound
|
71
|
-
nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
test_against_subclass :test_should_delete_attachment_from_cloud_files_when_attachment_record_destroyed, CloudFilesAttachment
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
protected
|
81
|
-
def http_response_for(url)
|
82
|
-
url = URI.parse(url)
|
83
|
-
Net::HTTP.start(url.host, url.port) {|http| http.request_head(url.path) }
|
84
|
-
end
|
85
|
-
|
86
|
-
def s3_protocol
|
87
|
-
Technoweenie::AttachmentFu::Backends::S3Backend.protocol
|
88
|
-
end
|
89
|
-
|
90
|
-
def s3_hostname
|
91
|
-
Technoweenie::AttachmentFu::Backends::S3Backend.hostname
|
92
|
-
end
|
93
|
-
|
94
|
-
def s3_port_string
|
95
|
-
Technoweenie::AttachmentFu::Backends::S3Backend.port_string
|
96
|
-
end
|
97
|
-
else
|
98
|
-
def test_flunk_s3
|
99
|
-
puts "s3 config file not loaded, tests not running"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|