cloudfuji_paperclip 2.4.6 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +9 -6
- data/Appraisals +6 -6
- data/CONTRIBUTING.md +34 -2
- data/Gemfile +2 -0
- data/NEWS +90 -0
- data/README.md +62 -29
- data/RUNNING_TESTS.md +4 -0
- data/Rakefile +7 -2
- data/UPGRADING +14 -0
- data/features/basic_integration.feature +11 -7
- data/features/rake_tasks.feature +1 -1
- data/features/step_definitions/attachment_steps.rb +11 -2
- data/features/step_definitions/rails_steps.rb +17 -79
- data/features/support/env.rb +3 -0
- data/features/support/fakeweb.rb +7 -0
- data/features/support/file_helpers.rb +24 -0
- data/features/support/rails.rb +3 -3
- data/gemfiles/{rails3_1.gemfile → 3.0.gemfile} +3 -1
- data/gemfiles/{rails2.gemfile → 3.1.gemfile} +3 -1
- data/gemfiles/{rails3.gemfile → 3.2.gemfile} +3 -1
- data/images.rake +21 -0
- data/lib/cloudfuji_paperclip.rb +1 -0
- data/lib/generators/paperclip/paperclip_generator.rb +1 -2
- data/lib/paperclip.rb +54 -319
- data/lib/paperclip/attachment.rb +86 -107
- data/lib/paperclip/attachment_options.rb +9 -0
- data/lib/paperclip/callbacks.rb +30 -0
- data/lib/paperclip/errors.rb +27 -0
- data/lib/paperclip/geometry.rb +6 -4
- data/lib/paperclip/glue.rb +23 -0
- data/lib/paperclip/helpers.rb +71 -0
- data/lib/paperclip/instance_methods.rb +35 -0
- data/lib/paperclip/interpolations.rb +4 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +69 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +81 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -0
- data/lib/paperclip/io_adapters/nil_adapter.rb +34 -0
- data/lib/paperclip/io_adapters/registry.rb +32 -0
- data/lib/paperclip/io_adapters/stringio_adapter.rb +64 -0
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +63 -0
- data/lib/paperclip/locales/en.yml +17 -0
- data/lib/paperclip/logger.rb +21 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +5 -5
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +7 -7
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -11
- data/lib/paperclip/missing_attachment_styles.rb +6 -9
- data/lib/paperclip/processor.rb +32 -17
- data/lib/paperclip/railtie.rb +13 -17
- data/lib/paperclip/storage/filesystem.rb +4 -13
- data/lib/paperclip/storage/fog.rb +33 -24
- data/lib/paperclip/storage/s3.rb +36 -28
- data/lib/paperclip/tempfile.rb +41 -0
- data/lib/paperclip/thumbnail.rb +2 -3
- data/lib/paperclip/validators.rb +45 -0
- data/lib/paperclip/validators/attachment_content_type_validator.rb +54 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +26 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +102 -0
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +4 -12
- data/paperclip.gemspec +15 -5
- data/test/adapter_registry_test.rb +32 -0
- data/test/attachment_adapter_test.rb +51 -0
- data/test/attachment_options_test.rb +27 -0
- data/test/attachment_test.rb +130 -46
- data/test/file_adapter_test.rb +88 -0
- data/test/generator_test.rb +78 -0
- data/test/geometry_test.rb +5 -5
- data/test/helper.rb +21 -22
- data/test/identity_adapter_test.rb +8 -0
- data/test/integration_test.rb +55 -102
- data/test/interpolations_test.rb +15 -5
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +23 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +21 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +37 -2
- data/test/nil_adapter_test.rb +25 -0
- data/test/paperclip_missing_attachment_styles_test.rb +16 -0
- data/test/paperclip_test.rb +34 -183
- data/test/storage/filesystem_test.rb +27 -27
- data/test/storage/fog_test.rb +68 -12
- data/test/storage/s3_live_test.rb +79 -38
- data/test/storage/s3_test.rb +204 -34
- data/test/stringio_adapter_test.rb +42 -0
- data/test/thumbnail_test.rb +29 -8
- data/test/uploaded_file_adapter_test.rb +98 -0
- data/test/url_generator_test.rb +8 -8
- data/test/validators/attachment_content_type_validator_test.rb +192 -0
- data/test/validators/attachment_presence_validator_test.rb +85 -0
- data/test/validators/attachment_size_validator_test.rb +207 -0
- data/test/validators_test.rb +25 -0
- metadata +166 -59
- data/generators/paperclip/USAGE +0 -5
- data/generators/paperclip/paperclip_generator.rb +0 -27
- data/generators/paperclip/templates/paperclip_migration.rb.erb +0 -19
- data/init.rb +0 -4
- data/lib/paperclip/callback_compatibility.rb +0 -61
- data/lib/paperclip/iostream.rb +0 -45
- data/lib/paperclip/upfile.rb +0 -62
- data/rails/init.rb +0 -2
- data/test/.gitignore +0 -1
- data/test/fixtures/question?mark.png +0 -0
- data/test/iostream_test.rb +0 -71
- data/test/upfile_test.rb +0 -53
@@ -0,0 +1,41 @@
|
|
1
|
+
module Paperclip
|
2
|
+
# Overriding some implementation of Tempfile
|
3
|
+
class Tempfile < ::Tempfile
|
4
|
+
# Due to how ImageMagick handles its image format conversion and how
|
5
|
+
# Tempfile handles its naming scheme, it is necessary to override how
|
6
|
+
# Tempfile makes # its names so as to allow for file extensions. Idea
|
7
|
+
# taken from the comments on this blog post:
|
8
|
+
# http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
|
9
|
+
#
|
10
|
+
# This is Ruby 1.8.7's implementation.
|
11
|
+
def make_tmpname(basename, n)
|
12
|
+
if RUBY_PLATFORM =~ /java/
|
13
|
+
case basename
|
14
|
+
when Array
|
15
|
+
prefix, suffix = *basename
|
16
|
+
else
|
17
|
+
prefix, suffix = basename, ''
|
18
|
+
end
|
19
|
+
|
20
|
+
t = Time.now.strftime("%y%m%d")
|
21
|
+
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module TempfileEncoding
|
29
|
+
# This overrides Tempfile#binmode to make sure that the extenal encoding
|
30
|
+
# for binary mode is ASCII-8BIT. This behavior is what's in CRuby, but not
|
31
|
+
# in JRuby
|
32
|
+
def binmode
|
33
|
+
set_encoding('ASCII-8BIT')
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if RUBY_PLATFORM =~ /java/
|
40
|
+
::Tempfile.send :include, Paperclip::TempfileEncoding
|
41
|
+
end
|
data/lib/paperclip/thumbnail.rb
CHANGED
@@ -44,7 +44,6 @@ module Paperclip
|
|
44
44
|
|
45
45
|
@current_format = File.extname(@file.path)
|
46
46
|
@basename = File.basename(@file.path, @current_format)
|
47
|
-
|
48
47
|
end
|
49
48
|
|
50
49
|
# Returns true if the +target_geometry+ is meant to crop.
|
@@ -76,9 +75,9 @@ module Paperclip
|
|
76
75
|
|
77
76
|
success = Paperclip.run("convert", parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path))
|
78
77
|
rescue Cocaine::ExitStatusError => e
|
79
|
-
raise
|
78
|
+
raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
|
80
79
|
rescue Cocaine::CommandNotFoundError => e
|
81
|
-
raise Paperclip::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
|
80
|
+
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
|
82
81
|
end
|
83
82
|
|
84
83
|
dst
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'paperclip/validators/attachment_content_type_validator'
|
3
|
+
require 'paperclip/validators/attachment_presence_validator'
|
4
|
+
require 'paperclip/validators/attachment_size_validator'
|
5
|
+
|
6
|
+
module Paperclip
|
7
|
+
module Validators
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
extend HelperMethods
|
12
|
+
include HelperMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
# This method is a shortcut to validator classes that is in
|
17
|
+
# "Attachment...Validator" format. It is almost the same thing as the
|
18
|
+
# +validates+ method that shipped with Rails, but this is customized to
|
19
|
+
# be using with attachment validators. This is helpful when you're using
|
20
|
+
# multiple attachment validators on a single attachment.
|
21
|
+
#
|
22
|
+
# Example of using the validator:
|
23
|
+
#
|
24
|
+
# validates_attachment :avatar, :presence => true,
|
25
|
+
# :content_type => { :content_type => "image/jpg" },
|
26
|
+
# :size => { :in => 0..10.kilobytes }
|
27
|
+
#
|
28
|
+
def validates_attachment(*attributes)
|
29
|
+
options = attributes.extract_options!.dup
|
30
|
+
|
31
|
+
Paperclip::Validators.constants.each do |constant|
|
32
|
+
if constant.to_s =~ /^Attachment(.+)Validator$/
|
33
|
+
validator_kind = $1.underscore.to_sym
|
34
|
+
|
35
|
+
if options.has_key?(validator_kind)
|
36
|
+
options[:"attachment_#{validator_kind}"] = options.delete(validator_kind)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
validates(*attributes + [options])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Validators
|
3
|
+
class AttachmentContentTypeValidator < ActiveModel::EachValidator
|
4
|
+
def initialize(options)
|
5
|
+
options[:allow_nil] = true unless options.has_key?(:allow_nil)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
attribute = "#{attribute}_content_type".to_sym
|
11
|
+
value = record.send(:read_attribute_for_validation, attribute)
|
12
|
+
allowed_types = [options[:content_type]].flatten
|
13
|
+
|
14
|
+
return if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
|
15
|
+
|
16
|
+
if allowed_types.none? { |type| type === value }
|
17
|
+
record.errors.add(attribute, :invalid, options.merge(
|
18
|
+
:types => allowed_types.join(', ')
|
19
|
+
))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_validity!
|
24
|
+
unless options.has_key?(:content_type)
|
25
|
+
raise ArgumentError, "You must pass in :content_type to the validator"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module HelperMethods
|
31
|
+
# Places ActiveRecord-style validations on the content type of the file
|
32
|
+
# assigned. The possible options are:
|
33
|
+
# * +content_type+: Allowed content types. Can be a single content type
|
34
|
+
# or an array. Each type can be a String or a Regexp. It should be
|
35
|
+
# noted that Internet Explorer uploads files with content_types that you
|
36
|
+
# may not expect. For example, JPEG images are given image/pjpeg and
|
37
|
+
# PNGs are image/x-png, so keep that in mind when determining how you
|
38
|
+
# match. Allows all by default.
|
39
|
+
# * +message+: The message to display when the uploaded file has an invalid
|
40
|
+
# content type.
|
41
|
+
# * +if+: A lambda or name of an instance method. Validation will only
|
42
|
+
# be run is this lambda or method returns true.
|
43
|
+
# * +unless+: Same as +if+ but validates if lambda or method returns false.
|
44
|
+
# NOTE: If you do not specify an [attachment]_content_type field on your
|
45
|
+
# model, content_type validation will work _ONLY upon assignment_ and
|
46
|
+
# re-validation after the instance has been reloaded will always succeed.
|
47
|
+
# You'll still need to have a virtual attribute (created by +attr_accessor+)
|
48
|
+
# name +[attachment]_content_type+ to be able to use this validator.
|
49
|
+
def validates_attachment_content_type(*attr_names)
|
50
|
+
validates_with AttachmentContentTypeValidator, _merge_attributes(attr_names)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_model/validations/presence'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
module Validators
|
5
|
+
class AttachmentPresenceValidator < ActiveModel::Validations::PresenceValidator
|
6
|
+
def validate(record)
|
7
|
+
[attributes].flatten.map do |attribute|
|
8
|
+
if record.send(:read_attribute_for_validation, "#{attribute}_file_name").blank?
|
9
|
+
record.errors.add(attribute, :blank, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module HelperMethods
|
16
|
+
# Places ActiveRecord-style validations on the presence of a file.
|
17
|
+
# Options:
|
18
|
+
# * +if+: A lambda or name of an instance method. Validation will only
|
19
|
+
# be run if this lambda or method returns true.
|
20
|
+
# * +unless+: Same as +if+ but validates if lambda or method returns false.
|
21
|
+
def validates_attachment_presence(*attr_names)
|
22
|
+
validates_with AttachmentPresenceValidator, _merge_attributes(attr_names)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'active_model/validations/numericality'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
module Validators
|
5
|
+
class AttachmentSizeValidator < ActiveModel::Validations::NumericalityValidator
|
6
|
+
AVAILABLE_CHECKS = [:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to]
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
extract_options(options)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate_each(record, attr_name, value)
|
14
|
+
attr_name = "#{attr_name}_file_size".to_sym
|
15
|
+
value = record.send(:read_attribute_for_validation, attr_name)
|
16
|
+
|
17
|
+
unless value.blank?
|
18
|
+
options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
|
19
|
+
option_value = option_value.call(record) if option_value.is_a?(Proc)
|
20
|
+
option_value = extract_option_value(option, option_value)
|
21
|
+
|
22
|
+
unless value.send(CHECKS[option], option_value)
|
23
|
+
error_message_key = options[:in] ? :in_between : option
|
24
|
+
record.errors.add(attr_name, error_message_key, filtered_options(value).merge(
|
25
|
+
:min => min_value_in_human_size(record),
|
26
|
+
:max => max_value_in_human_size(record),
|
27
|
+
:count => human_size(option_value)
|
28
|
+
))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_validity!
|
35
|
+
unless (AVAILABLE_CHECKS + [:in]).any? { |argument| options.has_key?(argument) }
|
36
|
+
raise ArgumentError, "You must pass either :less_than, :greater_than, or :in to the validator"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def extract_options(options)
|
43
|
+
if range = options[:in]
|
44
|
+
if !options[:in].respond_to?(:call)
|
45
|
+
options[:less_than_or_equal_to] = range.max
|
46
|
+
options[:greater_than_or_equal_to] = range.min
|
47
|
+
else
|
48
|
+
options[:less_than_or_equal_to] = range
|
49
|
+
options[:greater_than_or_equal_to] = range
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_option_value(option, option_value)
|
55
|
+
if option_value.is_a?(Range)
|
56
|
+
if [:less_than, :less_than_or_equal_to].include?(option)
|
57
|
+
option_value.max
|
58
|
+
else
|
59
|
+
option_value.min
|
60
|
+
end
|
61
|
+
else
|
62
|
+
option_value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def human_size(size)
|
67
|
+
storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true)
|
68
|
+
unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => size.to_i, :raise => true)
|
69
|
+
storage_units_format.gsub(/%n/, size.to_i.to_s).gsub(/%u/, unit).html_safe
|
70
|
+
end
|
71
|
+
|
72
|
+
def min_value_in_human_size(record)
|
73
|
+
value = options[:greater_than_or_equal_to] || options[:greater_than]
|
74
|
+
value = value.call(record) if value.respond_to?(:call)
|
75
|
+
value = value.min if value.respond_to?(:min)
|
76
|
+
human_size(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
def max_value_in_human_size(record)
|
80
|
+
value = options[:less_than_or_equal_to] || options[:less_than]
|
81
|
+
value = value.call(record) if value.respond_to?(:call)
|
82
|
+
value = value.max if value.respond_to?(:max)
|
83
|
+
human_size(value)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module HelperMethods
|
88
|
+
# Places ActiveRecord-style validations on the size of the file assigned. The
|
89
|
+
# possible options are:
|
90
|
+
# * +in+: a Range of bytes (i.e. +1..1.megabyte+),
|
91
|
+
# * +less_than+: equivalent to :in => 0..options[:less_than]
|
92
|
+
# * +greater_than+: equivalent to :in => options[:greater_than]..Infinity
|
93
|
+
# * +message+: error message to display, use :min and :max as replacements
|
94
|
+
# * +if+: A lambda or name of an instance method. Validation will only
|
95
|
+
# be run if this lambda or method returns true.
|
96
|
+
# * +unless+: Same as +if+ but validates if lambda or method returns false.
|
97
|
+
def validates_attachment_size(*attr_names)
|
98
|
+
validates_with AttachmentSizeValidator, _merge_attributes(attr_names)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/paperclip/version.rb
CHANGED
data/lib/tasks/paperclip.rake
CHANGED
@@ -10,7 +10,7 @@ module Paperclip
|
|
10
10
|
klass = Paperclip.class_for(klass.to_s)
|
11
11
|
name = ENV['ATTACHMENT'] || ENV['attachment']
|
12
12
|
raise "Class #{klass.name} has no attachments specified" unless klass.respond_to?(:attachment_definitions)
|
13
|
-
if !name.blank? && klass.attachment_definitions.keys.include?(name)
|
13
|
+
if !name.blank? && klass.attachment_definitions.keys.map(&:to_s).include?(name.to_s)
|
14
14
|
[ name ]
|
15
15
|
else
|
16
16
|
klass.attachment_definitions.keys
|
@@ -45,15 +45,11 @@ namespace :paperclip do
|
|
45
45
|
names = Paperclip::Task.obtain_attachments(klass)
|
46
46
|
names.each do |name|
|
47
47
|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
|
48
|
-
if file = instance.send(name)
|
48
|
+
if file = Paperclip.io_adapters.for(instance.send(name))
|
49
49
|
instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip)
|
50
50
|
instance.send("#{name}_content_type=", file.content_type.to_s.strip)
|
51
51
|
instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size")
|
52
|
-
|
53
|
-
instance.save(:validate => false)
|
54
|
-
else
|
55
|
-
instance.save(false)
|
56
|
-
end
|
52
|
+
instance.save(:validate => false)
|
57
53
|
else
|
58
54
|
true
|
59
55
|
end
|
@@ -88,11 +84,7 @@ namespace :paperclip do
|
|
88
84
|
attributes = %w(file_size file_name content_type).map{ |suffix| "#{name}_#{suffix}".to_sym }
|
89
85
|
if attributes.any?{ |attribute| instance.errors[attribute].present? }
|
90
86
|
instance.send("#{name}=", nil)
|
91
|
-
|
92
|
-
instance.save(:validate => false)
|
93
|
-
else
|
94
|
-
instance.save(false)
|
95
|
-
end
|
87
|
+
instance.save(:validate => false)
|
96
88
|
end
|
97
89
|
end
|
98
90
|
end
|
data/paperclip.gemspec
CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.version = Paperclip::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.author = "Jon Yurek"
|
9
|
-
s.email = ["sean@fakecoolguys.com"]
|
9
|
+
s.email = ["sean@fakecoolguys.com", "jyurek@thoughtbot.com"]
|
10
10
|
s.homepage = "https://github.com/thoughtbot/paperclip"
|
11
11
|
s.summary = "File attachments as attributes for ActiveRecord"
|
12
|
-
s.description = "
|
12
|
+
s.description = "Easy upload management for ActiveRecord"
|
13
13
|
|
14
14
|
s.rubyforge_project = "paperclip"
|
15
15
|
|
@@ -18,24 +18,34 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
if File.exists?('UPGRADING')
|
22
|
+
s.post_install_message = File.read("UPGRADING")
|
23
|
+
end
|
24
|
+
|
21
25
|
s.requirements << "ImageMagick"
|
26
|
+
s.required_ruby_version = ">= 1.9.2"
|
22
27
|
|
23
|
-
s.add_dependency('activerecord', '>=
|
24
|
-
s.add_dependency('
|
28
|
+
s.add_dependency('activerecord', '>= 3.0.0')
|
29
|
+
s.add_dependency('activemodel', '>= 3.0.0')
|
30
|
+
s.add_dependency('activesupport', '>= 3.0.0')
|
25
31
|
s.add_dependency('cocaine', '>= 0.0.2')
|
26
32
|
s.add_dependency('mime-types')
|
27
33
|
|
28
34
|
s.add_development_dependency('shoulda')
|
29
|
-
s.add_development_dependency('appraisal'
|
35
|
+
s.add_development_dependency('appraisal')
|
30
36
|
s.add_development_dependency('mocha')
|
31
37
|
s.add_development_dependency('aws-sdk')
|
38
|
+
s.add_development_dependency('bourne')
|
32
39
|
s.add_development_dependency('sqlite3', '~> 1.3.4')
|
33
40
|
s.add_development_dependency('cucumber', '~> 1.1.0')
|
34
41
|
s.add_development_dependency('aruba')
|
42
|
+
s.add_development_dependency('nokogiri')
|
35
43
|
s.add_development_dependency('capybara')
|
36
44
|
s.add_development_dependency('bundler')
|
37
45
|
s.add_development_dependency('cocaine', '~> 0.2')
|
38
46
|
s.add_development_dependency('fog')
|
47
|
+
s.add_development_dependency('pry')
|
48
|
+
s.add_development_dependency('launchy')
|
39
49
|
s.add_development_dependency('rake')
|
40
50
|
s.add_development_dependency('fakeweb')
|
41
51
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class AdapterRegistryTest < Test::Unit::TestCase
|
4
|
+
context "for" do
|
5
|
+
setup do
|
6
|
+
class AdapterTest
|
7
|
+
def initialize(target); end
|
8
|
+
end
|
9
|
+
@subject = Paperclip::AdapterRegistry.new
|
10
|
+
@subject.register(AdapterTest){|t| Symbol === t }
|
11
|
+
end
|
12
|
+
should "return the class registered for the adapted type" do
|
13
|
+
assert_equal AdapterTest, @subject.for(:target).class
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "registered?" do
|
18
|
+
setup do
|
19
|
+
class AdapterTest
|
20
|
+
def initialize(target); end
|
21
|
+
end
|
22
|
+
@subject = Paperclip::AdapterRegistry.new
|
23
|
+
@subject.register(AdapterTest){|t| Symbol === t }
|
24
|
+
end
|
25
|
+
should "return true when the class of this adapter has been registered" do
|
26
|
+
assert @subject.registered?(AdapterTest.new(:target))
|
27
|
+
end
|
28
|
+
should "return false when the adapter has not been registered" do
|
29
|
+
assert ! @subject.registered?(Object)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class AttachmentAdapterTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
rebuild_model :path => "tmp/:class/:attachment/:style/:filename"
|
6
|
+
@attachment = Dummy.new.avatar
|
7
|
+
@file = File.new(fixture_file("5k.png"))
|
8
|
+
@file.binmode
|
9
|
+
|
10
|
+
@attachment.assign(@file)
|
11
|
+
@attachment.save
|
12
|
+
@subject = Paperclip.io_adapters.for(@attachment)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@file.close
|
17
|
+
end
|
18
|
+
|
19
|
+
should "get the right filename" do
|
20
|
+
assert_equal "5k.png", @subject.original_filename
|
21
|
+
end
|
22
|
+
|
23
|
+
should "force binmode on tempfile" do
|
24
|
+
assert @subject.instance_variable_get("@tempfile").binmode?
|
25
|
+
end
|
26
|
+
|
27
|
+
should "get the content type" do
|
28
|
+
assert_equal "image/png", @subject.content_type
|
29
|
+
end
|
30
|
+
|
31
|
+
should "get the file's size" do
|
32
|
+
assert_equal 4456, @subject.size
|
33
|
+
end
|
34
|
+
|
35
|
+
should "return false for a call to nil?" do
|
36
|
+
assert ! @subject.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
should "generate a MD5 hash of the contents" do
|
40
|
+
expected = Digest::MD5.file(@file.path).to_s
|
41
|
+
assert_equal expected, @subject.fingerprint
|
42
|
+
end
|
43
|
+
|
44
|
+
should "read the contents of the file" do
|
45
|
+
expected = @file.read
|
46
|
+
actual = @subject.read
|
47
|
+
assert expected.length > 0
|
48
|
+
assert_equal expected.length, actual.length
|
49
|
+
assert_equal expected, actual
|
50
|
+
end
|
51
|
+
end
|