snapimage 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,91 +1,91 @@
|
|
1
|
-
require "spec_helper"
|
1
|
+
#require "spec_helper"
|
2
2
|
|
3
|
-
describe SnapImage::ServerActions::SyncResource do
|
4
|
-
before do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
3
|
+
#describe SnapImage::ServerActions::SyncResource do
|
4
|
+
#before do
|
5
|
+
#@image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
|
6
|
+
#@storage = double("storage")
|
7
|
+
#@config = { "max_width" => 1024, "max_height" => 2048 }
|
8
|
+
#@config.stub(:storage).and_return(@storage)
|
9
|
+
#@request = double("request")
|
10
|
+
#@response = double("response")
|
11
|
+
#@sync_resource = SnapImage::ServerActions::SyncResource.new(@config, @request, @response)
|
12
|
+
#end
|
13
13
|
|
14
|
-
describe "#request_valid?" do
|
15
|
-
it "returns false when content is not valid" do
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
#describe "#request_valid?" do
|
15
|
+
#it "returns false when content is not valid" do
|
16
|
+
#@sync_resource.stub(:content_valid?).and_return(false)
|
17
|
+
#@sync_resource.send(:request_valid?).should be_false
|
18
|
+
#end
|
19
19
|
|
20
|
-
it "returns false when sync_date_time is not defined" do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
20
|
+
#it "returns false when sync_date_time is not defined" do
|
21
|
+
#@sync_resource.stub(:content_valid?).and_return(true)
|
22
|
+
#@request.stub(:json).and_return({})
|
23
|
+
#@sync_resource.send(:request_valid?).should be_false
|
24
|
+
#end
|
25
25
|
|
26
|
-
it "returns true when the request is valid" do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
26
|
+
#it "returns true when the request is valid" do
|
27
|
+
#@request.stub(:json).and_return({"sync_date_time" => DateTime.now.iso8601})
|
28
|
+
#@sync_resource.stub(:content_valid?).and_return(true)
|
29
|
+
#@sync_resource.send(:request_valid?).should be_true
|
30
|
+
#end
|
31
|
+
#end
|
32
32
|
|
33
|
-
describe "#content_valid?" do
|
34
|
-
it "returns false when content is not defined" do
|
35
|
-
|
36
|
-
|
37
|
-
end
|
33
|
+
#describe "#content_valid?" do
|
34
|
+
#it "returns false when content is not defined" do
|
35
|
+
#@request.stub(:json).and_return({})
|
36
|
+
#@sync_resource.send(:content_valid?).should be_false
|
37
|
+
#end
|
38
38
|
|
39
|
-
it "returns false when content is not a hash" do
|
40
|
-
|
41
|
-
|
42
|
-
end
|
39
|
+
#it "returns false when content is not a hash" do
|
40
|
+
#@request.stub(:json).and_return({"content" => "content"})
|
41
|
+
#@sync_resource.send(:content_valid?).should be_false
|
42
|
+
#end
|
43
43
|
|
44
|
-
it "returns false when content is empty" do
|
45
|
-
|
46
|
-
|
47
|
-
end
|
44
|
+
#it "returns false when content is empty" do
|
45
|
+
#@request.stub(:json).and_return({"content" => {}})
|
46
|
+
#@sync_resource.send(:content_valid?).should be_false
|
47
|
+
#end
|
48
48
|
|
49
|
-
it "returns true when content is valid" do
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
49
|
+
#it "returns true when content is valid" do
|
50
|
+
#@request.stub(:json).and_return({"content" => {"body" => "test"}})
|
51
|
+
#@sync_resource.send(:content_valid?).should be_true
|
52
|
+
#end
|
53
|
+
#end
|
54
54
|
|
55
|
-
describe "#get_content" do
|
56
|
-
it "returns all the content concatenated" do
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
55
|
+
#describe "#get_content" do
|
56
|
+
#it "returns all the content concatenated" do
|
57
|
+
#@request.stub(:json).and_return({"content" => {"first" => "hello", "second" => "world"}})
|
58
|
+
#@sync_resource.send(:get_content).should eq "helloworld"
|
59
|
+
#end
|
60
|
+
#end
|
61
61
|
|
62
|
-
describe "#urls_to_keep" do
|
63
|
-
it "returns all urls that match" do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
])
|
69
|
-
url_1 = "http://example.com/storage/abc/123/12345678-1024x768.png"
|
70
|
-
url_2 = "http://snapeditor.com/abc/123/12345678-1024x768-10x40x200x300-400x500-0.gif"
|
71
|
-
url_3 = "//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768-10x40x200x300-400x500-0.jpg"
|
72
|
-
url_4 = "//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768-10x40x200x300-400x500-1.jpg"
|
73
|
-
|
74
|
-
|
75
|
-
This is some fake content with images. <img src="#{url_1}" /><img src="http://example.com/abc/123/image.png" />
|
76
|
-
Some more ["#{url_2}"] but maybe not this http://snapeditor.com/.
|
77
|
-
|
78
|
-
CONTENT
|
79
|
-
)
|
80
|
-
keep = @sync_resource.send(:urls_to_keep)
|
81
|
-
keep.size.should eq 7
|
82
|
-
keep.include?(url_1)
|
83
|
-
keep.include?(url_2)
|
84
|
-
keep.include?(url_3)
|
85
|
-
keep.include?(url_4)
|
86
|
-
keep.include?("http://snapeditor.com/abc/123/12345678-1024x768.gif")
|
87
|
-
keep.include?("//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768.jpg")
|
88
|
-
keep.include?("//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768.jpg")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
62
|
+
#describe "#urls_to_keep" do
|
63
|
+
#it "returns all urls that match" do
|
64
|
+
#@storage.stub(:url_regexps).and_return([
|
65
|
+
#/(\/\/example\.com\/storage\/.+?\.(png|gif|jpg))/,
|
66
|
+
#/\/\/snapeditor\.com\/.+?\.(png|gif|jpg)/,
|
67
|
+
#/\/\/my-bucket\.s3\.amazonaws\.com\/my-images\/.+?\.(png|gif|jpg)/
|
68
|
+
#])
|
69
|
+
#url_1 = "http://example.com/storage/abc/123/12345678-1024x768.png"
|
70
|
+
#url_2 = "http://snapeditor.com/abc/123/12345678-1024x768-10x40x200x300-400x500-0.gif"
|
71
|
+
#url_3 = "//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768-10x40x200x300-400x500-0.jpg"
|
72
|
+
#url_4 = "//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768-10x40x200x300-400x500-1.jpg"
|
73
|
+
#@sync_resource.stub(:get_content).and_return(
|
74
|
+
#<<-CONTENT
|
75
|
+
#This is some fake content with images. <img src="#{url_1}" /><img src="http://example.com/abc/123/image.png" />
|
76
|
+
#Some more ["#{url_2}"] but maybe not this http://snapeditor.com/.
|
77
|
+
##{url_3} and //my-bucket.s3.amazonaws.com/my-images/abc/123/image.jpeg and #{url_4}
|
78
|
+
#CONTENT
|
79
|
+
#)
|
80
|
+
#keep = @sync_resource.send(:urls_to_keep)
|
81
|
+
#keep.size.should eq 7
|
82
|
+
#keep.include?(url_1)
|
83
|
+
#keep.include?(url_2)
|
84
|
+
#keep.include?(url_3)
|
85
|
+
#keep.include?(url_4)
|
86
|
+
#keep.include?("http://snapeditor.com/abc/123/12345678-1024x768.gif")
|
87
|
+
#keep.include?("//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768.jpg")
|
88
|
+
#keep.include?("//my-bucket.s3.amazonaws.com/my-images/abc/123/12345678-1024x768.jpg")
|
89
|
+
#end
|
90
|
+
#end
|
91
|
+
#end
|
@@ -3,8 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe SnapImage::Server do
|
4
4
|
before do
|
5
5
|
@request = double("request")
|
6
|
-
@config =
|
7
|
-
@config.stub(:storage).and_return("storage")
|
6
|
+
@config = { "directory" => "/directory", "max_file_size" => 100 }
|
8
7
|
@server = SnapImage::Server.new(@request, @config)
|
9
8
|
end
|
10
9
|
|
@@ -17,39 +16,77 @@ describe SnapImage::Server do
|
|
17
16
|
response[2].body.should eq ['{"status_code":400,"message":"Bad Request"}']
|
18
17
|
end
|
19
18
|
|
20
|
-
it "returns invalid
|
19
|
+
it "returns invalid filename when the filename is invalid" do
|
21
20
|
@request.stub(:bad_request?).and_return(false)
|
22
|
-
|
21
|
+
file = double("file")
|
22
|
+
file.stub(:filename).and_return("abc123.txt")
|
23
|
+
@request.stub(:file).and_return(file)
|
23
24
|
response = @server.call
|
24
25
|
response[0].should eq 200
|
25
26
|
response[1]["Content-Type"].should eq "text/json"
|
26
|
-
response[2].body.should eq ['{"status_code":
|
27
|
+
response[2].body.should eq ['{"status_code":403,"message":"Invalid Filename"}']
|
27
28
|
end
|
28
29
|
|
29
|
-
it "returns
|
30
|
+
it "returns invalid directory when the directory is invalid" do
|
30
31
|
@request.stub(:bad_request?).and_return(false)
|
31
|
-
|
32
|
+
file = double("file")
|
33
|
+
file.stub(:filename).and_return("abc123.png")
|
34
|
+
@request.stub(:file).and_return(file)
|
35
|
+
@request.stub(:[]).with("directory").and_return("abc?123")
|
32
36
|
response = @server.call
|
33
37
|
response[0].should eq 200
|
34
38
|
response[1]["Content-Type"].should eq "text/json"
|
35
|
-
response[2].body.should eq ['{"status_code":
|
39
|
+
response[2].body.should eq ['{"status_code":404,"message":"Invalid Directory"}']
|
36
40
|
end
|
37
41
|
|
38
|
-
it "
|
39
|
-
response = double("response")
|
40
|
-
response.stub(:finish)
|
41
|
-
generate_image = double("Generate Image")
|
42
|
-
generate_image.should_receive(:call).once.and_return(response)
|
43
|
-
SnapImage::ServerActions::GenerateImage.stub(:new).and_return(generate_image)
|
42
|
+
it "returns file too large when the file is too large" do
|
44
43
|
@request.stub(:bad_request?).and_return(false)
|
45
|
-
|
46
|
-
|
44
|
+
tempfile = double("tempfile")
|
45
|
+
tempfile.stub(:size).and_return(200)
|
46
|
+
file = double("file")
|
47
|
+
file.stub(:filename).and_return("abc123.png")
|
48
|
+
file.stub(:tempfile).and_return(tempfile)
|
49
|
+
@request.stub(:file).and_return(file)
|
50
|
+
@request.stub(:[]).with("directory").and_return("abc/123")
|
51
|
+
response = @server.call
|
52
|
+
response[0].should eq 200
|
53
|
+
response[1]["Content-Type"].should eq "text/json"
|
54
|
+
response[2].body.should eq ['{"status_code":405,"message":"File Too Large"}']
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns success when the file already exists" do
|
58
|
+
@request.stub(:bad_request?).and_return(false)
|
59
|
+
tempfile = double("tempfile")
|
60
|
+
tempfile.stub(:size).and_return(50)
|
61
|
+
file = double("file")
|
62
|
+
file.stub(:filename).and_return("abc123.png")
|
63
|
+
file.stub(:tempfile).and_return(tempfile)
|
64
|
+
@request.stub(:file).and_return(file)
|
65
|
+
@request.stub(:[]).with("directory").and_return("abc/123")
|
66
|
+
File.stub(:exists?).and_return(true)
|
67
|
+
FileUtils.stub(:mkdir_p)
|
68
|
+
response = @server.call
|
69
|
+
response[0].should eq 200
|
70
|
+
response[1]["Content-Type"].should eq "text/json"
|
71
|
+
response[2].body.should eq ['{"status_code":200,"message":"Success"}']
|
47
72
|
end
|
48
|
-
end
|
49
73
|
|
50
|
-
|
51
|
-
|
52
|
-
|
74
|
+
it "returns success when the file is saved" do
|
75
|
+
@request.stub(:bad_request?).and_return(false)
|
76
|
+
tempfile = double("tempfile")
|
77
|
+
tempfile.stub(:size).and_return(50)
|
78
|
+
file = double("file")
|
79
|
+
file.stub(:filename).and_return("abc123.png")
|
80
|
+
file.stub(:tempfile).and_return(tempfile)
|
81
|
+
@request.stub(:file).and_return(file)
|
82
|
+
@request.stub(:[]).with("directory").and_return("abc/123")
|
83
|
+
File.stub(:exists?).and_return(false)
|
84
|
+
FileUtils.stub(:mkdir_p)
|
85
|
+
File.should_receive(:open).with("/directory/abc/123/abc123.png", "wb").once
|
86
|
+
response = @server.call
|
87
|
+
response[0].should eq 200
|
88
|
+
response[1]["Content-Type"].should eq "text/json"
|
89
|
+
response[2].body.should eq ['{"status_code":200,"message":"Success"}']
|
53
90
|
end
|
54
91
|
end
|
55
92
|
end
|
@@ -1,150 +1,150 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe SnapImage::StorageServer::Local do
|
4
|
-
before do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
"name" => "Test",
|
9
|
-
"public_url" => "//example.com/storage",
|
10
|
-
"local_root" => @local_root,
|
11
|
-
"max_width" => 1024,
|
12
|
-
"max_height" => 2048
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
after do
|
17
|
-
FileUtils.rm_rf(@local_root)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#store_file" do
|
21
|
-
before do
|
22
|
-
SnapImage::ImageNameUtils.stub(:generate_image_name).and_return("test_image.png")
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
it "copies the contents of the file" do
|
28
|
-
contents = File.new(File.join(@local_root, "abc/123/test_image.png"), "rb").read
|
29
|
-
blob = SnapImage::Image.from_blob(File.new(@image_path, "rb").read).blob
|
30
|
-
contents.should eq blob
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#get" do
|
35
|
-
before do
|
36
|
-
SnapImage::ImageNameUtils.stub(:generate_image_name).and_return("test_image.png")
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
it "raises an error when the file doesn't exist" do
|
41
|
-
expect { @server.get("http://example.com/storage/abc/123/test_image.gif") }.should raise_error SnapImage::FileDoesNotExist
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns a SnapImage::Image" do
|
45
|
-
image = @server.get("http://example.com/storage/abc/123/test_image.png")
|
46
|
-
image.is_a?(SnapImage::Image).should be_true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#store" do
|
51
|
-
before do
|
52
|
-
SnapImage::ImageNameUtils.stub(:generate_image_name).and_return("test_image.png")
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
it "creates a new file in the storage" do
|
57
|
-
File.exists?(File.join(@local_root, "abc/123/test_image.png")).should be_true
|
58
|
-
end
|
59
|
-
|
60
|
-
it "writes the contents to the file" do
|
61
|
-
contents = File.new(File.join(@local_root, "abc/123/test_image.png"), "rb").read
|
62
|
-
blob = SnapImage::Image.from_blob(File.new(@image_path, "rb").read).blob
|
63
|
-
contents.should eq blob
|
64
|
-
end
|
65
|
-
|
66
|
-
it "returns the image" do
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#root" do
|
73
|
-
it "creates the root when it doesn't exist" do
|
74
|
-
|
75
|
-
File.directory?(@local_root)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "returns the root" do
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "#get_local_path_parts" do
|
84
|
-
it "returns nil when the the path is not a local path" do
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
it "returns the parts when the path is a local path" do
|
89
|
-
parts = @server.send(:get_local_path_parts, File.join(@local_root, "abc/123/image.png"))
|
90
|
-
parts[:resource_id].should eq "abc/123"
|
91
|
-
parts[:filename].should eq "image.png"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#local_path_to_public_url" do
|
96
|
-
it "returns the public url corresponding to the local path" do
|
97
|
-
local_path = File.join(@local_root, "abc/123/image.png")
|
98
|
-
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "#public_url_to_local_path" do
|
103
|
-
it "returns the local path corresponding to the public url" do
|
104
|
-
url = "http://example.com/storage/abc/123/image.png"
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "#get_resource_filenames" do
|
110
|
-
before do
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
"name" => "Test",
|
115
|
-
"public_url" => "//example.com/storage",
|
116
|
-
"local_root" => @local_root,
|
117
|
-
"max_width" => 1024,
|
118
|
-
"max_height" => 2048
|
119
|
-
)
|
120
|
-
end
|
121
|
-
|
122
|
-
after do
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
it "returns only images for the given resource id" do
|
127
|
-
filenames = @server.send(:get_resource_filenames, "resource_1")
|
128
|
-
filenames.size.should eq 3
|
129
|
-
filenames.include?(File.join(@local_root, "resource_1/12345678-1x1.png")).should be_true
|
130
|
-
filenames.include?(File.join(@local_root, "resource_1/12345678-1x1-0x0x1x1-300x200-0.jpg")).should be_true
|
131
|
-
filenames.include?(File.join(@local_root, "resource_1/12345678-1x1-0x0x1x1-1x1-1.gif")).should be_true
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "#file_modified_before_timestamp??" do
|
136
|
-
it "returns true when no timestamp is given" do
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
it "returns true when the file was modified before the timestamp" do
|
141
|
-
timestamp = DateTime.parse(File.mtime(@image_path).iso8601) + 100
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
it "returns false when file was not modified before the timestamp" do
|
146
|
-
timestamp = DateTime.parse(File.mtime(@image_path).iso8601)
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
1
|
+
#require "spec_helper"
|
2
|
+
|
3
|
+
#describe SnapImage::StorageServer::Local do
|
4
|
+
#before do
|
5
|
+
#@local_root = File.join(RSpec.root, "storage")
|
6
|
+
#@image_path = File.join(RSpec.root, "support/assets/stub-1x1.png")
|
7
|
+
#@server = SnapImage::StorageServer::Local.new(
|
8
|
+
#"name" => "Test",
|
9
|
+
#"public_url" => "//example.com/storage",
|
10
|
+
#"local_root" => @local_root,
|
11
|
+
#"max_width" => 1024,
|
12
|
+
#"max_height" => 2048
|
13
|
+
#)
|
14
|
+
#end
|
15
|
+
|
16
|
+
#after do
|
17
|
+
#FileUtils.rm_rf(@local_root)
|
18
|
+
#end
|
19
|
+
|
20
|
+
#describe "#store_file" do
|
21
|
+
#before do
|
22
|
+
#SnapImage::ImageNameUtils.stub(:generate_image_name).and_return("test_image.png")
|
23
|
+
#@file = File.new(@image_path, "rb")
|
24
|
+
#@server.store_file(@file, "png", "abc/123")
|
25
|
+
#end
|
26
|
+
|
27
|
+
#it "copies the contents of the file" do
|
28
|
+
#contents = File.new(File.join(@local_root, "abc/123/test_image.png"), "rb").read
|
29
|
+
#blob = SnapImage::Image.from_blob(File.new(@image_path, "rb").read).blob
|
30
|
+
#contents.should eq blob
|
31
|
+
#end
|
32
|
+
#end
|
33
|
+
|
34
|
+
#describe "#get" do
|
35
|
+
#before do
|
36
|
+
#SnapImage::ImageNameUtils.stub(:generate_image_name).and_return("test_image.png")
|
37
|
+
#@server.store_file(File.new(@image_path), "png", "abc/123")
|
38
|
+
#end
|
39
|
+
|
40
|
+
#it "raises an error when the file doesn't exist" do
|
41
|
+
#expect { @server.get("http://example.com/storage/abc/123/test_image.gif") }.should raise_error SnapImage::FileDoesNotExist
|
42
|
+
#end
|
43
|
+
|
44
|
+
#it "returns a SnapImage::Image" do
|
45
|
+
#image = @server.get("http://example.com/storage/abc/123/test_image.png")
|
46
|
+
#image.is_a?(SnapImage::Image).should be_true
|
47
|
+
#end
|
48
|
+
#end
|
49
|
+
|
50
|
+
#describe "#store" do
|
51
|
+
#before do
|
52
|
+
#SnapImage::ImageNameUtils.stub(:generate_image_name).and_return("test_image.png")
|
53
|
+
#@image = @server.send(:store, SnapImage::Image.from_blob(File.new(@image_path, "rb").read), "test_image.png", "abc/123")
|
54
|
+
#end
|
55
|
+
|
56
|
+
#it "creates a new file in the storage" do
|
57
|
+
#File.exists?(File.join(@local_root, "abc/123/test_image.png")).should be_true
|
58
|
+
#end
|
59
|
+
|
60
|
+
#it "writes the contents to the file" do
|
61
|
+
#contents = File.new(File.join(@local_root, "abc/123/test_image.png"), "rb").read
|
62
|
+
#blob = SnapImage::Image.from_blob(File.new(@image_path, "rb").read).blob
|
63
|
+
#contents.should eq blob
|
64
|
+
#end
|
65
|
+
|
66
|
+
#it "returns the image" do
|
67
|
+
#@image.is_a?(SnapImage::Image).should be_true
|
68
|
+
#@image.public_url.should eq "//example.com/storage/abc/123/test_image.png"
|
69
|
+
#end
|
70
|
+
#end
|
71
|
+
|
72
|
+
#describe "#root" do
|
73
|
+
#it "creates the root when it doesn't exist" do
|
74
|
+
#@server.send(:root)
|
75
|
+
#File.directory?(@local_root)
|
76
|
+
#end
|
77
|
+
|
78
|
+
#it "returns the root" do
|
79
|
+
#@server.send(:root).should eq @local_root
|
80
|
+
#end
|
81
|
+
#end
|
82
|
+
|
83
|
+
#describe "#get_local_path_parts" do
|
84
|
+
#it "returns nil when the the path is not a local path" do
|
85
|
+
#@server.send(:get_local_path_parts, "some/random/path/image.png").should be_nil
|
86
|
+
#end
|
87
|
+
|
88
|
+
#it "returns the parts when the path is a local path" do
|
89
|
+
#parts = @server.send(:get_local_path_parts, File.join(@local_root, "abc/123/image.png"))
|
90
|
+
#parts[:resource_id].should eq "abc/123"
|
91
|
+
#parts[:filename].should eq "image.png"
|
92
|
+
#end
|
93
|
+
#end
|
94
|
+
|
95
|
+
#describe "#local_path_to_public_url" do
|
96
|
+
#it "returns the public url corresponding to the local path" do
|
97
|
+
#local_path = File.join(@local_root, "abc/123/image.png")
|
98
|
+
#@server.send(:local_path_to_public_url, local_path).should eq "//example.com/storage/abc/123/image.png"
|
99
|
+
#end
|
100
|
+
#end
|
101
|
+
|
102
|
+
#describe "#public_url_to_local_path" do
|
103
|
+
#it "returns the local path corresponding to the public url" do
|
104
|
+
#url = "http://example.com/storage/abc/123/image.png"
|
105
|
+
#@server.send(:public_url_to_local_path, url).should eq File.join(@local_root, "abc/123/image.png")
|
106
|
+
#end
|
107
|
+
#end
|
108
|
+
|
109
|
+
#describe "#get_resource_filenames" do
|
110
|
+
#before do
|
111
|
+
#@old_local_root = @local_root
|
112
|
+
#@local_root = File.join(File.expand_path(File.dirname(__FILE__)), "assets/local")
|
113
|
+
#@server = SnapImage::StorageServer::Local.new(
|
114
|
+
#"name" => "Test",
|
115
|
+
#"public_url" => "//example.com/storage",
|
116
|
+
#"local_root" => @local_root,
|
117
|
+
#"max_width" => 1024,
|
118
|
+
#"max_height" => 2048
|
119
|
+
#)
|
120
|
+
#end
|
121
|
+
|
122
|
+
#after do
|
123
|
+
#@local_root = @old_local_root
|
124
|
+
#end
|
125
|
+
|
126
|
+
#it "returns only images for the given resource id" do
|
127
|
+
#filenames = @server.send(:get_resource_filenames, "resource_1")
|
128
|
+
#filenames.size.should eq 3
|
129
|
+
#filenames.include?(File.join(@local_root, "resource_1/12345678-1x1.png")).should be_true
|
130
|
+
#filenames.include?(File.join(@local_root, "resource_1/12345678-1x1-0x0x1x1-300x200-0.jpg")).should be_true
|
131
|
+
#filenames.include?(File.join(@local_root, "resource_1/12345678-1x1-0x0x1x1-1x1-1.gif")).should be_true
|
132
|
+
#end
|
133
|
+
#end
|
134
|
+
|
135
|
+
#describe "#file_modified_before_timestamp??" do
|
136
|
+
#it "returns true when no timestamp is given" do
|
137
|
+
#@server.send(:file_modified_before_timestamp?, @image_path).should be_true
|
138
|
+
#end
|
139
|
+
|
140
|
+
#it "returns true when the file was modified before the timestamp" do
|
141
|
+
#timestamp = DateTime.parse(File.mtime(@image_path).iso8601) + 100
|
142
|
+
#@server.send(:file_modified_before_timestamp?, @image_path, timestamp).should be_true
|
143
|
+
#end
|
144
|
+
|
145
|
+
#it "returns false when file was not modified before the timestamp" do
|
146
|
+
#timestamp = DateTime.parse(File.mtime(@image_path).iso8601)
|
147
|
+
#@server.send(:file_modified_before_timestamp?, @image_path, timestamp).should be_false
|
148
|
+
#end
|
149
|
+
#end
|
150
|
+
#end
|