paperclip-v2_7-patched-ruby-1_8_6 2.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +14 -0
- data/Appraisals +20 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/NEWS +69 -0
- data/README.md +444 -0
- data/Rakefile +41 -0
- data/cucumber/paperclip_steps.rb +6 -0
- data/features/basic_integration.feature +48 -0
- data/features/rake_tasks.feature +68 -0
- data/features/step_definitions/attachment_steps.rb +65 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +193 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +209 -0
- data/features/support/env.rb +8 -0
- data/features/support/fakeweb.rb +3 -0
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +46 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/rails2.gemfile +9 -0
- data/gemfiles/rails3.gemfile +9 -0
- data/gemfiles/rails3_1.gemfile +9 -0
- data/gemfiles/rails3_2.gemfile +9 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +4 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +33 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip.rb +493 -0
- data/lib/paperclip/attachment.rb +491 -0
- data/lib/paperclip/attachment_options.rb +10 -0
- data/lib/paperclip/callback_compatibility.rb +61 -0
- data/lib/paperclip/geometry.rb +120 -0
- data/lib/paperclip/interpolations.rb +174 -0
- data/lib/paperclip/iostream.rb +45 -0
- data/lib/paperclip/matchers.rb +64 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
- data/lib/paperclip/missing_attachment_styles.rb +87 -0
- data/lib/paperclip/processor.rb +58 -0
- data/lib/paperclip/railtie.rb +35 -0
- data/lib/paperclip/schema.rb +39 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/storage/filesystem.rb +81 -0
- data/lib/paperclip/storage/fog.rb +191 -0
- data/lib/paperclip/storage/s3.rb +351 -0
- data/lib/paperclip/style.rb +103 -0
- data/lib/paperclip/thumbnail.rb +105 -0
- data/lib/paperclip/upfile.rb +64 -0
- data/lib/paperclip/url_generator.rb +64 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/tasks/paperclip.rake +101 -0
- data/paperclip.gemspec +41 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +124 -0
- data/test/attachment_options_test.rb +40 -0
- data/test/attachment_test.rb +1211 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/animated.gif +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/fog.yml +8 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/spaced file.png +0 -0
- data/test/fixtures/text.txt +1 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +206 -0
- data/test/helper.rb +181 -0
- data/test/integration_test.rb +652 -0
- data/test/interpolations_test.rb +219 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +24 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +110 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +47 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +72 -0
- data/test/paperclip_missing_attachment_styles_test.rb +96 -0
- data/test/paperclip_test.rb +409 -0
- data/test/processor_test.rb +10 -0
- data/test/schema_test.rb +98 -0
- data/test/storage/filesystem_test.rb +62 -0
- data/test/storage/fog_test.rb +280 -0
- data/test/storage/s3_live_test.rb +138 -0
- data/test/storage/s3_test.rb +1093 -0
- data/test/style_test.rb +215 -0
- data/test/support/mock_attachment.rb +22 -0
- data/test/support/mock_interpolator.rb +24 -0
- data/test/support/mock_model.rb +2 -0
- data/test/support/mock_url_generator_builder.rb +27 -0
- data/test/thumbnail_test.rb +396 -0
- data/test/upfile_test.rb +53 -0
- data/test/url_generator_test.rb +187 -0
- metadata +374 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class ProcessorTest < Test::Unit::TestCase
|
4
|
+
should "instantiate and call #make when sent #make to the class" do
|
5
|
+
processor = mock
|
6
|
+
processor.expects(:make).with()
|
7
|
+
Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
|
8
|
+
Paperclip::Processor.make(:one, :two, :three)
|
9
|
+
end
|
10
|
+
end
|
data/test/schema_test.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
require 'paperclip/schema'
|
3
|
+
|
4
|
+
class MockSchema
|
5
|
+
include Paperclip::Schema
|
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
|
26
|
+
|
27
|
+
def deleted_column?(column_name)
|
28
|
+
@deleted_columns.include?(column_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def type_of(column_name)
|
32
|
+
@columns[column_name]
|
33
|
+
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
|
+
|
59
|
+
should "make the file_name column a string" do
|
60
|
+
assert_equal :string, @schema.type_of(:avatar_file_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "make the content_type column a string" do
|
64
|
+
assert_equal :string, @schema.type_of(:avatar_content_type)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "make the file_size column an integer" do
|
68
|
+
assert_equal :integer, @schema.type_of(:avatar_file_size)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "make the updated_at column a datetime" do
|
72
|
+
assert_equal :datetime, @schema.type_of(:avatar_updated_at)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "Migrating down" do
|
77
|
+
setup do
|
78
|
+
@schema = MockSchema.new(:users)
|
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)
|
88
|
+
end
|
89
|
+
|
90
|
+
should "remove the file_size column" do
|
91
|
+
assert @schema.deleted_column?(:avatar_file_size)
|
92
|
+
end
|
93
|
+
|
94
|
+
should "remove the updated_at column" do
|
95
|
+
assert @schema.deleted_column?(:avatar_updated_at)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class FileSystemTest < Test::Unit::TestCase
|
4
|
+
context "Filesystem" do
|
5
|
+
setup do
|
6
|
+
rebuild_model :styles => { :thumbnail => "25x25#" }
|
7
|
+
@dummy = Dummy.create!
|
8
|
+
|
9
|
+
@dummy.avatar = File.open(fixture_file('5k.png'))
|
10
|
+
end
|
11
|
+
|
12
|
+
should "allow file assignment" do
|
13
|
+
assert @dummy.save
|
14
|
+
end
|
15
|
+
|
16
|
+
should "store the original" do
|
17
|
+
@dummy.save
|
18
|
+
assert File.exists?(@dummy.avatar.path)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "store the thumbnail" do
|
22
|
+
@dummy.save
|
23
|
+
assert File.exists?(@dummy.avatar.path(:thumbnail))
|
24
|
+
end
|
25
|
+
|
26
|
+
should "clean up file objects" do
|
27
|
+
File.stubs(:exist?).returns(true)
|
28
|
+
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
|
29
|
+
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
|
30
|
+
|
31
|
+
@dummy.save!
|
32
|
+
end
|
33
|
+
|
34
|
+
should "always be rewound when returning from #to_file" do
|
35
|
+
assert_equal 0, @dummy.avatar.to_file.pos
|
36
|
+
@dummy.avatar.to_file.seek(10)
|
37
|
+
assert_equal 0, @dummy.avatar.to_file.pos
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with file that has space in file name" do
|
41
|
+
setup do
|
42
|
+
rebuild_model :styles => { :thumbnail => "25x25#" }
|
43
|
+
@dummy = Dummy.create!
|
44
|
+
|
45
|
+
@dummy.avatar = File.open(fixture_file('spaced file.png'))
|
46
|
+
@dummy.save
|
47
|
+
end
|
48
|
+
|
49
|
+
should "store the file" do
|
50
|
+
assert File.exists?(@dummy.avatar.path)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "return a replaced version for path" do
|
54
|
+
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
|
55
|
+
end
|
56
|
+
|
57
|
+
should "return a replaced version for url" do
|
58
|
+
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
require 'fog'
|
3
|
+
|
4
|
+
Fog.mock!
|
5
|
+
|
6
|
+
class FogTest < Test::Unit::TestCase
|
7
|
+
context "" do
|
8
|
+
|
9
|
+
context "with credentials provided in a path string" do
|
10
|
+
setup do
|
11
|
+
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
12
|
+
:storage => :fog,
|
13
|
+
:url => '/:attachment/:filename',
|
14
|
+
:fog_directory => "paperclip",
|
15
|
+
:fog_credentials => fixture_file('fog.yml')
|
16
|
+
@dummy = Dummy.new
|
17
|
+
@dummy.avatar = File.new(fixture_file('5k.png'), 'rb')
|
18
|
+
end
|
19
|
+
|
20
|
+
should "have the proper information loading credentials from a file" do
|
21
|
+
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with credentials provided in a File object" do
|
26
|
+
setup do
|
27
|
+
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
28
|
+
:storage => :fog,
|
29
|
+
:url => '/:attachment/:filename',
|
30
|
+
:fog_directory => "paperclip",
|
31
|
+
:fog_credentials => File.open(fixture_file('fog.yml'))
|
32
|
+
@dummy = Dummy.new
|
33
|
+
@dummy.avatar = File.new(fixture_file('5k.png'), 'rb')
|
34
|
+
end
|
35
|
+
|
36
|
+
should "have the proper information loading credentials from a file" do
|
37
|
+
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with default values for path and url" do
|
42
|
+
setup do
|
43
|
+
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
44
|
+
:storage => :fog,
|
45
|
+
:url => '/:attachment/:filename',
|
46
|
+
:fog_directory => "paperclip",
|
47
|
+
:fog_credentials => {
|
48
|
+
:provider => 'AWS',
|
49
|
+
:aws_access_key_id => 'AWS_ID',
|
50
|
+
:aws_secret_access_key => 'AWS_SECRET'
|
51
|
+
}
|
52
|
+
@dummy = Dummy.new
|
53
|
+
@dummy.avatar = File.new(fixture_file('5k.png'), 'rb')
|
54
|
+
end
|
55
|
+
should "be able to interpolate the path without blowing up" do
|
56
|
+
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../public/avatars/5k.png")),
|
57
|
+
@dummy.avatar.path
|
58
|
+
end
|
59
|
+
|
60
|
+
should "clean up file objects" do
|
61
|
+
File.stubs(:exist?).returns(true)
|
62
|
+
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
|
63
|
+
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
|
64
|
+
|
65
|
+
@dummy.save!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
setup do
|
70
|
+
@fog_directory = 'papercliptests'
|
71
|
+
|
72
|
+
@credentials = {
|
73
|
+
:provider => 'AWS',
|
74
|
+
:aws_access_key_id => 'ID',
|
75
|
+
:aws_secret_access_key => 'SECRET'
|
76
|
+
}
|
77
|
+
|
78
|
+
@connection = Fog::Storage.new(@credentials)
|
79
|
+
@connection.directories.create(
|
80
|
+
:key => @fog_directory
|
81
|
+
)
|
82
|
+
|
83
|
+
@options = {
|
84
|
+
:fog_directory => @fog_directory,
|
85
|
+
:fog_credentials => @credentials,
|
86
|
+
:fog_host => nil,
|
87
|
+
:fog_file => {:cache_control => 1234},
|
88
|
+
:path => ":attachment/:basename.:extension",
|
89
|
+
:storage => :fog
|
90
|
+
}
|
91
|
+
|
92
|
+
rebuild_model(@options)
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be extended by the Fog module" do
|
96
|
+
assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog)
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when assigned" do
|
100
|
+
setup do
|
101
|
+
@file = File.new(fixture_file('5k.png'), 'rb')
|
102
|
+
@dummy = Dummy.new
|
103
|
+
@dummy.avatar = @file
|
104
|
+
end
|
105
|
+
|
106
|
+
teardown do
|
107
|
+
@file.close
|
108
|
+
directory = @connection.directories.new(:key => @fog_directory)
|
109
|
+
directory.files.each {|file| file.destroy}
|
110
|
+
directory.destroy
|
111
|
+
end
|
112
|
+
|
113
|
+
should "always be rewound when returning from #to_file" do
|
114
|
+
assert_equal 0, @dummy.avatar.to_file.pos
|
115
|
+
@dummy.avatar.to_file.seek(10)
|
116
|
+
assert_equal 0, @dummy.avatar.to_file.pos
|
117
|
+
end
|
118
|
+
|
119
|
+
should "pass the content type to the Fog::Storage::AWS::Files instance" do
|
120
|
+
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
|
121
|
+
hash[:content_type]
|
122
|
+
end
|
123
|
+
@dummy.save
|
124
|
+
end
|
125
|
+
|
126
|
+
context "without a bucket" do
|
127
|
+
setup do
|
128
|
+
@connection.directories.get(@fog_directory).destroy
|
129
|
+
end
|
130
|
+
|
131
|
+
should "create the bucket" do
|
132
|
+
assert @dummy.save
|
133
|
+
assert @connection.directories.get(@fog_directory)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "with a bucket" do
|
138
|
+
should "succeed" do
|
139
|
+
assert @dummy.save
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "without a fog_host" do
|
144
|
+
setup do
|
145
|
+
rebuild_model(@options.merge(:fog_host => nil))
|
146
|
+
@dummy = Dummy.new
|
147
|
+
@dummy.avatar = StringIO.new('.')
|
148
|
+
@dummy.save
|
149
|
+
end
|
150
|
+
|
151
|
+
should "provide a public url" do
|
152
|
+
assert !@dummy.avatar.url.nil?
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "with a fog_host" do
|
157
|
+
setup do
|
158
|
+
rebuild_model(@options.merge(:fog_host => 'http://example.com'))
|
159
|
+
@dummy = Dummy.new
|
160
|
+
@dummy.avatar = StringIO.new('.')
|
161
|
+
@dummy.save
|
162
|
+
end
|
163
|
+
|
164
|
+
should "provide a public url" do
|
165
|
+
assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/stringio\.txt\?\d*$/
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "with a fog_host that includes a wildcard placeholder" do
|
170
|
+
setup do
|
171
|
+
rebuild_model(
|
172
|
+
:fog_directory => @fog_directory,
|
173
|
+
:fog_credentials => @credentials,
|
174
|
+
:fog_host => 'http://img%d.example.com',
|
175
|
+
:path => ":attachment/:basename.:extension",
|
176
|
+
:storage => :fog
|
177
|
+
)
|
178
|
+
@dummy = Dummy.new
|
179
|
+
@dummy.avatar = StringIO.new('.')
|
180
|
+
@dummy.save
|
181
|
+
end
|
182
|
+
|
183
|
+
should "provide a public url" do
|
184
|
+
assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/stringio\.txt\?\d*$/
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "with fog_public set to false" do
|
189
|
+
setup do
|
190
|
+
rebuild_model(@options.merge(:fog_public => false))
|
191
|
+
@dummy = Dummy.new
|
192
|
+
@dummy.avatar = StringIO.new('.')
|
193
|
+
@dummy.save
|
194
|
+
end
|
195
|
+
|
196
|
+
should 'set the @fog_public instance variable to false' do
|
197
|
+
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
|
198
|
+
assert_equal false, @dummy.avatar.fog_public
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "with a valid bucket name for a subdomain" do
|
203
|
+
should "provide an url in subdomain style" do
|
204
|
+
assert_match /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "with an invalid bucket name for a subdomain" do
|
209
|
+
setup do
|
210
|
+
rebuild_model(@options.merge(:fog_directory => "this_is_invalid"))
|
211
|
+
@dummy = Dummy.new
|
212
|
+
@dummy.avatar = @file
|
213
|
+
@dummy.save
|
214
|
+
end
|
215
|
+
|
216
|
+
should "not match the bucket-subdomain restrictions" do
|
217
|
+
invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
|
218
|
+
invalid_subdomains.each do |name|
|
219
|
+
assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
should "provide an url in folder style" do
|
224
|
+
assert_match /^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
context "with a proc for a bucket name evaluating a model method" do
|
230
|
+
setup do
|
231
|
+
@dynamic_fog_directory = 'dynamicpaperclip'
|
232
|
+
rebuild_model(@options.merge(:fog_directory => lambda { |attachment| attachment.instance.bucket_name }))
|
233
|
+
@dummy = Dummy.new
|
234
|
+
@dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
|
235
|
+
@dummy.avatar = @file
|
236
|
+
@dummy.save
|
237
|
+
end
|
238
|
+
|
239
|
+
should "have created the bucket" do
|
240
|
+
assert @connection.directories.get(@dynamic_fog_directory).inspect
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
context "with a proc for the fog_host evaluating a model method" do
|
246
|
+
setup do
|
247
|
+
rebuild_model(@options.merge(:fog_host => lambda { |attachment| attachment.instance.fog_host }))
|
248
|
+
@dummy = Dummy.new
|
249
|
+
@dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
|
250
|
+
@dummy.avatar = @file
|
251
|
+
@dummy.save
|
252
|
+
end
|
253
|
+
|
254
|
+
should "provide a public url" do
|
255
|
+
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context "with a proc for the fog_credentials evaluating a model method" do
|
260
|
+
setup do
|
261
|
+
@dynamic_fog_credentials = {
|
262
|
+
:provider => 'AWS',
|
263
|
+
:aws_access_key_id => 'DYNAMIC_ID',
|
264
|
+
:aws_secret_access_key => 'DYNAMIC_SECRET'
|
265
|
+
}
|
266
|
+
rebuild_model(@options.merge(:fog_credentials => lambda { |attachment| attachment.instance.fog_credentials }))
|
267
|
+
@dummy = Dummy.new
|
268
|
+
@dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
|
269
|
+
@dummy.avatar = @file
|
270
|
+
@dummy.save
|
271
|
+
end
|
272
|
+
|
273
|
+
should "provide a public url" do
|
274
|
+
assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
end
|