This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
s3_live_test.rb
153 lines (127 loc) · 4.52 KB
/
s3_live_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require './test/helper'
require 'aws'
unless ENV["S3_BUCKET"].blank?
class S3LiveTest < Test::Unit::TestCase
context "when assigning an S3 attachment directly to another model" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@dummy = Dummy.new
@attachment = Dummy.new.avatar
@file = File.new(fixture_file("5k.png"))
@attachment.assign(@file)
@attachment.save
@attachment2 = Dummy.new.avatar
@attachment2.assign(@file)
@attachment2.save
end
end
context "Generating an expiring url on a nonexistant attachment" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@dummy = Dummy.new
end
should "return nil" do
assert_nil @dummy.avatar.expiring_url
end
end
context "Using S3 for real, an attachment with S3 storage" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
Dummy.delete_all
@dummy = Dummy.new
end
should "be extended by the S3 module" do
assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
end
context "when assigned" do
setup do
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy.avatar = @file
end
teardown do
@file.close
@dummy.destroy
end
context "and saved" do
setup do
@dummy.save
end
should "be on S3" do
assert true
end
end
end
end
context "An attachment that uses S3 for storage and has spaces in file name" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
Dummy.delete_all
@dummy = Dummy.new
@dummy.avatar = File.new(fixture_file('spaced file.png'), 'rb')
@dummy.save
end
should "return a replaced version for path" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
end
should "return a replaced version for url" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
end
should "be accessible" do
assert_success_response @dummy.avatar.url
end
should "be reprocessable" do
assert @dummy.avatar.reprocess!
end
should "be destroyable" do
url = @dummy.avatar.url
@dummy.destroy
assert_not_found_response url
end
end
context "An attachment that uses S3 for storage and uses AES256 encryption" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml")),
:s3_server_side_encryption => :aes256
Dummy.delete_all
@dummy = Dummy.new
end
context "when assigned" do
setup do
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy.avatar = @file
end
teardown do
@file.close
@dummy.destroy
end
context "and saved" do
setup do
@dummy.save
end
should "be encrypted on S3" do
assert @dummy.avatar.s3_object.server_side_encryption == :aes256
end
end
end
end
end
end