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/schema_test.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
require 'paperclip/schema'
|
3
|
-
require 'active_support/testing/deprecation'
|
4
|
-
|
5
|
-
class SchemaTest < Test::Unit::TestCase
|
6
|
-
include ActiveSupport::Testing::Deprecation
|
7
|
-
|
8
|
-
def setup
|
9
|
-
rebuild_class
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
Dummy.connection.drop_table :dummies rescue nil
|
14
|
-
end
|
15
|
-
|
16
|
-
context "within table definition" do
|
17
|
-
context "using #has_attached_file" do
|
18
|
-
should "create attachment columns" do
|
19
|
-
Dummy.connection.create_table :dummies, :force => true do |t|
|
20
|
-
ActiveSupport::Deprecation.silence do
|
21
|
-
t.has_attached_file :avatar
|
22
|
-
end
|
23
|
-
end
|
24
|
-
rebuild_class
|
25
|
-
|
26
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
27
|
-
|
28
|
-
assert_includes columns, ['avatar_file_name', :string]
|
29
|
-
assert_includes columns, ['avatar_content_type', :string]
|
30
|
-
assert_includes columns, ['avatar_file_size', :integer]
|
31
|
-
assert_includes columns, ['avatar_updated_at', :datetime]
|
32
|
-
end
|
33
|
-
|
34
|
-
should "display deprecation warning" do
|
35
|
-
Dummy.connection.create_table :dummies, :force => true do |t|
|
36
|
-
assert_deprecated do
|
37
|
-
t.has_attached_file :avatar
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "using #attachment" do
|
44
|
-
setup do
|
45
|
-
Dummy.connection.create_table :dummies, :force => true do |t|
|
46
|
-
t.attachment :avatar
|
47
|
-
end
|
48
|
-
rebuild_class
|
49
|
-
end
|
50
|
-
|
51
|
-
should "create attachment columns" do
|
52
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
53
|
-
|
54
|
-
assert_includes columns, ['avatar_file_name', :string]
|
55
|
-
assert_includes columns, ['avatar_content_type', :string]
|
56
|
-
assert_includes columns, ['avatar_file_size', :integer]
|
57
|
-
assert_includes columns, ['avatar_updated_at', :datetime]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "within schema statement" do
|
63
|
-
setup do
|
64
|
-
Dummy.connection.create_table :dummies, :force => true
|
65
|
-
end
|
66
|
-
|
67
|
-
context "migrating up" do
|
68
|
-
context "with single attachment" do
|
69
|
-
setup do
|
70
|
-
Dummy.connection.add_attachment :dummies, :avatar
|
71
|
-
rebuild_class
|
72
|
-
end
|
73
|
-
|
74
|
-
should "create attachment columns" do
|
75
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
76
|
-
|
77
|
-
assert_includes columns, ['avatar_file_name', :string]
|
78
|
-
assert_includes columns, ['avatar_content_type', :string]
|
79
|
-
assert_includes columns, ['avatar_file_size', :integer]
|
80
|
-
assert_includes columns, ['avatar_updated_at', :datetime]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "with multiple attachments" do
|
85
|
-
setup do
|
86
|
-
Dummy.connection.add_attachment :dummies, :avatar, :photo
|
87
|
-
rebuild_class
|
88
|
-
end
|
89
|
-
|
90
|
-
should "create attachment columns" do
|
91
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
92
|
-
|
93
|
-
assert_includes columns, ['avatar_file_name', :string]
|
94
|
-
assert_includes columns, ['avatar_content_type', :string]
|
95
|
-
assert_includes columns, ['avatar_file_size', :integer]
|
96
|
-
assert_includes columns, ['avatar_updated_at', :datetime]
|
97
|
-
assert_includes columns, ['photo_file_name', :string]
|
98
|
-
assert_includes columns, ['photo_content_type', :string]
|
99
|
-
assert_includes columns, ['photo_file_size', :integer]
|
100
|
-
assert_includes columns, ['photo_updated_at', :datetime]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "with no attachment" do
|
105
|
-
should "raise an error" do
|
106
|
-
assert_raise ArgumentError do
|
107
|
-
Dummy.connection.add_attachment :dummies
|
108
|
-
rebuild_class
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context "migrating down" do
|
115
|
-
setup do
|
116
|
-
Dummy.connection.change_table :dummies do |t|
|
117
|
-
t.column :avatar_file_name, :string
|
118
|
-
t.column :avatar_content_type, :string
|
119
|
-
t.column :avatar_file_size, :integer
|
120
|
-
t.column :avatar_updated_at, :datetime
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context "using #drop_attached_file" do
|
125
|
-
should "remove the attachment columns" do
|
126
|
-
ActiveSupport::Deprecation.silence do
|
127
|
-
Dummy.connection.drop_attached_file :dummies, :avatar
|
128
|
-
end
|
129
|
-
rebuild_class
|
130
|
-
|
131
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
132
|
-
|
133
|
-
assert_not_includes columns, ['avatar_file_name', :string]
|
134
|
-
assert_not_includes columns, ['avatar_content_type', :string]
|
135
|
-
assert_not_includes columns, ['avatar_file_size', :integer]
|
136
|
-
assert_not_includes columns, ['avatar_updated_at', :datetime]
|
137
|
-
end
|
138
|
-
|
139
|
-
should "display a deprecation warning" do
|
140
|
-
assert_deprecated do
|
141
|
-
Dummy.connection.drop_attached_file :dummies, :avatar
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "using #remove_attachment" do
|
147
|
-
context "with single attachment" do
|
148
|
-
setup do
|
149
|
-
Dummy.connection.remove_attachment :dummies, :avatar
|
150
|
-
rebuild_class
|
151
|
-
end
|
152
|
-
|
153
|
-
should "remove the attachment columns" do
|
154
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
155
|
-
|
156
|
-
assert_not_includes columns, ['avatar_file_name', :string]
|
157
|
-
assert_not_includes columns, ['avatar_content_type', :string]
|
158
|
-
assert_not_includes columns, ['avatar_file_size', :integer]
|
159
|
-
assert_not_includes columns, ['avatar_updated_at', :datetime]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context "with multiple attachments" do
|
164
|
-
setup do
|
165
|
-
Dummy.connection.change_table :dummies do |t|
|
166
|
-
t.column :photo_file_name, :string
|
167
|
-
t.column :photo_content_type, :string
|
168
|
-
t.column :photo_file_size, :integer
|
169
|
-
t.column :photo_updated_at, :datetime
|
170
|
-
end
|
171
|
-
|
172
|
-
Dummy.connection.remove_attachment :dummies, :avatar, :photo
|
173
|
-
rebuild_class
|
174
|
-
end
|
175
|
-
|
176
|
-
should "remove the attachment columns" do
|
177
|
-
columns = Dummy.columns.map{ |column| [column.name, column.type] }
|
178
|
-
|
179
|
-
assert_not_includes columns, ['avatar_file_name', :string]
|
180
|
-
assert_not_includes columns, ['avatar_content_type', :string]
|
181
|
-
assert_not_includes columns, ['avatar_file_size', :integer]
|
182
|
-
assert_not_includes columns, ['avatar_updated_at', :datetime]
|
183
|
-
assert_not_includes columns, ['photo_file_name', :string]
|
184
|
-
assert_not_includes columns, ['photo_content_type', :string]
|
185
|
-
assert_not_includes columns, ['photo_file_size', :integer]
|
186
|
-
assert_not_includes columns, ['photo_updated_at', :datetime]
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "with no attachment" do
|
191
|
-
should "raise an error" do
|
192
|
-
assert_raise ArgumentError do
|
193
|
-
Dummy.connection.remove_attachment :dummies
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
data/test/storage/fog_test.rb
DELETED
@@ -1,453 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
require 'fog'
|
3
|
-
|
4
|
-
class FogTest < Test::Unit::TestCase
|
5
|
-
context "" do
|
6
|
-
setup { Fog.mock! }
|
7
|
-
|
8
|
-
context "with credentials provided in a path string" do
|
9
|
-
setup do
|
10
|
-
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
11
|
-
:storage => :fog,
|
12
|
-
:url => '/:attachment/:filename',
|
13
|
-
:fog_directory => "paperclip",
|
14
|
-
:fog_credentials => fixture_file('fog.yml')
|
15
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
16
|
-
@dummy = Dummy.new
|
17
|
-
@dummy.avatar = @file
|
18
|
-
end
|
19
|
-
|
20
|
-
teardown { @file.close }
|
21
|
-
|
22
|
-
should "have the proper information loading credentials from a file" do
|
23
|
-
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with credentials provided in a File object" do
|
28
|
-
setup do
|
29
|
-
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
30
|
-
:storage => :fog,
|
31
|
-
:url => '/:attachment/:filename',
|
32
|
-
:fog_directory => "paperclip",
|
33
|
-
:fog_credentials => File.open(fixture_file('fog.yml'))
|
34
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
35
|
-
@dummy = Dummy.new
|
36
|
-
@dummy.avatar = @file
|
37
|
-
end
|
38
|
-
|
39
|
-
teardown { @file.close }
|
40
|
-
|
41
|
-
should "have the proper information loading credentials from a file" do
|
42
|
-
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with default values for path and url" do
|
47
|
-
setup do
|
48
|
-
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
49
|
-
:storage => :fog,
|
50
|
-
:url => '/:attachment/:filename',
|
51
|
-
:fog_directory => "paperclip",
|
52
|
-
:fog_credentials => {
|
53
|
-
:provider => 'AWS',
|
54
|
-
:aws_access_key_id => 'AWS_ID',
|
55
|
-
:aws_secret_access_key => 'AWS_SECRET'
|
56
|
-
}
|
57
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
58
|
-
@dummy = Dummy.new
|
59
|
-
@dummy.avatar = @file
|
60
|
-
end
|
61
|
-
|
62
|
-
teardown { @file.close }
|
63
|
-
|
64
|
-
should "be able to interpolate the path without blowing up" do
|
65
|
-
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../tmp/public/avatars/5k.png")),
|
66
|
-
@dummy.avatar.path
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with no path or url given and using defaults" do
|
71
|
-
setup do
|
72
|
-
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
73
|
-
:storage => :fog,
|
74
|
-
:fog_directory => "paperclip",
|
75
|
-
:fog_credentials => {
|
76
|
-
:provider => 'AWS',
|
77
|
-
:aws_access_key_id => 'AWS_ID',
|
78
|
-
:aws_secret_access_key => 'AWS_SECRET'
|
79
|
-
}
|
80
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
81
|
-
@dummy = Dummy.new
|
82
|
-
@dummy.id = 1
|
83
|
-
@dummy.avatar = @file
|
84
|
-
end
|
85
|
-
|
86
|
-
teardown { @file.close }
|
87
|
-
|
88
|
-
should "have correct path and url from interpolated defaults" do
|
89
|
-
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "with file params provided as lambda" do
|
94
|
-
setup do
|
95
|
-
fog_file = lambda{ |a| { :custom_header => a.instance.custom_method }}
|
96
|
-
klass = rebuild_model :storage => :fog,
|
97
|
-
:fog_file => fog_file
|
98
|
-
|
99
|
-
klass.class_eval do
|
100
|
-
def custom_method
|
101
|
-
'foobar'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
@dummy = Dummy.new
|
107
|
-
end
|
108
|
-
|
109
|
-
should "be able to evaluate correct values for file headers" do
|
110
|
-
assert_equal @dummy.avatar.send(:fog_file), { :custom_header => 'foobar' }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
setup do
|
115
|
-
@fog_directory = 'papercliptests'
|
116
|
-
|
117
|
-
@credentials = {
|
118
|
-
:provider => 'AWS',
|
119
|
-
:aws_access_key_id => 'ID',
|
120
|
-
:aws_secret_access_key => 'SECRET'
|
121
|
-
}
|
122
|
-
|
123
|
-
@connection = Fog::Storage.new(@credentials)
|
124
|
-
@connection.directories.create(
|
125
|
-
:key => @fog_directory
|
126
|
-
)
|
127
|
-
|
128
|
-
@options = {
|
129
|
-
:fog_directory => @fog_directory,
|
130
|
-
:fog_credentials => @credentials,
|
131
|
-
:fog_host => nil,
|
132
|
-
:fog_file => {:cache_control => 1234},
|
133
|
-
:path => ":attachment/:basename.:extension",
|
134
|
-
:storage => :fog
|
135
|
-
}
|
136
|
-
|
137
|
-
rebuild_model(@options)
|
138
|
-
end
|
139
|
-
|
140
|
-
should "be extended by the Fog module" do
|
141
|
-
assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog)
|
142
|
-
end
|
143
|
-
|
144
|
-
context "when assigned" do
|
145
|
-
setup do
|
146
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
147
|
-
@dummy = Dummy.new
|
148
|
-
@dummy.avatar = @file
|
149
|
-
end
|
150
|
-
|
151
|
-
teardown do
|
152
|
-
@file.close
|
153
|
-
directory = @connection.directories.new(:key => @fog_directory)
|
154
|
-
directory.files.each {|file| file.destroy}
|
155
|
-
directory.destroy
|
156
|
-
end
|
157
|
-
|
158
|
-
should "be rewinded after flush_writes" do
|
159
|
-
@dummy.avatar.instance_eval "def after_flush_writes; end"
|
160
|
-
|
161
|
-
files = @dummy.avatar.queued_for_write.values
|
162
|
-
@dummy.save
|
163
|
-
assert files.none?(&:eof?), "Expect all the files to be rewinded."
|
164
|
-
end
|
165
|
-
|
166
|
-
should "be removed after after_flush_writes" do
|
167
|
-
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
168
|
-
@dummy.save
|
169
|
-
assert paths.none?{ |path| File.exists?(path) },
|
170
|
-
"Expect all the files to be deleted."
|
171
|
-
end
|
172
|
-
|
173
|
-
should 'be able to be copied to a local file' do
|
174
|
-
@dummy.save
|
175
|
-
tempfile = Tempfile.new("known_location")
|
176
|
-
tempfile.binmode
|
177
|
-
@dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
178
|
-
tempfile.rewind
|
179
|
-
assert_equal @connection.directories.get(@fog_directory).files.get(@dummy.avatar.path).body,
|
180
|
-
tempfile.read
|
181
|
-
tempfile.close
|
182
|
-
end
|
183
|
-
|
184
|
-
should "pass the content type to the Fog::Storage::AWS::Files instance" do
|
185
|
-
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
|
186
|
-
hash[:content_type]
|
187
|
-
end
|
188
|
-
@dummy.save
|
189
|
-
end
|
190
|
-
|
191
|
-
context "without a bucket" do
|
192
|
-
setup do
|
193
|
-
@connection.directories.get(@fog_directory).destroy
|
194
|
-
end
|
195
|
-
|
196
|
-
should "create the bucket" do
|
197
|
-
assert @dummy.save
|
198
|
-
assert @connection.directories.get(@fog_directory)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "with a bucket" do
|
203
|
-
should "succeed" do
|
204
|
-
assert @dummy.save
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context "without a fog_host" do
|
209
|
-
setup do
|
210
|
-
rebuild_model(@options.merge(:fog_host => nil))
|
211
|
-
@dummy = Dummy.new
|
212
|
-
@dummy.avatar = StringIO.new('.')
|
213
|
-
@dummy.save
|
214
|
-
end
|
215
|
-
|
216
|
-
should "provide a public url" do
|
217
|
-
assert !@dummy.avatar.url.nil?
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
context "with a fog_host" do
|
222
|
-
setup do
|
223
|
-
rebuild_model(@options.merge(:fog_host => 'http://example.com'))
|
224
|
-
@dummy = Dummy.new
|
225
|
-
@dummy.avatar = StringIO.new('.')
|
226
|
-
@dummy.save
|
227
|
-
end
|
228
|
-
|
229
|
-
should "provide a public url" do
|
230
|
-
assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/stringio\.txt\?\d*$/
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context "with a fog_host that includes a wildcard placeholder" do
|
235
|
-
setup do
|
236
|
-
rebuild_model(
|
237
|
-
:fog_directory => @fog_directory,
|
238
|
-
:fog_credentials => @credentials,
|
239
|
-
:fog_host => 'http://img%d.example.com',
|
240
|
-
:path => ":attachment/:basename.:extension",
|
241
|
-
:storage => :fog
|
242
|
-
)
|
243
|
-
@dummy = Dummy.new
|
244
|
-
@dummy.avatar = StringIO.new('.')
|
245
|
-
@dummy.save
|
246
|
-
end
|
247
|
-
|
248
|
-
should "provide a public url" do
|
249
|
-
assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/stringio\.txt\?\d*$/
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context "with fog_public set to false" do
|
254
|
-
setup do
|
255
|
-
rebuild_model(@options.merge(:fog_public => false))
|
256
|
-
@dummy = Dummy.new
|
257
|
-
@dummy.avatar = StringIO.new('.')
|
258
|
-
@dummy.save
|
259
|
-
end
|
260
|
-
|
261
|
-
should 'set the @fog_public instance variable to false' do
|
262
|
-
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
|
263
|
-
assert_equal false, @dummy.avatar.fog_public
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
context "with styles set and fog_public set to false" do
|
268
|
-
setup do
|
269
|
-
rebuild_model(@options.merge(:fog_public => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
|
270
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
271
|
-
@dummy = Dummy.new
|
272
|
-
@dummy.avatar = @file
|
273
|
-
@dummy.save
|
274
|
-
end
|
275
|
-
|
276
|
-
should 'set the @fog_public for a particular style to false' do
|
277
|
-
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
|
278
|
-
assert_equal false, @dummy.avatar.fog_public(:thumb)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
context "with styles set and fog_public set per-style" do
|
283
|
-
setup do
|
284
|
-
rebuild_model(@options.merge(:fog_public => { :medium => false, :thumb => true}, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
|
285
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
286
|
-
@dummy = Dummy.new
|
287
|
-
@dummy.avatar = @file
|
288
|
-
@dummy.save
|
289
|
-
end
|
290
|
-
|
291
|
-
should 'set the fog_public for a particular style to correct value' do
|
292
|
-
assert_equal false, @dummy.avatar.fog_public(:medium)
|
293
|
-
assert_equal true, @dummy.avatar.fog_public(:thumb)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
context "with fog_public not set" do
|
298
|
-
setup do
|
299
|
-
rebuild_model(@options)
|
300
|
-
@dummy = Dummy.new
|
301
|
-
@dummy.avatar = StringIO.new('.')
|
302
|
-
@dummy.save
|
303
|
-
end
|
304
|
-
|
305
|
-
should "default fog_public to true" do
|
306
|
-
assert_equal true, @dummy.avatar.fog_public
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
context "with a valid bucket name for a subdomain" do
|
311
|
-
should "provide an url in subdomain style" do
|
312
|
-
assert_match @dummy.avatar.url, /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/
|
313
|
-
end
|
314
|
-
|
315
|
-
should "provide an url that expires in subdomain style" do
|
316
|
-
assert_match /^http:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
context "with an invalid bucket name for a subdomain" do
|
321
|
-
setup do
|
322
|
-
rebuild_model(@options.merge(:fog_directory => "this_is_invalid"))
|
323
|
-
@dummy = Dummy.new
|
324
|
-
@dummy.avatar = @file
|
325
|
-
@dummy.save
|
326
|
-
end
|
327
|
-
|
328
|
-
should "not match the bucket-subdomain restrictions" do
|
329
|
-
invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
|
330
|
-
invalid_subdomains.each do |name|
|
331
|
-
assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
should "provide an url in folder style" do
|
336
|
-
assert_match /^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url
|
337
|
-
end
|
338
|
-
|
339
|
-
should "provide a url that expires in folder style" do
|
340
|
-
assert_match /^http:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url
|
341
|
-
end
|
342
|
-
|
343
|
-
end
|
344
|
-
|
345
|
-
context "with a proc for a bucket name evaluating a model method" do
|
346
|
-
setup do
|
347
|
-
@dynamic_fog_directory = 'dynamicpaperclip'
|
348
|
-
rebuild_model(@options.merge(:fog_directory => lambda { |attachment| attachment.instance.bucket_name }))
|
349
|
-
@dummy = Dummy.new
|
350
|
-
@dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
|
351
|
-
@dummy.avatar = @file
|
352
|
-
@dummy.save
|
353
|
-
end
|
354
|
-
|
355
|
-
should "have created the bucket" do
|
356
|
-
assert @connection.directories.get(@dynamic_fog_directory).inspect
|
357
|
-
end
|
358
|
-
|
359
|
-
end
|
360
|
-
|
361
|
-
context "with a proc for the fog_host evaluating a model method" do
|
362
|
-
setup do
|
363
|
-
rebuild_model(@options.merge(:fog_host => lambda { |attachment| attachment.instance.fog_host }))
|
364
|
-
@dummy = Dummy.new
|
365
|
-
@dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
|
366
|
-
@dummy.avatar = @file
|
367
|
-
@dummy.save
|
368
|
-
end
|
369
|
-
|
370
|
-
should "provide a public url" do
|
371
|
-
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
|
372
|
-
end
|
373
|
-
|
374
|
-
end
|
375
|
-
|
376
|
-
context "with a custom fog_host" do
|
377
|
-
setup do
|
378
|
-
rebuild_model(@options.merge(:fog_host => "http://dynamicfoghost.com"))
|
379
|
-
@dummy = Dummy.new
|
380
|
-
@dummy.avatar = @file
|
381
|
-
@dummy.save
|
382
|
-
end
|
383
|
-
|
384
|
-
should "provide a public url" do
|
385
|
-
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
|
386
|
-
end
|
387
|
-
|
388
|
-
should "provide an expiring url" do
|
389
|
-
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url
|
390
|
-
end
|
391
|
-
|
392
|
-
context "with an invalid bucket name for a subdomain" do
|
393
|
-
setup do
|
394
|
-
rebuild_model(@options.merge({:fog_directory => "this_is_invalid", :fog_host => "http://dynamicfoghost.com"}))
|
395
|
-
@dummy = Dummy.new
|
396
|
-
@dummy.avatar = @file
|
397
|
-
@dummy.save
|
398
|
-
end
|
399
|
-
|
400
|
-
should "provide an expiring url" do
|
401
|
-
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
end
|
406
|
-
|
407
|
-
context "with a proc for the fog_credentials evaluating a model method" do
|
408
|
-
setup do
|
409
|
-
@dynamic_fog_credentials = {
|
410
|
-
:provider => 'AWS',
|
411
|
-
:aws_access_key_id => 'DYNAMIC_ID',
|
412
|
-
:aws_secret_access_key => 'DYNAMIC_SECRET'
|
413
|
-
}
|
414
|
-
rebuild_model(@options.merge(:fog_credentials => lambda { |attachment| attachment.instance.fog_credentials }))
|
415
|
-
@dummy = Dummy.new
|
416
|
-
@dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
|
417
|
-
@dummy.avatar = @file
|
418
|
-
@dummy.save
|
419
|
-
end
|
420
|
-
|
421
|
-
should "provide a public url" do
|
422
|
-
assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
|
423
|
-
end
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
end
|
428
|
-
|
429
|
-
context "when using local storage" do
|
430
|
-
setup do
|
431
|
-
Fog.unmock!
|
432
|
-
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
433
|
-
:storage => :fog,
|
434
|
-
:url => '/:attachment/:filename',
|
435
|
-
:fog_directory => "paperclip",
|
436
|
-
:fog_credentials => { :provider => :local, :local_root => "." },
|
437
|
-
:fog_host => 'localhost'
|
438
|
-
|
439
|
-
@file = File.new(fixture_file('5k.png'), 'rb')
|
440
|
-
@dummy = Dummy.new
|
441
|
-
@dummy.avatar = @file
|
442
|
-
end
|
443
|
-
|
444
|
-
teardown do
|
445
|
-
@file.close
|
446
|
-
Fog.mock!
|
447
|
-
end
|
448
|
-
|
449
|
-
should "return the public url in place of the expiring url" do
|
450
|
-
assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url
|
451
|
-
end
|
452
|
-
end
|
453
|
-
end
|