snapimage 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/bin/snapimage_generate_config +9 -11
- data/bin/snapimage_server +1 -1
- data/lib/snapimage.rb +12 -12
- data/lib/snapimage/config.rb +2 -9
- data/lib/snapimage/exceptions.rb +7 -10
- data/lib/snapimage/rack/request.rb +1 -6
- data/lib/snapimage/rack/request_file.rb +3 -6
- data/lib/snapimage/rack/response.rb +13 -13
- data/lib/snapimage/server.rb +24 -28
- data/lib/snapimage/version.rb +1 -1
- data/spec/acceptance/delete_resource_images_spec.rb +166 -166
- data/spec/acceptance/list_resource_images_spec.rb +158 -158
- data/spec/acceptance/modify_spec.rb +165 -165
- data/spec/acceptance/sync_spec.rb +237 -237
- data/spec/acceptance/upload_spec.rb +28 -189
- data/spec/snapimage/config_spec.rb +5 -13
- data/spec/snapimage/image/image_name_utils_spec.rb +113 -113
- data/spec/snapimage/image/image_spec.rb +55 -55
- data/spec/snapimage/rack/request_file_spec.rb +0 -11
- data/spec/snapimage/rack/request_spec.rb +6 -25
- data/spec/snapimage/server_actions/server_actions.authorize_spec.rb +56 -56
- data/spec/snapimage/server_actions/server_actions.generate_image_spec.rb +146 -146
- data/spec/snapimage/server_actions/server_actions.sync_resource_spec.rb +81 -81
- data/spec/snapimage/server_spec.rb +57 -20
- data/spec/snapimage/storage/storage_server.local_spec.rb +150 -150
- data/spec/snapimage/storage/storage_server_spec.rb +83 -83
- data/spec/snapimage/storage/storage_spec.rb +42 -42
- data/spec/support/assets/config.json +2 -6
- data/spec/support/assets/config.yml +2 -9
- metadata +4 -4
@@ -8,7 +8,7 @@ describe "Upload" do
|
|
8
8
|
@local_root = File.join(RSpec.root, "storage")
|
9
9
|
@image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
|
10
10
|
@large_image_path = File.join(RSpec.root, "support/assets/stub-2048x100.png")
|
11
|
-
@
|
11
|
+
@directory = "abc/123"
|
12
12
|
end
|
13
13
|
|
14
14
|
after do
|
@@ -23,61 +23,13 @@ describe "Upload" do
|
|
23
23
|
SnapImage::Middleware.new(
|
24
24
|
app,
|
25
25
|
path: "/snapimage_api",
|
26
|
-
config: {
|
27
|
-
"primary_storage_server" => "local",
|
28
|
-
"storage_servers" => [
|
29
|
-
{
|
30
|
-
"name" => "local",
|
31
|
-
"type" => "LOCAL",
|
32
|
-
"local_root" => File.join(RSpec.root, "storage"),
|
33
|
-
"public_url" => "//example.com/images"
|
34
|
-
}
|
35
|
-
]
|
36
|
-
}
|
26
|
+
config: { "directory" => File.join(RSpec.root, "storage") }
|
37
27
|
)
|
38
28
|
end
|
39
29
|
|
40
30
|
context "upload a file" do
|
41
31
|
before do
|
42
|
-
|
43
|
-
action: "generate_image",
|
44
|
-
resource_identifier: @resource_id,
|
45
|
-
response_content_type: "text/html",
|
46
|
-
response_template: "json = {{json}}"
|
47
|
-
}.to_json
|
48
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => json
|
49
|
-
end
|
50
|
-
|
51
|
-
it "is successful" do
|
52
|
-
last_response.should be_successful
|
53
|
-
last_response["Content-Type"].should eq "text/html"
|
54
|
-
matches = last_response.body.match(/json = ({.*})/)
|
55
|
-
matches.should_not be_nil
|
56
|
-
matches.size.should eq 2
|
57
|
-
json = JSON.parse(matches[1])
|
58
|
-
json["status_code"].should eq 200
|
59
|
-
json["message"].should eq "Get Modified Image Successful"
|
60
|
-
json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-300x200.png$")
|
61
|
-
json["image_width"].should eq 300
|
62
|
-
json["image_height"].should eq 200
|
63
|
-
end
|
64
|
-
|
65
|
-
it "stores the image" do
|
66
|
-
matches = last_response.body.match(/json = ({.*})/)
|
67
|
-
json = JSON.parse(matches[1])
|
68
|
-
path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
|
69
|
-
File.exist?(path).should be_true
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "upload from URL" do
|
74
|
-
before do
|
75
|
-
json = {
|
76
|
-
action: "generate_image",
|
77
|
-
url: "http://snapeditor.com/assets/se_logo.png",
|
78
|
-
resource_identifier: @resource_id
|
79
|
-
}.to_json
|
80
|
-
post "/snapimage_api", "json" => json
|
32
|
+
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "directory" => @directory
|
81
33
|
end
|
82
34
|
|
83
35
|
it "is successful" do
|
@@ -85,151 +37,38 @@ describe "Upload" do
|
|
85
37
|
last_response["Content-Type"].should eq "text/json"
|
86
38
|
json = JSON.parse(last_response.body)
|
87
39
|
json["status_code"].should eq 200
|
88
|
-
json["message"].should eq "
|
89
|
-
json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-54x41.png$")
|
90
|
-
json["image_width"].should eq 54
|
91
|
-
json["image_height"].should eq 41
|
40
|
+
json["message"].should eq "Success"
|
92
41
|
end
|
93
42
|
|
94
43
|
it "stores the image" do
|
95
44
|
json = JSON.parse(last_response.body)
|
96
|
-
path = File.join(@local_root, @
|
45
|
+
path = File.join(@local_root, @directory, File.basename(@image_path))
|
97
46
|
File.exist?(path).should be_true
|
98
47
|
end
|
99
48
|
end
|
100
49
|
|
101
|
-
context "upload too large" do
|
102
|
-
before do
|
103
|
-
json = { action: "generate_image", resource_identifier: @resource_id }.to_json
|
104
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@large_image_path, "image/png"), "json" => json
|
105
|
-
end
|
106
|
-
|
107
|
-
it "resizes successfully" do
|
108
|
-
last_response.should be_successful
|
109
|
-
last_response["Content-Type"].should eq "text/json"
|
110
|
-
json = JSON.parse(last_response.body)
|
111
|
-
json["status_code"].should eq 200
|
112
|
-
json["message"].should eq "Get Modified Image Successful"
|
113
|
-
json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-1024x50.png$")
|
114
|
-
json["image_width"].should eq 1024
|
115
|
-
json["image_height"].should eq 50
|
116
|
-
end
|
117
|
-
|
118
|
-
it "stores the image" do
|
119
|
-
json = JSON.parse(last_response.body)
|
120
|
-
path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
|
121
|
-
File.exist?(path).should be_true
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "with security tokens" do
|
127
|
-
def app
|
128
|
-
app = Proc.new do |env|
|
129
|
-
[200, {}, ""]
|
130
|
-
end
|
131
|
-
SnapImage::Middleware.new(
|
132
|
-
app,
|
133
|
-
path: "/snapimage_api",
|
134
|
-
config: {
|
135
|
-
"security_salt" => "123456789",
|
136
|
-
"primary_storage_server" => "local",
|
137
|
-
"storage_servers" => [
|
138
|
-
{
|
139
|
-
"name" => "local",
|
140
|
-
"type" => "LOCAL",
|
141
|
-
"local_root" => File.join(RSpec.root, "storage"),
|
142
|
-
"public_url" => "//example.com/images"
|
143
|
-
}
|
144
|
-
]
|
145
|
-
}
|
146
|
-
)
|
147
|
-
end
|
148
|
-
|
149
|
-
before do
|
150
|
-
@security_token = Digest::SHA1.hexdigest("client:#{Time.now.strftime("%Y-%m-%d")}:123456789:#{@resource_id}")
|
151
|
-
end
|
152
|
-
|
153
|
-
context "upload a file" do
|
154
|
-
before do
|
155
|
-
@options = { action: "generate_image", resource_identifier: @resource_id }
|
156
|
-
end
|
157
|
-
|
158
|
-
it "requires authorization when no security token is provided" do
|
159
|
-
request_json = @options.to_json
|
160
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => request_json
|
161
|
-
last_response.should be_successful
|
162
|
-
last_response["content-type"].should eq "text/json"
|
163
|
-
json = JSON.parse(last_response.body)
|
164
|
-
json["status_code"].should eq 401
|
165
|
-
json["message"].should eq "Authorization Required"
|
166
|
-
end
|
167
|
-
|
168
|
-
it "fails authorization when the security token is invalid" do
|
169
|
-
request_json = @options.merge!({"client_security_token" => "abc"}).to_json
|
170
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => request_json
|
171
|
-
last_response.should be_successful
|
172
|
-
last_response["content-type"].should eq "text/json"
|
173
|
-
json = JSON.parse(last_response.body)
|
174
|
-
json["status_code"].should eq 402
|
175
|
-
json["message"].should eq "Authorization Failed"
|
176
|
-
end
|
177
|
-
|
178
|
-
it "is successful when the security token is valid" do
|
179
|
-
request_json = @options.merge!({"client_security_token" => @security_token}).to_json
|
180
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => request_json
|
181
|
-
last_response.should be_successful
|
182
|
-
last_response["content-type"].should eq "text/json"
|
183
|
-
json = JSON.parse(last_response.body)
|
184
|
-
json["status_code"].should eq 200
|
185
|
-
json["message"].should eq "Get Modified Image Successful"
|
186
|
-
json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-300x200.png$")
|
187
|
-
json["image_width"].should eq 300
|
188
|
-
json["image_height"].should eq 200
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context "upload from URL" do
|
193
|
-
before do
|
194
|
-
@options = {
|
195
|
-
action: "generate_image",
|
196
|
-
url: "http://snapeditor.com/assets/se_logo.png",
|
197
|
-
resource_identifier: @resource_id
|
198
|
-
}
|
199
|
-
end
|
200
|
-
|
201
|
-
it "requires authorization when no security token is provided" do
|
202
|
-
request_json = @options.to_json
|
203
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => request_json
|
204
|
-
last_response.should be_successful
|
205
|
-
last_response["content-type"].should eq "text/json"
|
206
|
-
json = JSON.parse(last_response.body)
|
207
|
-
json["status_code"].should eq 401
|
208
|
-
json["message"].should eq "Authorization Required"
|
209
|
-
end
|
210
|
-
|
211
|
-
it "fails authorization when the security token is invalid" do
|
212
|
-
request_json = @options.merge!({"client_security_token" => "abc"}).to_json
|
213
|
-
post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@image_path, "image/png"), "json" => request_json
|
214
|
-
last_response.should be_successful
|
215
|
-
last_response["content-type"].should eq "text/json"
|
216
|
-
json = JSON.parse(last_response.body)
|
217
|
-
json["status_code"].should eq 402
|
218
|
-
json["message"].should eq "Authorization Failed"
|
219
|
-
end
|
220
|
-
|
221
|
-
it "is successful" do
|
222
|
-
request_json = @options.merge!({"client_security_token" => @security_token}).to_json
|
223
|
-
post "/snapimage_api", "json" => request_json
|
224
|
-
last_response.should be_successful
|
225
|
-
last_response["Content-Type"].should eq "text/json"
|
226
|
-
json = JSON.parse(last_response.body)
|
227
|
-
json["status_code"].should eq 200
|
228
|
-
json["message"].should eq "Get Modified Image Successful"
|
229
|
-
json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-54x41.png$")
|
230
|
-
json["image_width"].should eq 54
|
231
|
-
json["image_height"].should eq 41
|
232
|
-
end
|
233
|
-
end
|
50
|
+
#context "upload too large" do
|
51
|
+
#before do
|
52
|
+
#json = { action: "generate_image", resource_identifier: @resource_id }.to_json
|
53
|
+
#post "/snapimage_api", "file" => Rack::Test::UploadedFile.new(@large_image_path, "image/png"), "json" => json
|
54
|
+
#end
|
55
|
+
|
56
|
+
#it "resizes successfully" do
|
57
|
+
#last_response.should be_successful
|
58
|
+
#last_response["Content-Type"].should eq "text/json"
|
59
|
+
#json = JSON.parse(last_response.body)
|
60
|
+
#json["status_code"].should eq 200
|
61
|
+
#json["message"].should eq "Get Modified Image Successful"
|
62
|
+
#json["image_url"].should match Regexp.new("^//example.com/images/abc/123/[a-z0-9]{8}-1024x50.png$")
|
63
|
+
#json["image_width"].should eq 1024
|
64
|
+
#json["image_height"].should eq 50
|
65
|
+
#end
|
66
|
+
|
67
|
+
#it "stores the image" do
|
68
|
+
#json = JSON.parse(last_response.body)
|
69
|
+
#path = File.join(@local_root, @resource_id, File.basename(json["image_url"]))
|
70
|
+
#File.exist?(path).should be_true
|
71
|
+
#end
|
72
|
+
#end
|
234
73
|
end
|
235
74
|
end
|
@@ -20,23 +20,15 @@ describe SnapImage::Config do
|
|
20
20
|
it "returns the config from a YAML file" do
|
21
21
|
config = SnapImage::Config.new(File.join(RSpec.root, "support/assets/config.yml"))
|
22
22
|
c = config.get_config
|
23
|
-
c["
|
24
|
-
c["
|
25
|
-
c["storage_servers"][0]["name"].should eq "storage 1"
|
26
|
-
c["storage_servers"][0]["type"].should eq "test"
|
27
|
-
c["storage_servers"][1]["name"].should eq "storage 2"
|
28
|
-
c["storage_servers"][1]["type"].should eq "test"
|
23
|
+
c["directory"].should eq "/path/to/directory"
|
24
|
+
c["max_file_size"].should eq 100
|
29
25
|
end
|
30
26
|
|
31
27
|
it "returns the config from a JSON file" do
|
32
28
|
config = SnapImage::Config.new(File.join(RSpec.root, "support/assets/config.json"))
|
33
29
|
c = config.get_config
|
34
|
-
c["
|
35
|
-
c["
|
36
|
-
c["storage_servers"][0]["name"].should eq "storage 1"
|
37
|
-
c["storage_servers"][0]["type"].should eq "test"
|
38
|
-
c["storage_servers"][1]["name"].should eq "storage 2"
|
39
|
-
c["storage_servers"][1]["type"].should eq "test"
|
30
|
+
c["directory"].should eq "/path/to/directory"
|
31
|
+
c["max_file_size"].should eq 100
|
40
32
|
end
|
41
33
|
end
|
42
34
|
|
@@ -46,7 +38,7 @@ describe SnapImage::Config do
|
|
46
38
|
end
|
47
39
|
|
48
40
|
it "returns the value when the key exists" do
|
49
|
-
@config["
|
41
|
+
@config["directory"].should eq "/path/to/directory"
|
50
42
|
end
|
51
43
|
|
52
44
|
it "returns nil when the key does not exist" do
|
@@ -1,127 +1,127 @@
|
|
1
|
-
require "spec_helper"
|
1
|
+
#require "spec_helper"
|
2
2
|
|
3
|
-
describe SnapImage::ImageNameUtils do
|
4
|
-
before do
|
5
|
-
|
6
|
-
end
|
3
|
+
#describe SnapImage::ImageNameUtils do
|
4
|
+
#before do
|
5
|
+
#@image_path = File.join(RSpec.root, "support/assets/stub.png")
|
6
|
+
#end
|
7
7
|
|
8
|
-
describe "#get_image_type" do
|
9
|
-
it "returns the correct type" do
|
10
|
-
SnapImage::ImageNameUtils.get_image_type("http://example.com/storage/abc/123/image.png").should eq "png"
|
11
|
-
end
|
8
|
+
#describe "#get_image_type" do
|
9
|
+
#it "returns the correct type" do
|
10
|
+
#SnapImage::ImageNameUtils.get_image_type("http://example.com/storage/abc/123/image.png").should eq "png"
|
11
|
+
#end
|
12
12
|
|
13
|
-
it "returns jpg when the type is jpeg" do
|
14
|
-
SnapImage::ImageNameUtils.get_image_type("http://example.com/storage/abc/123/image.jpeg").should eq "jpg"
|
15
|
-
end
|
16
|
-
end
|
13
|
+
#it "returns jpg when the type is jpeg" do
|
14
|
+
#SnapImage::ImageNameUtils.get_image_type("http://example.com/storage/abc/123/image.jpeg").should eq "jpg"
|
15
|
+
#end
|
16
|
+
#end
|
17
17
|
|
18
|
-
describe "#get_image_name_parts" do
|
19
|
-
it "raises an error when the image identifier is invalid" do
|
20
|
-
expect { SnapImage::ImageNameUtils.get_image_name_parts("a bad url") }.should raise_error SnapImage::InvalidImageIdentifier
|
21
|
-
end
|
18
|
+
#describe "#get_image_name_parts" do
|
19
|
+
#it "raises an error when the image identifier is invalid" do
|
20
|
+
#expect { SnapImage::ImageNameUtils.get_image_name_parts("a bad url") }.should raise_error SnapImage::InvalidImageIdentifier
|
21
|
+
#end
|
22
22
|
|
23
|
-
it "returns all the parts given a base image url" do
|
24
|
-
url = "http://example.com/dkej2o3i-1024x768.png"
|
25
|
-
parts = SnapImage::ImageNameUtils.get_image_name_parts(url)
|
26
|
-
parts[:is_base].should be_true
|
27
|
-
parts[:full].should eq url
|
28
|
-
parts[:path].should eq "http://example.com"
|
29
|
-
parts[:filename].should eq "dkej2o3i-1024x768.png"
|
30
|
-
parts[:basename].should eq "dkej2o3i"
|
31
|
-
parts[:original_dimensions].should eq [1024, 768]
|
32
|
-
parts[:extname].should eq "png"
|
33
|
-
parts[:crop].should be_nil
|
34
|
-
parts[:dimensions].should be_nil
|
35
|
-
parts[:sharpen].should be_nil
|
36
|
-
end
|
23
|
+
#it "returns all the parts given a base image url" do
|
24
|
+
#url = "http://example.com/dkej2o3i-1024x768.png"
|
25
|
+
#parts = SnapImage::ImageNameUtils.get_image_name_parts(url)
|
26
|
+
#parts[:is_base].should be_true
|
27
|
+
#parts[:full].should eq url
|
28
|
+
#parts[:path].should eq "http://example.com"
|
29
|
+
#parts[:filename].should eq "dkej2o3i-1024x768.png"
|
30
|
+
#parts[:basename].should eq "dkej2o3i"
|
31
|
+
#parts[:original_dimensions].should eq [1024, 768]
|
32
|
+
#parts[:extname].should eq "png"
|
33
|
+
#parts[:crop].should be_nil
|
34
|
+
#parts[:dimensions].should be_nil
|
35
|
+
#parts[:sharpen].should be_nil
|
36
|
+
#end
|
37
37
|
|
38
|
-
it "returns all the parts given a modified image url" do
|
39
|
-
url = "http://example.com/dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
40
|
-
parts = SnapImage::ImageNameUtils.get_image_name_parts(url)
|
41
|
-
parts[:is_base].should be_false
|
42
|
-
parts[:full].should eq url
|
43
|
-
parts[:path].should eq "http://example.com"
|
44
|
-
parts[:filename].should eq "dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
45
|
-
parts[:basename].should eq "dkej2o3i"
|
46
|
-
parts[:original_dimensions].should eq [1024, 768]
|
47
|
-
parts[:crop][:x].should eq 6
|
48
|
-
parts[:crop][:y].should eq 10
|
49
|
-
parts[:crop][:width].should eq 143
|
50
|
-
parts[:crop][:height].should eq 402
|
51
|
-
parts[:dimensions].should eq [640, 480]
|
52
|
-
parts[:sharpen].should eq true
|
53
|
-
parts[:extname].should eq "png"
|
54
|
-
end
|
38
|
+
#it "returns all the parts given a modified image url" do
|
39
|
+
#url = "http://example.com/dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
40
|
+
#parts = SnapImage::ImageNameUtils.get_image_name_parts(url)
|
41
|
+
#parts[:is_base].should be_false
|
42
|
+
#parts[:full].should eq url
|
43
|
+
#parts[:path].should eq "http://example.com"
|
44
|
+
#parts[:filename].should eq "dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
45
|
+
#parts[:basename].should eq "dkej2o3i"
|
46
|
+
#parts[:original_dimensions].should eq [1024, 768]
|
47
|
+
#parts[:crop][:x].should eq 6
|
48
|
+
#parts[:crop][:y].should eq 10
|
49
|
+
#parts[:crop][:width].should eq 143
|
50
|
+
#parts[:crop][:height].should eq 402
|
51
|
+
#parts[:dimensions].should eq [640, 480]
|
52
|
+
#parts[:sharpen].should eq true
|
53
|
+
#parts[:extname].should eq "png"
|
54
|
+
#end
|
55
55
|
|
56
|
-
it "returns all the parts given a filename" do
|
57
|
-
url = "dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
58
|
-
parts = SnapImage::ImageNameUtils.get_image_name_parts(url)
|
59
|
-
parts[:is_base].should be_false
|
60
|
-
parts[:full].should eq url
|
61
|
-
parts[:path].should eq ""
|
62
|
-
parts[:filename].should eq "dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
63
|
-
parts[:basename].should eq "dkej2o3i"
|
64
|
-
parts[:original_dimensions].should eq [1024, 768]
|
65
|
-
parts[:crop][:x].should eq 6
|
66
|
-
parts[:crop][:y].should eq 10
|
67
|
-
parts[:crop][:width].should eq 143
|
68
|
-
parts[:crop][:height].should eq 402
|
69
|
-
parts[:dimensions].should eq [640, 480]
|
70
|
-
parts[:sharpen].should eq true
|
71
|
-
parts[:extname].should eq "png"
|
72
|
-
end
|
73
|
-
end
|
56
|
+
#it "returns all the parts given a filename" do
|
57
|
+
#url = "dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
58
|
+
#parts = SnapImage::ImageNameUtils.get_image_name_parts(url)
|
59
|
+
#parts[:is_base].should be_false
|
60
|
+
#parts[:full].should eq url
|
61
|
+
#parts[:path].should eq ""
|
62
|
+
#parts[:filename].should eq "dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
63
|
+
#parts[:basename].should eq "dkej2o3i"
|
64
|
+
#parts[:original_dimensions].should eq [1024, 768]
|
65
|
+
#parts[:crop][:x].should eq 6
|
66
|
+
#parts[:crop][:y].should eq 10
|
67
|
+
#parts[:crop][:width].should eq 143
|
68
|
+
#parts[:crop][:height].should eq 402
|
69
|
+
#parts[:dimensions].should eq [640, 480]
|
70
|
+
#parts[:sharpen].should eq true
|
71
|
+
#parts[:extname].should eq "png"
|
72
|
+
#end
|
73
|
+
#end
|
74
74
|
|
75
|
-
describe "#get_base_image_path" do
|
76
|
-
it "returns the base image name from the url" do
|
77
|
-
url = "http://example.com/dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
78
|
-
SnapImage::ImageNameUtils.get_base_image_path(url).should eq "http://example.com/dkej2o3i-1024x768.png"
|
79
|
-
end
|
80
|
-
end
|
75
|
+
#describe "#get_base_image_path" do
|
76
|
+
#it "returns the base image name from the url" do
|
77
|
+
#url = "http://example.com/dkej2o3i-1024x768-6x10x143x402-640x480-1.png"
|
78
|
+
#SnapImage::ImageNameUtils.get_base_image_path(url).should eq "http://example.com/dkej2o3i-1024x768.png"
|
79
|
+
#end
|
80
|
+
#end
|
81
81
|
|
82
|
-
describe "#get_resized_image_name" do
|
83
|
-
it "returns the resized name given a base image" do
|
84
|
-
name = SnapImage::ImageNameUtils.get_resized_image_name("12345678-2048x100.png", 1024, 50)
|
85
|
-
name.should eq "12345678-1024x50.png"
|
86
|
-
end
|
82
|
+
#describe "#get_resized_image_name" do
|
83
|
+
#it "returns the resized name given a base image" do
|
84
|
+
#name = SnapImage::ImageNameUtils.get_resized_image_name("12345678-2048x100.png", 1024, 50)
|
85
|
+
#name.should eq "12345678-1024x50.png"
|
86
|
+
#end
|
87
87
|
|
88
|
-
it "returns the resized name given a modified image" do
|
89
|
-
name = SnapImage::ImageNameUtils.get_resized_image_name("12345678-1x1-0x0x1x1-2048x100-0.png", 1024, 50)
|
90
|
-
name.should eq "12345678-1x1-0x0x1x1-1024x50-0.png"
|
91
|
-
end
|
92
|
-
end
|
88
|
+
#it "returns the resized name given a modified image" do
|
89
|
+
#name = SnapImage::ImageNameUtils.get_resized_image_name("12345678-1x1-0x0x1x1-2048x100-0.png", 1024, 50)
|
90
|
+
#name.should eq "12345678-1x1-0x0x1x1-1024x50-0.png"
|
91
|
+
#end
|
92
|
+
#end
|
93
93
|
|
94
|
-
describe "#generate_basename" do
|
95
|
-
it "generates 8 random alphanumeric characters" do
|
96
|
-
SnapImage::ImageNameUtils.generate_basename.should match /^[a-z0-9]{8}$/
|
97
|
-
end
|
98
|
-
end
|
94
|
+
#describe "#generate_basename" do
|
95
|
+
#it "generates 8 random alphanumeric characters" do
|
96
|
+
#SnapImage::ImageNameUtils.generate_basename.should match /^[a-z0-9]{8}$/
|
97
|
+
#end
|
98
|
+
#end
|
99
99
|
|
100
|
-
describe "#generate_image_name" do
|
101
|
-
it "generates a base image name without options" do
|
102
|
-
SnapImage::ImageNameUtils.generate_image_name(1024, 768, "png").should match /[a-z0-9]{8}-1024x768\.png/
|
103
|
-
end
|
100
|
+
#describe "#generate_image_name" do
|
101
|
+
#it "generates a base image name without options" do
|
102
|
+
#SnapImage::ImageNameUtils.generate_image_name(1024, 768, "png").should match /[a-z0-9]{8}-1024x768\.png/
|
103
|
+
#end
|
104
104
|
|
105
|
-
it "generates a base image name with just a basename option" do
|
106
|
-
SnapImage::ImageNameUtils.generate_image_name(1024, 768, "png", basename: "test").should eq "test-1024x768.png"
|
107
|
-
end
|
105
|
+
#it "generates a base image name with just a basename option" do
|
106
|
+
#SnapImage::ImageNameUtils.generate_image_name(1024, 768, "png", basename: "test").should eq "test-1024x768.png"
|
107
|
+
#end
|
108
108
|
|
109
|
-
it "generates a modified image name with options" do
|
110
|
-
SnapImage::ImageNameUtils.generate_image_name(
|
111
|
-
1024,
|
112
|
-
768,
|
113
|
-
"png",
|
114
|
-
basename: "image",
|
115
|
-
crop: {
|
116
|
-
x: 6,
|
117
|
-
y: 7,
|
118
|
-
width: 134,
|
119
|
-
height: 350
|
120
|
-
},
|
121
|
-
width: 640,
|
122
|
-
height: 480,
|
123
|
-
sharpen: true
|
124
|
-
).should eq "image-1024x768-6x7x134x350-640x480-1.png"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
109
|
+
#it "generates a modified image name with options" do
|
110
|
+
#SnapImage::ImageNameUtils.generate_image_name(
|
111
|
+
#1024,
|
112
|
+
#768,
|
113
|
+
#"png",
|
114
|
+
#basename: "image",
|
115
|
+
#crop: {
|
116
|
+
#x: 6,
|
117
|
+
#y: 7,
|
118
|
+
#width: 134,
|
119
|
+
#height: 350
|
120
|
+
#},
|
121
|
+
#width: 640,
|
122
|
+
#height: 480,
|
123
|
+
#sharpen: true
|
124
|
+
#).should eq "image-1024x768-6x7x134x350-640x480-1.png"
|
125
|
+
#end
|
126
|
+
#end
|
127
|
+
#end
|