paperclip 3.4.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +3 -0
- data/.gitignore +0 -6
- data/.hound.yml +1055 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +19 -12
- data/Appraisals +4 -11
- data/CONTRIBUTING.md +29 -13
- data/Gemfile +13 -4
- data/LICENSE +1 -3
- data/MIGRATING-ES.md +317 -0
- data/MIGRATING.md +375 -0
- data/NEWS +390 -71
- data/README.md +607 -152
- data/RELEASING.md +17 -0
- data/Rakefile +6 -8
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +34 -21
- data/features/migration.feature +0 -24
- data/features/rake_tasks.feature +2 -3
- data/features/step_definitions/attachment_steps.rb +44 -36
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +125 -26
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/env.rb +3 -2
- data/features/support/fakeweb.rb +4 -1
- data/features/support/file_helpers.rb +12 -2
- data/features/support/fixtures/gemfile.txt +1 -1
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +4 -11
- data/gemfiles/4.2.gemfile +17 -0
- data/gemfiles/5.0.gemfile +17 -0
- data/lib/generators/paperclip/paperclip_generator.rb +9 -3
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +2 -2
- data/lib/paperclip/attachment.rb +215 -82
- data/lib/paperclip/attachment_registry.rb +60 -0
- data/lib/paperclip/callbacks.rb +13 -1
- data/lib/paperclip/content_type_detector.rb +48 -24
- data/lib/paperclip/errors.rb +8 -1
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/filename_cleaner.rb +15 -0
- data/lib/paperclip/geometry_detector_factory.rb +12 -5
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -2
- data/lib/paperclip/has_attached_file.rb +115 -0
- data/lib/paperclip/helpers.rb +15 -20
- data/lib/paperclip/interpolations/plural_cache.rb +18 -0
- data/lib/paperclip/interpolations.rb +36 -14
- data/lib/paperclip/io_adapters/abstract_adapter.rb +42 -5
- data/lib/paperclip/io_adapters/attachment_adapter.rb +20 -9
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +22 -0
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +19 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +13 -7
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +16 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +15 -16
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +11 -7
- data/lib/paperclip/io_adapters/uri_adapter.rb +43 -19
- data/lib/paperclip/locales/en.yml +1 -0
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +3 -6
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +7 -2
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
- data/lib/paperclip/matchers.rb +1 -1
- data/lib/paperclip/media_type_spoof_detector.rb +93 -0
- data/lib/paperclip/missing_attachment_styles.rb +11 -16
- data/lib/paperclip/processor.rb +15 -43
- data/lib/paperclip/processor_helpers.rb +50 -0
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/schema.rb +10 -8
- data/lib/paperclip/storage/filesystem.rb +20 -5
- data/lib/paperclip/storage/fog.rb +49 -23
- data/lib/paperclip/storage/s3.rb +153 -82
- data/lib/paperclip/style.rb +8 -3
- data/lib/paperclip/tempfile_factory.rb +6 -4
- data/lib/paperclip/thumbnail.rb +35 -19
- data/lib/paperclip/url_generator.rb +26 -14
- data/lib/paperclip/validators/attachment_content_type_validator.rb +15 -2
- data/lib/paperclip/validators/attachment_file_name_validator.rb +80 -0
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +29 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +12 -8
- data/lib/paperclip/validators/attachment_size_validator.rb +17 -10
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +31 -0
- data/lib/paperclip/validators.rb +31 -3
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +41 -55
- data/lib/tasks/paperclip.rake +56 -9
- data/paperclip.gemspec +18 -17
- data/shoulda_macros/paperclip.rb +13 -3
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/spec/paperclip/attachment_processing_spec.rb +79 -0
- data/spec/paperclip/attachment_registry_spec.rb +158 -0
- data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +597 -389
- data/spec/paperclip/content_type_detector_spec.rb +48 -0
- data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
- data/spec/paperclip/filename_cleaner_spec.rb +13 -0
- data/spec/paperclip/geometry_detector_spec.rb +39 -0
- data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
- data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +50 -52
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +158 -0
- data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +179 -199
- data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +79 -46
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +160 -0
- data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +54 -25
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +89 -0
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +131 -0
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +138 -0
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
- data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +12 -9
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +64 -0
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +146 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +220 -0
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +109 -0
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +120 -0
- data/spec/paperclip/meta_class_spec.rb +30 -0
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
- data/spec/paperclip/paperclip_spec.rb +192 -0
- data/spec/paperclip/plural_cache_spec.rb +37 -0
- data/spec/paperclip/processor_helpers_spec.rb +57 -0
- data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +7 -7
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/spec/paperclip/rake_spec.rb +103 -0
- data/spec/paperclip/schema_spec.rb +248 -0
- data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
- data/spec/paperclip/storage/fog_spec.rb +566 -0
- data/spec/paperclip/storage/s3_live_spec.rb +188 -0
- data/spec/paperclip/storage/s3_spec.rb +1693 -0
- data/spec/paperclip/style_spec.rb +254 -0
- data/spec/paperclip/tempfile_factory_spec.rb +33 -0
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +186 -141
- data/spec/paperclip/url_generator_spec.rb +221 -0
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
- data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +20 -20
- data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +87 -59
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +52 -0
- data/spec/paperclip/validators_spec.rb +164 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/assertions.rb +82 -0
- data/spec/support/fake_model.rb +25 -0
- data/spec/support/fake_rails.rb +12 -0
- data/spec/support/fixtures/empty.html +1 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/matchers/accept.rb +5 -0
- data/spec/support/matchers/exist.rb +5 -0
- data/spec/support/matchers/have_column.rb +23 -0
- data/{test → spec}/support/mock_attachment.rb +2 -0
- data/{test → spec}/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +68 -0
- data/spec/support/reporting.rb +11 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +395 -346
- data/Gemfile.lock +0 -200
- data/RUNNING_TESTS.md +0 -4
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.0.gemfile +0 -11
- data/gemfiles/3.1.gemfile +0 -11
- data/gemfiles/3.2.gemfile +0 -11
- data/lib/paperclip/attachment_options.rb +0 -9
- data/lib/paperclip/instance_methods.rb +0 -35
- data/test/attachment_options_test.rb +0 -27
- data/test/attachment_processing_test.rb +0 -29
- data/test/content_type_detector_test.rb +0 -40
- data/test/file_command_content_type_detector_test.rb +0 -25
- data/test/generator_test.rb +0 -80
- data/test/geometry_detector_test.rb +0 -24
- data/test/helper.rb +0 -199
- data/test/io_adapters/abstract_adapter_test.rb +0 -50
- data/test/io_adapters/file_adapter_test.rb +0 -100
- data/test/io_adapters/identity_adapter_test.rb +0 -8
- data/test/io_adapters/stringio_adapter_test.rb +0 -51
- data/test/io_adapters/uploaded_file_adapter_test.rb +0 -123
- data/test/io_adapters/uri_adapter_test.rb +0 -86
- data/test/matchers/have_attached_file_matcher_test.rb +0 -24
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -110
- data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -47
- data/test/matchers/validate_attachment_size_matcher_test.rb +0 -86
- data/test/meta_class_test.rb +0 -32
- data/test/paperclip_missing_attachment_styles_test.rb +0 -94
- data/test/paperclip_test.rb +0 -259
- data/test/schema_test.rb +0 -200
- data/test/storage/fog_test.rb +0 -453
- data/test/storage/s3_live_test.rb +0 -179
- data/test/storage/s3_test.rb +0 -1236
- data/test/style_test.rb +0 -213
- data/test/support/mock_model.rb +0 -2
- data/test/tempfile_factory_test.rb +0 -13
- data/test/url_generator_test.rb +0 -187
- data/test/validators/attachment_content_type_validator_test.rb +0 -292
- data/test/validators_test.rb +0 -25
- /data/{test → spec}/database.yml +0 -0
- /data/{test → spec/support}/fixtures/12k.png +0 -0
- /data/{test → spec/support}/fixtures/50x50.png +0 -0
- /data/{test → spec/support}/fixtures/5k.png +0 -0
- /data/{test → spec/support}/fixtures/animated +0 -0
- /data/{test → spec/support}/fixtures/animated.gif +0 -0
- /data/{test → spec/support}/fixtures/animated.unknown +0 -0
- /data/{test → spec/support}/fixtures/bad.png +0 -0
- /data/{test → spec/support}/fixtures/fog.yml +0 -0
- /data/{test → spec/support}/fixtures/rotated.jpg +0 -0
- /data/{test → spec/support}/fixtures/s3.yml +0 -0
- /data/{test → spec/support}/fixtures/spaced file.png +0 -0
- /data/{test → spec/support}/fixtures/text.txt +0 -0
- /data/{test → spec/support}/fixtures/twopage.pdf +0 -0
- /data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
- /data/{test → spec}/support/mock_interpolator.rb +0 -0
data/test/helper.rb
DELETED
@@ -1,199 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'tempfile'
|
3
|
-
require 'pathname'
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
require 'shoulda'
|
7
|
-
require 'mocha'
|
8
|
-
require 'bourne'
|
9
|
-
|
10
|
-
require 'active_record'
|
11
|
-
require 'active_record/version'
|
12
|
-
require 'active_support'
|
13
|
-
require 'active_support/core_ext'
|
14
|
-
require 'mime/types'
|
15
|
-
require 'pathname'
|
16
|
-
require 'ostruct'
|
17
|
-
require 'pry'
|
18
|
-
|
19
|
-
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
|
20
|
-
|
21
|
-
`ruby -e 'exit 0'` # Prime $? with a value.
|
22
|
-
|
23
|
-
begin
|
24
|
-
require 'ruby-debug'
|
25
|
-
rescue LoadError => e
|
26
|
-
puts "debugger disabled"
|
27
|
-
end
|
28
|
-
|
29
|
-
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
30
|
-
|
31
|
-
class Test::Unit::TestCase
|
32
|
-
def setup
|
33
|
-
silence_warnings do
|
34
|
-
Object.const_set(:Rails, stub('Rails'))
|
35
|
-
Rails.stubs(:root).returns(Pathname.new(ROOT).join('tmp'))
|
36
|
-
Rails.stubs(:env).returns('test')
|
37
|
-
Rails.stubs(:const_defined?).with(:Railtie).returns(false)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
$LOAD_PATH << File.join(ROOT, 'lib')
|
43
|
-
$LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
|
44
|
-
|
45
|
-
require File.join(ROOT, 'lib', 'paperclip.rb')
|
46
|
-
|
47
|
-
require './shoulda_macros/paperclip'
|
48
|
-
|
49
|
-
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
50
|
-
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
51
|
-
ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
|
52
|
-
ActiveRecord::Base.establish_connection(config['test'])
|
53
|
-
Paperclip.options[:logger] = ActiveRecord::Base.logger
|
54
|
-
|
55
|
-
def require_everything_in_directory(directory_name)
|
56
|
-
Dir[File.join(File.dirname(__FILE__), directory_name, '*')].each do |f|
|
57
|
-
require f
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
require_everything_in_directory('support')
|
62
|
-
|
63
|
-
def reset_class class_name
|
64
|
-
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
65
|
-
Object.send(:remove_const, class_name) rescue nil
|
66
|
-
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
|
67
|
-
|
68
|
-
klass.class_eval do
|
69
|
-
include Paperclip::Glue
|
70
|
-
end
|
71
|
-
|
72
|
-
klass.reset_column_information
|
73
|
-
klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!)
|
74
|
-
klass.connection.schema_cache.clear_table_cache!(klass.table_name) if klass.connection.respond_to?(:schema_cache)
|
75
|
-
klass
|
76
|
-
end
|
77
|
-
|
78
|
-
def reset_table table_name, &block
|
79
|
-
block ||= lambda { |table| true }
|
80
|
-
ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
|
81
|
-
end
|
82
|
-
|
83
|
-
def modify_table table_name, &block
|
84
|
-
ActiveRecord::Base.connection.change_table :dummies, &block
|
85
|
-
end
|
86
|
-
|
87
|
-
def rebuild_model options = {}
|
88
|
-
ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
|
89
|
-
table.column :title, :string
|
90
|
-
table.column :other, :string
|
91
|
-
table.column :avatar_file_name, :string
|
92
|
-
table.column :avatar_content_type, :string
|
93
|
-
table.column :avatar_file_size, :integer
|
94
|
-
table.column :avatar_updated_at, :datetime
|
95
|
-
table.column :avatar_fingerprint, :string
|
96
|
-
end
|
97
|
-
rebuild_class options
|
98
|
-
end
|
99
|
-
|
100
|
-
def rebuild_class options = {}
|
101
|
-
reset_class("Dummy").tap do |klass|
|
102
|
-
klass.has_attached_file :avatar, options
|
103
|
-
Paperclip.reset_duplicate_clash_check!
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def rebuild_meta_class_of obj, options = {}
|
108
|
-
(class << obj; self; end).tap do |metaklass|
|
109
|
-
metaklass.has_attached_file :avatar, options
|
110
|
-
Paperclip.reset_duplicate_clash_check!
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
class FakeModel
|
115
|
-
attr_accessor :avatar_file_name,
|
116
|
-
:avatar_file_size,
|
117
|
-
:avatar_updated_at,
|
118
|
-
:avatar_content_type,
|
119
|
-
:avatar_fingerprint,
|
120
|
-
:id
|
121
|
-
|
122
|
-
def errors
|
123
|
-
@errors ||= []
|
124
|
-
end
|
125
|
-
|
126
|
-
def run_paperclip_callbacks name, *args
|
127
|
-
end
|
128
|
-
|
129
|
-
def valid?
|
130
|
-
errors.empty?
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def attachment(options={})
|
135
|
-
Paperclip::Attachment.new(:avatar, FakeModel.new, options)
|
136
|
-
end
|
137
|
-
|
138
|
-
def silence_warnings
|
139
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
140
|
-
yield
|
141
|
-
ensure
|
142
|
-
$VERBOSE = old_verbose
|
143
|
-
end
|
144
|
-
|
145
|
-
def should_accept_dummy_class
|
146
|
-
should "accept the class" do
|
147
|
-
assert_accepts @matcher, @dummy_class
|
148
|
-
end
|
149
|
-
|
150
|
-
should "accept an instance of that class" do
|
151
|
-
assert_accepts @matcher, @dummy_class.new
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def should_reject_dummy_class
|
156
|
-
should "reject the class" do
|
157
|
-
assert_rejects @matcher, @dummy_class
|
158
|
-
end
|
159
|
-
|
160
|
-
should "reject an instance of that class" do
|
161
|
-
assert_rejects @matcher, @dummy_class.new
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def with_exitstatus_returning(code)
|
166
|
-
saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
|
167
|
-
begin
|
168
|
-
`ruby -e 'exit #{code.to_i}'`
|
169
|
-
yield
|
170
|
-
ensure
|
171
|
-
`ruby -e 'exit #{saved_exitstatus.to_i}'`
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def fixture_file(filename)
|
176
|
-
File.join(File.dirname(__FILE__), 'fixtures', filename)
|
177
|
-
end
|
178
|
-
|
179
|
-
def assert_success_response(url)
|
180
|
-
Net::HTTP.get_response(URI.parse(url)) do |response|
|
181
|
-
assert_equal "200", response.code,
|
182
|
-
"Expected HTTP response code 200, got #{response.code}"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def assert_not_found_response(url)
|
187
|
-
Net::HTTP.get_response(URI.parse(url)) do |response|
|
188
|
-
assert_equal "404", response.code,
|
189
|
-
"Expected HTTP response code 404, got #{response.code}"
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def assert_file_exists(path)
|
194
|
-
assert File.exists?(path), %(Expect "#{path}" to be exists.)
|
195
|
-
end
|
196
|
-
|
197
|
-
def assert_file_not_exists(path)
|
198
|
-
assert !File.exists?(path), %(Expect "#{path}" to not exists.)
|
199
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class AbstractAdapterTest < Test::Unit::TestCase
|
4
|
-
class TestAdapter < Paperclip::AbstractAdapter
|
5
|
-
attr_accessor :tempfile
|
6
|
-
|
7
|
-
def content_type
|
8
|
-
Paperclip::ContentTypeDetector.new(path).detect
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "content type from file command" do
|
13
|
-
setup do
|
14
|
-
@adapter = TestAdapter.new
|
15
|
-
@adapter.stubs(:path).returns("image.png")
|
16
|
-
end
|
17
|
-
|
18
|
-
should "return the content type without newline" do
|
19
|
-
assert_equal "image/png", @adapter.content_type
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "nil?" do
|
24
|
-
should "return false" do
|
25
|
-
assert !TestAdapter.new.nil?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "delegation" do
|
30
|
-
setup do
|
31
|
-
@adapter = TestAdapter.new
|
32
|
-
@adapter.tempfile = stub("Tempfile")
|
33
|
-
end
|
34
|
-
|
35
|
-
[:close, :closed?, :eof?, :path, :rewind, :unlink].each do |method|
|
36
|
-
should "delegate #{method} to @tempfile" do
|
37
|
-
@adapter.tempfile.stubs(method)
|
38
|
-
@adapter.public_send(method)
|
39
|
-
assert_received @adapter.tempfile, method
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'get rid of slashes and colons in filenames' do
|
45
|
-
@adapter = TestAdapter.new
|
46
|
-
@adapter.original_filename = "awesome/file:name.png"
|
47
|
-
|
48
|
-
assert_equal "awesome_file_name.png", @adapter.original_filename
|
49
|
-
end
|
50
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class FileAdapterTest < Test::Unit::TestCase
|
4
|
-
context "a new instance" do
|
5
|
-
context "with normal file" do
|
6
|
-
setup do
|
7
|
-
@file = File.new(fixture_file("5k.png"))
|
8
|
-
@file.binmode
|
9
|
-
@subject = Paperclip.io_adapters.for(@file)
|
10
|
-
end
|
11
|
-
|
12
|
-
teardown { @file.close }
|
13
|
-
|
14
|
-
should "get the right filename" do
|
15
|
-
assert_equal "5k.png", @subject.original_filename
|
16
|
-
end
|
17
|
-
|
18
|
-
should "force binmode on tempfile" do
|
19
|
-
assert @subject.instance_variable_get("@tempfile").binmode?
|
20
|
-
end
|
21
|
-
|
22
|
-
should "get the content type" do
|
23
|
-
assert_equal "image/png", @subject.content_type
|
24
|
-
end
|
25
|
-
|
26
|
-
should "return content type as a string" do
|
27
|
-
assert_kind_of String, @subject.content_type
|
28
|
-
end
|
29
|
-
|
30
|
-
should "get the file's size" do
|
31
|
-
assert_equal 4456, @subject.size
|
32
|
-
end
|
33
|
-
|
34
|
-
should "return false for a call to nil?" do
|
35
|
-
assert ! @subject.nil?
|
36
|
-
end
|
37
|
-
|
38
|
-
should "generate a MD5 hash of the contents" do
|
39
|
-
expected = Digest::MD5.file(@file.path).to_s
|
40
|
-
assert_equal expected, @subject.fingerprint
|
41
|
-
end
|
42
|
-
|
43
|
-
should "read the contents of the file" do
|
44
|
-
expected = @file.read
|
45
|
-
assert expected.length > 0
|
46
|
-
assert_equal expected, @subject.read
|
47
|
-
end
|
48
|
-
|
49
|
-
context "file with multiple possible content type" do
|
50
|
-
setup do
|
51
|
-
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')])
|
52
|
-
end
|
53
|
-
|
54
|
-
should "prefer officially registered mime type" do
|
55
|
-
assert_equal "image/png", @subject.content_type
|
56
|
-
end
|
57
|
-
|
58
|
-
should "return content type as a string" do
|
59
|
-
assert_kind_of String, @subject.content_type
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "file with multiple possible x-types but no official type" do
|
64
|
-
setup do
|
65
|
-
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-mp4'), MIME::Type.new('image/x-video')])
|
66
|
-
@subject = Paperclip.io_adapters.for(@file)
|
67
|
-
end
|
68
|
-
|
69
|
-
should "return the first" do
|
70
|
-
assert_equal "image/x-mp4", @subject.content_type
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "file with content type derived from file command on *nix" do
|
75
|
-
setup do
|
76
|
-
MIME::Types.stubs(:type_for).returns([])
|
77
|
-
Paperclip.stubs(:run).returns("application/vnd.ms-office\n")
|
78
|
-
@subject = Paperclip.io_adapters.for(@file)
|
79
|
-
end
|
80
|
-
|
81
|
-
should "return content type without newline character" do
|
82
|
-
assert_equal "application/vnd.ms-office", @subject.content_type
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "empty file" do
|
88
|
-
setup do
|
89
|
-
@file = Tempfile.new("file_adapter_test")
|
90
|
-
@subject = Paperclip.io_adapters.for(@file)
|
91
|
-
end
|
92
|
-
|
93
|
-
teardown { @file.close }
|
94
|
-
|
95
|
-
should "provide correct mime-type" do
|
96
|
-
assert_match %r{.*/x-empty}, @subject.content_type
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class StringioFileProxyTest < Test::Unit::TestCase
|
4
|
-
context "a new instance" do
|
5
|
-
setup do
|
6
|
-
@contents = "abc123"
|
7
|
-
@stringio = StringIO.new(@contents)
|
8
|
-
@subject = Paperclip.io_adapters.for(@stringio)
|
9
|
-
end
|
10
|
-
|
11
|
-
should "return a file name" do
|
12
|
-
assert_equal "stringio.txt", @subject.original_filename
|
13
|
-
end
|
14
|
-
|
15
|
-
should "return a content type" do
|
16
|
-
assert_equal "text/plain", @subject.content_type
|
17
|
-
end
|
18
|
-
|
19
|
-
should "return the size of the data" do
|
20
|
-
assert_equal 6, @subject.size
|
21
|
-
end
|
22
|
-
|
23
|
-
should "generate an MD5 hash of the contents" do
|
24
|
-
assert_equal Digest::MD5.hexdigest(@contents), @subject.fingerprint
|
25
|
-
end
|
26
|
-
|
27
|
-
should "generate correct fingerprint after read" do
|
28
|
-
fingerprint = Digest::MD5.hexdigest(@subject.read)
|
29
|
-
assert_equal fingerprint, @subject.fingerprint
|
30
|
-
end
|
31
|
-
|
32
|
-
should "generate same fingerprint" do
|
33
|
-
assert_equal @subject.fingerprint, @subject.fingerprint
|
34
|
-
end
|
35
|
-
|
36
|
-
should "return the data contained in the StringIO" do
|
37
|
-
assert_equal "abc123", @subject.read
|
38
|
-
end
|
39
|
-
|
40
|
-
should 'accept a content_type' do
|
41
|
-
@subject.content_type = 'image/png'
|
42
|
-
assert_equal 'image/png', @subject.content_type
|
43
|
-
end
|
44
|
-
|
45
|
-
should 'accept an orgiginal_filename' do
|
46
|
-
@subject.original_filename = 'image.png'
|
47
|
-
assert_equal 'image.png', @subject.original_filename
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class UploadedFileAdapterTest < Test::Unit::TestCase
|
4
|
-
context "a new instance" do
|
5
|
-
context "with UploadedFile responding to #tempfile" do
|
6
|
-
setup do
|
7
|
-
Paperclip::UploadedFileAdapter.content_type_detector = nil
|
8
|
-
|
9
|
-
class UploadedFile < OpenStruct; end
|
10
|
-
tempfile = File.new(fixture_file("5k.png"))
|
11
|
-
tempfile.binmode
|
12
|
-
|
13
|
-
@file = UploadedFile.new(
|
14
|
-
:original_filename => "5k.png",
|
15
|
-
:content_type => "image/x-png-by-browser\r",
|
16
|
-
:head => "",
|
17
|
-
:tempfile => tempfile,
|
18
|
-
:path => tempfile.path
|
19
|
-
)
|
20
|
-
@subject = Paperclip.io_adapters.for(@file)
|
21
|
-
end
|
22
|
-
|
23
|
-
should "get the right filename" do
|
24
|
-
assert_equal "5k.png", @subject.original_filename
|
25
|
-
end
|
26
|
-
|
27
|
-
should "force binmode on tempfile" do
|
28
|
-
assert @subject.instance_variable_get("@tempfile").binmode?
|
29
|
-
end
|
30
|
-
|
31
|
-
should "get the content type" do
|
32
|
-
assert_equal "image/x-png-by-browser", @subject.content_type
|
33
|
-
end
|
34
|
-
|
35
|
-
should "get the file's size" do
|
36
|
-
assert_equal 4456, @subject.size
|
37
|
-
end
|
38
|
-
|
39
|
-
should "return false for a call to nil?" do
|
40
|
-
assert ! @subject.nil?
|
41
|
-
end
|
42
|
-
|
43
|
-
should "generate a MD5 hash of the contents" do
|
44
|
-
expected = Digest::MD5.file(@file.tempfile.path).to_s
|
45
|
-
assert_equal expected, @subject.fingerprint
|
46
|
-
end
|
47
|
-
|
48
|
-
should "read the contents of the file" do
|
49
|
-
expected = @file.tempfile.read
|
50
|
-
assert expected.length > 0
|
51
|
-
assert_equal expected, @subject.read
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with UploadFile responding to #path" do
|
56
|
-
setup do
|
57
|
-
Paperclip::UploadedFileAdapter.content_type_detector = nil
|
58
|
-
|
59
|
-
class UploadedFile < OpenStruct; end
|
60
|
-
@file = UploadedFile.new(
|
61
|
-
:original_filename => "5k.png",
|
62
|
-
:content_type => "image/x-png-by-browser",
|
63
|
-
:head => "",
|
64
|
-
:path => fixture_file("5k.png")
|
65
|
-
)
|
66
|
-
@subject = Paperclip.io_adapters.for(@file)
|
67
|
-
end
|
68
|
-
|
69
|
-
should "get the right filename" do
|
70
|
-
assert_equal "5k.png", @subject.original_filename
|
71
|
-
end
|
72
|
-
|
73
|
-
should "force binmode on tempfile" do
|
74
|
-
assert @subject.instance_variable_get("@tempfile").binmode?
|
75
|
-
end
|
76
|
-
|
77
|
-
should "get the content type" do
|
78
|
-
assert_equal "image/x-png-by-browser", @subject.content_type
|
79
|
-
end
|
80
|
-
|
81
|
-
should "get the file's size" do
|
82
|
-
assert_equal 4456, @subject.size
|
83
|
-
end
|
84
|
-
|
85
|
-
should "return false for a call to nil?" do
|
86
|
-
assert ! @subject.nil?
|
87
|
-
end
|
88
|
-
|
89
|
-
should "generate a MD5 hash of the contents" do
|
90
|
-
expected = Digest::MD5.file(@file.path).to_s
|
91
|
-
assert_equal expected, @subject.fingerprint
|
92
|
-
end
|
93
|
-
|
94
|
-
should "read the contents of the file" do
|
95
|
-
expected_file = File.new(@file.path)
|
96
|
-
expected_file.binmode
|
97
|
-
expected = expected_file.read
|
98
|
-
assert expected.length > 0
|
99
|
-
assert_equal expected, @subject.read
|
100
|
-
end
|
101
|
-
|
102
|
-
context "don't trust client-given MIME type" do
|
103
|
-
setup do
|
104
|
-
Paperclip::UploadedFileAdapter.content_type_detector =
|
105
|
-
Paperclip::FileCommandContentTypeDetector
|
106
|
-
|
107
|
-
class UploadedFile < OpenStruct; end
|
108
|
-
@file = UploadedFile.new(
|
109
|
-
:original_filename => "5k.png",
|
110
|
-
:content_type => "image/x-png-by-browser",
|
111
|
-
:head => "",
|
112
|
-
:path => fixture_file("5k.png")
|
113
|
-
)
|
114
|
-
@subject = Paperclip.io_adapters.for(@file)
|
115
|
-
end
|
116
|
-
|
117
|
-
should "get the content type" do
|
118
|
-
assert_equal "image/png", @subject.content_type
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class UriProxyTest < Test::Unit::TestCase
|
4
|
-
context "a new instance" do
|
5
|
-
setup do
|
6
|
-
@open_return = StringIO.new("xxx")
|
7
|
-
@open_return.stubs(:content_type).returns("image/png")
|
8
|
-
Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(@open_return)
|
9
|
-
@uri = URI.parse("http://thoughtbot.com/images/thoughtbot-logo.png")
|
10
|
-
@subject = Paperclip.io_adapters.for(@uri)
|
11
|
-
end
|
12
|
-
|
13
|
-
should "return a file name" do
|
14
|
-
assert_equal "thoughtbot-logo.png", @subject.original_filename
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'close open handle after reading' do
|
18
|
-
assert_equal true, @open_return.closed?
|
19
|
-
end
|
20
|
-
|
21
|
-
should "return a content type" do
|
22
|
-
assert_equal "image/png", @subject.content_type
|
23
|
-
end
|
24
|
-
|
25
|
-
should "return the size of the data" do
|
26
|
-
assert_equal @open_return.size, @subject.size
|
27
|
-
end
|
28
|
-
|
29
|
-
should "generate an MD5 hash of the contents" do
|
30
|
-
assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint
|
31
|
-
end
|
32
|
-
|
33
|
-
should "generate correct fingerprint after read" do
|
34
|
-
fingerprint = Digest::MD5.hexdigest(@subject.read)
|
35
|
-
assert_equal fingerprint, @subject.fingerprint
|
36
|
-
end
|
37
|
-
|
38
|
-
should "generate same fingerprint" do
|
39
|
-
assert_equal @subject.fingerprint, @subject.fingerprint
|
40
|
-
end
|
41
|
-
|
42
|
-
should "return the data contained in the StringIO" do
|
43
|
-
assert_equal "xxx", @subject.read
|
44
|
-
end
|
45
|
-
|
46
|
-
should 'accept a content_type' do
|
47
|
-
@subject.content_type = 'image/png'
|
48
|
-
assert_equal 'image/png', @subject.content_type
|
49
|
-
end
|
50
|
-
|
51
|
-
should 'accept an orgiginal_filename' do
|
52
|
-
@subject.original_filename = 'image.png'
|
53
|
-
assert_equal 'image.png', @subject.original_filename
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
context "a directory index url" do
|
59
|
-
setup do
|
60
|
-
Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
|
61
|
-
@uri = URI.parse("http://thoughtbot.com")
|
62
|
-
@subject = Paperclip.io_adapters.for(@uri)
|
63
|
-
end
|
64
|
-
|
65
|
-
should "return a file name" do
|
66
|
-
assert_equal "index.html", @subject.original_filename
|
67
|
-
end
|
68
|
-
|
69
|
-
should "return a content type" do
|
70
|
-
assert_equal "text/html", @subject.content_type
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "a url with query params" do
|
75
|
-
setup do
|
76
|
-
Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
|
77
|
-
@uri = URI.parse("https://github.com/thoughtbot/paperclip?file=test")
|
78
|
-
@subject = Paperclip.io_adapters.for(@uri)
|
79
|
-
end
|
80
|
-
|
81
|
-
should "return a file name" do
|
82
|
-
assert_equal "paperclip", @subject.original_filename
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
@@ -1,24 +0,0 @@
|
|
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
|