paperclip 3.0.3 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- checksums.yaml +15 -0
- data/.gitignore +2 -1
- data/.travis.yml +3 -0
- data/Appraisals +8 -3
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/NEWS +198 -35
- data/README.md +332 -113
- data/features/basic_integration.feature +24 -12
- data/features/migration.feature +94 -0
- data/features/rake_tasks.feature +2 -3
- data/features/step_definitions/attachment_steps.rb +28 -0
- data/features/step_definitions/rails_steps.rb +94 -8
- data/features/step_definitions/s3_steps.rb +1 -1
- data/features/step_definitions/web_steps.rb +3 -3
- data/features/support/fakeweb.rb +4 -1
- data/features/support/file_helpers.rb +10 -0
- data/features/support/rails.rb +18 -2
- data/gemfiles/3.0.gemfile +2 -2
- data/gemfiles/3.1.gemfile +2 -2
- data/gemfiles/3.2.gemfile +2 -2
- data/gemfiles/4.0.gemfile +11 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +4 -8
- data/lib/paperclip/attachment.rb +96 -43
- data/lib/paperclip/attachment_registry.rb +57 -0
- data/lib/paperclip/callbacks.rb +2 -2
- data/lib/paperclip/content_type_detector.rb +78 -0
- data/lib/paperclip/file_command_content_type_detector.rb +32 -0
- data/lib/paperclip/filename_cleaner.rb +16 -0
- data/lib/paperclip/geometry.rb +66 -30
- data/lib/paperclip/geometry_detector_factory.rb +41 -0
- data/lib/paperclip/geometry_parser_factory.rb +31 -0
- data/lib/paperclip/glue.rb +2 -8
- data/lib/paperclip/has_attached_file.rb +99 -0
- data/lib/paperclip/helpers.rb +12 -15
- data/lib/paperclip/interpolations/plural_cache.rb +17 -0
- data/lib/paperclip/interpolations.rb +15 -5
- data/lib/paperclip/io_adapters/abstract_adapter.rb +45 -0
- data/lib/paperclip/io_adapters/attachment_adapter.rb +14 -49
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +27 -0
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +18 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +8 -69
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/nil_adapter.rb +2 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +16 -45
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +17 -40
- data/lib/paperclip/io_adapters/uri_adapter.rb +44 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +1 -5
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +36 -17
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +5 -1
- data/lib/paperclip/matchers.rb +3 -3
- data/lib/paperclip/missing_attachment_styles.rb +11 -16
- data/lib/paperclip/processor.rb +12 -0
- data/lib/paperclip/railtie.rb +5 -1
- data/lib/paperclip/schema.rb +59 -23
- data/lib/paperclip/storage/filesystem.rb +23 -5
- data/lib/paperclip/storage/fog.rb +64 -25
- data/lib/paperclip/storage/s3.rb +93 -52
- data/lib/paperclip/style.rb +2 -2
- data/lib/paperclip/tempfile_factory.rb +21 -0
- data/lib/paperclip/thumbnail.rb +18 -3
- data/lib/paperclip/validators/attachment_content_type_validator.rb +38 -10
- data/lib/paperclip/validators/attachment_presence_validator.rb +8 -8
- data/lib/paperclip/validators/attachment_size_validator.rb +12 -7
- data/lib/paperclip/validators.rb +21 -2
- data/lib/paperclip/version.rb +1 -1
- data/lib/paperclip.rb +15 -44
- data/lib/tasks/paperclip.rake +26 -7
- data/paperclip.gemspec +11 -7
- data/test/attachment_definitions_test.rb +12 -0
- data/test/attachment_processing_test.rb +83 -0
- data/test/attachment_registry_test.rb +77 -0
- data/test/attachment_test.rb +253 -44
- data/test/content_type_detector_test.rb +50 -0
- data/test/file_command_content_type_detector_test.rb +25 -0
- data/test/filename_cleaner_test.rb +14 -0
- data/test/fixtures/animated +0 -0
- data/test/fixtures/animated.unknown +0 -0
- data/test/fixtures/rotated.jpg +0 -0
- data/test/generator_test.rb +26 -24
- data/test/geometry_detector_test.rb +24 -0
- data/test/geometry_parser_test.rb +73 -0
- data/test/geometry_test.rb +55 -4
- data/test/has_attached_file_test.rb +125 -0
- data/test/helper.rb +38 -7
- data/test/integration_test.rb +105 -89
- data/test/interpolations_test.rb +12 -0
- data/test/io_adapters/abstract_adapter_test.rb +58 -0
- data/test/io_adapters/attachment_adapter_test.rb +120 -33
- data/test/io_adapters/data_uri_adapter_test.rb +60 -0
- data/test/io_adapters/empty_string_adapter_test.rb +17 -0
- data/test/io_adapters/file_adapter_test.rb +32 -1
- data/test/io_adapters/stringio_adapter_test.rb +29 -10
- data/test/io_adapters/uploaded_file_adapter_test.rb +53 -5
- data/test/io_adapters/uri_adapter_test.rb +102 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +22 -0
- data/test/meta_class_test.rb +32 -0
- data/test/paperclip_missing_attachment_styles_test.rb +4 -8
- data/test/paperclip_test.rb +27 -51
- data/test/plural_cache_test.rb +36 -0
- data/test/processor_test.rb +16 -0
- data/test/rake_test.rb +103 -0
- data/test/schema_test.rb +179 -77
- data/test/storage/filesystem_test.rb +26 -3
- data/test/storage/fog_test.rb +181 -3
- data/test/storage/s3_test.rb +239 -4
- data/test/style_test.rb +18 -14
- data/test/tempfile_factory_test.rb +13 -0
- data/test/thumbnail_test.rb +96 -16
- data/test/validators/attachment_content_type_validator_test.rb +181 -55
- data/test/validators/attachment_size_validator_test.rb +10 -0
- data/test/validators_test.rb +8 -1
- metadata +126 -92
- data/Gemfile.lock +0 -157
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/images.rake +0 -21
- data/lib/.DS_Store +0 -0
- data/lib/paperclip/.DS_Store +0 -0
- 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/schema_test.rb
CHANGED
@@ -1,98 +1,200 @@
|
|
1
1
|
require './test/helper'
|
2
2
|
require 'paperclip/schema'
|
3
|
+
require 'active_support/testing/deprecation'
|
3
4
|
|
4
|
-
class
|
5
|
-
include
|
6
|
-
|
7
|
-
def initialize(table_name = nil)
|
8
|
-
@table_name = table_name
|
9
|
-
@columns = {}
|
10
|
-
@deleted_columns = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def column(name, type)
|
14
|
-
@columns[name] = type
|
15
|
-
end
|
16
|
-
|
17
|
-
def remove_column(table_name, column_name)
|
18
|
-
return if @table_name && @table_name != table_name
|
19
|
-
@columns.delete(column_name)
|
20
|
-
@deleted_columns.push(column_name)
|
21
|
-
end
|
22
|
-
|
23
|
-
def has_column?(column_name)
|
24
|
-
@columns.key?(column_name)
|
25
|
-
end
|
5
|
+
class SchemaTest < Test::Unit::TestCase
|
6
|
+
include ActiveSupport::Testing::Deprecation
|
26
7
|
|
27
|
-
def
|
28
|
-
|
8
|
+
def setup
|
9
|
+
rebuild_class
|
29
10
|
end
|
30
11
|
|
31
|
-
def
|
32
|
-
|
12
|
+
def teardown
|
13
|
+
Dummy.connection.drop_table :dummies rescue nil
|
33
14
|
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class SchemaTest < Test::Unit::TestCase
|
37
|
-
context "Migrating up" do
|
38
|
-
setup do
|
39
|
-
@schema = MockSchema.new
|
40
|
-
@schema.has_attached_file :avatar
|
41
|
-
end
|
42
|
-
|
43
|
-
should "create the file_name column" do
|
44
|
-
assert @schema.has_column?(:avatar_file_name)
|
45
|
-
end
|
46
|
-
|
47
|
-
should "create the content_type column" do
|
48
|
-
assert @schema.has_column?(:avatar_content_type)
|
49
|
-
end
|
50
|
-
|
51
|
-
should "create the file_size column" do
|
52
|
-
assert @schema.has_column?(:avatar_file_size)
|
53
|
-
end
|
54
|
-
|
55
|
-
should "create the updated_at column" do
|
56
|
-
assert @schema.has_column?(:avatar_updated_at)
|
57
|
-
end
|
58
15
|
|
59
|
-
|
60
|
-
|
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
|
61
41
|
end
|
62
42
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
73
59
|
end
|
74
60
|
end
|
75
61
|
|
76
|
-
context "
|
62
|
+
context "within schema statement" do
|
77
63
|
setup do
|
78
|
-
|
79
|
-
@schema.drop_attached_file :users, :avatar
|
80
|
-
end
|
81
|
-
|
82
|
-
should "remove the file_name column" do
|
83
|
-
assert @schema.deleted_column?(:avatar_file_name)
|
84
|
-
end
|
85
|
-
|
86
|
-
should "remove the content_type column" do
|
87
|
-
assert @schema.deleted_column?(:avatar_content_type)
|
64
|
+
Dummy.connection.create_table :dummies, :force => true
|
88
65
|
end
|
89
66
|
|
90
|
-
|
91
|
-
|
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
|
92
112
|
end
|
93
113
|
|
94
|
-
|
95
|
-
|
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
|
96
198
|
end
|
97
199
|
end
|
98
200
|
end
|
@@ -19,12 +19,35 @@ class FileSystemTest < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
should "store the original" do
|
21
21
|
@dummy.save
|
22
|
-
|
22
|
+
assert_file_exists(@dummy.avatar.path)
|
23
23
|
end
|
24
24
|
|
25
25
|
should "store the thumbnail" do
|
26
26
|
@dummy.save
|
27
|
-
|
27
|
+
assert_file_exists(@dummy.avatar.path(:thumbnail))
|
28
|
+
end
|
29
|
+
|
30
|
+
should "be rewinded after flush_writes" do
|
31
|
+
@dummy.avatar.instance_eval "def after_flush_writes; end"
|
32
|
+
|
33
|
+
files = @dummy.avatar.queued_for_write.values
|
34
|
+
@dummy.save
|
35
|
+
assert files.none?(&:eof?), "Expect all the files to be rewinded."
|
36
|
+
end
|
37
|
+
|
38
|
+
should "be removed after after_flush_writes" do
|
39
|
+
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
40
|
+
@dummy.save
|
41
|
+
assert paths.none?{ |path| File.exists?(path) },
|
42
|
+
"Expect all the files to be deleted."
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'copy the file to a known location with copy_to_local_file' do
|
46
|
+
tempfile = Tempfile.new("known_location")
|
47
|
+
@dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
48
|
+
tempfile.rewind
|
49
|
+
assert_equal @file.read, tempfile.read
|
50
|
+
tempfile.close
|
28
51
|
end
|
29
52
|
end
|
30
53
|
|
@@ -41,7 +64,7 @@ class FileSystemTest < Test::Unit::TestCase
|
|
41
64
|
teardown { @file.close }
|
42
65
|
|
43
66
|
should "store the file" do
|
44
|
-
|
67
|
+
assert_file_exists(@dummy.avatar.path)
|
45
68
|
end
|
46
69
|
|
47
70
|
should "return a replaced version for path" do
|
data/test/storage/fog_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require './test/helper'
|
2
2
|
require 'fog'
|
3
3
|
|
4
|
-
Fog.mock!
|
5
|
-
|
6
4
|
class FogTest < Test::Unit::TestCase
|
7
5
|
context "" do
|
6
|
+
setup { Fog.mock! }
|
7
|
+
|
8
8
|
context "with credentials provided in a path string" do
|
9
9
|
setup do
|
10
10
|
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
@@ -67,6 +67,50 @@ class FogTest < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
end
|
69
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
|
+
|
70
114
|
setup do
|
71
115
|
@fog_directory = 'papercliptests'
|
72
116
|
|
@@ -111,6 +155,32 @@ class FogTest < Test::Unit::TestCase
|
|
111
155
|
directory.destroy
|
112
156
|
end
|
113
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
|
+
|
114
184
|
should "pass the content type to the Fog::Storage::AWS::Files instance" do
|
115
185
|
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
|
116
186
|
hash[:content_type]
|
@@ -194,9 +264,56 @@ class FogTest < Test::Unit::TestCase
|
|
194
264
|
end
|
195
265
|
end
|
196
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
|
+
|
197
310
|
context "with a valid bucket name for a subdomain" do
|
198
311
|
should "provide an url in subdomain style" do
|
199
|
-
assert_match /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png
|
312
|
+
assert_match /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url
|
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
|
200
317
|
end
|
201
318
|
end
|
202
319
|
|
@@ -219,6 +336,10 @@ class FogTest < Test::Unit::TestCase
|
|
219
336
|
assert_match /^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url
|
220
337
|
end
|
221
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
|
+
|
222
343
|
end
|
223
344
|
|
224
345
|
context "with a proc for a bucket name evaluating a model method" do
|
@@ -249,6 +370,38 @@ class FogTest < Test::Unit::TestCase
|
|
249
370
|
should "provide a public url" do
|
250
371
|
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
|
251
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
|
+
|
252
405
|
end
|
253
406
|
|
254
407
|
context "with a proc for the fog_credentials evaluating a model method" do
|
@@ -272,4 +425,29 @@ class FogTest < Test::Unit::TestCase
|
|
272
425
|
end
|
273
426
|
|
274
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
|
275
453
|
end
|