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
@@ -1,55 +1,55 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe SnapImage::Image do
|
4
|
-
before do
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#crop" do
|
9
|
-
before do
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
it "correctly crops image" do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#resize" do
|
22
|
-
before do
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
it "raises an error when no height is specified and maintaining aspect ratio is false" do
|
28
|
-
expect { @image.resize(100, nil, false) }.should raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it "resizes the image when the width is larger or equal to the height" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
it "resizes the image when the width is less than the height" do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
it "resizes the image to fit within the width/height while maintaining aspect ratio" do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
it "stretches image when not maintaining aspect ratio" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
#require "spec_helper"
|
2
|
+
|
3
|
+
#describe SnapImage::Image do
|
4
|
+
#before do
|
5
|
+
#@image_path = File.join(RSpec.root, "support/assets/stub-300x200.png")
|
6
|
+
#end
|
7
|
+
|
8
|
+
#describe "#crop" do
|
9
|
+
#before do
|
10
|
+
#@image = SnapImage::Image.new
|
11
|
+
#@image.set_image_from_path(@image_path)
|
12
|
+
#end
|
13
|
+
|
14
|
+
#it "correctly crops image" do
|
15
|
+
#@image.crop(10, 30, 20, 30)
|
16
|
+
#@image.width.should eq 20
|
17
|
+
#@image.height.should eq 30
|
18
|
+
#end
|
19
|
+
#end
|
20
|
+
|
21
|
+
#describe "#resize" do
|
22
|
+
#before do
|
23
|
+
#@image = SnapImage::Image.new
|
24
|
+
#@image.set_image_from_path(@image_path)
|
25
|
+
#end
|
26
|
+
|
27
|
+
#it "raises an error when no height is specified and maintaining aspect ratio is false" do
|
28
|
+
#expect { @image.resize(100, nil, false) }.should raise_error
|
29
|
+
#end
|
30
|
+
|
31
|
+
#it "resizes the image when the width is larger or equal to the height" do
|
32
|
+
#@image.resize(330)
|
33
|
+
#@image.width.should eq 330
|
34
|
+
#@image.height.should eq 220
|
35
|
+
#end
|
36
|
+
|
37
|
+
#it "resizes the image when the width is less than the height" do
|
38
|
+
#@image.resize(150)
|
39
|
+
#@image.width.should eq 150
|
40
|
+
#@image.height.should eq 100
|
41
|
+
#end
|
42
|
+
|
43
|
+
#it "resizes the image to fit within the width/height while maintaining aspect ratio" do
|
44
|
+
#@image.resize(150, 200)
|
45
|
+
#@image.width.should eq 150
|
46
|
+
#@image.height.should eq 100
|
47
|
+
#end
|
48
|
+
|
49
|
+
#it "stretches image when not maintaining aspect ratio" do
|
50
|
+
#@image.resize(100, 200, false)
|
51
|
+
#@image.width.should eq 100
|
52
|
+
#@image.height.should eq 200
|
53
|
+
#end
|
54
|
+
#end
|
55
|
+
#end
|
@@ -1,15 +1,4 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe SnapImage::RequestFile do
|
4
|
-
describe "#type" do
|
5
|
-
it "returns the correct type" do
|
6
|
-
file = SnapImage::RequestFile.new({filename: "image.png"})
|
7
|
-
file.type.should eq "png"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns jpg when the type is jpeg" do
|
11
|
-
file = SnapImage::RequestFile.new({filename: "image.jpeg"})
|
12
|
-
file.type.should eq "jpg"
|
13
|
-
end
|
14
|
-
end
|
15
4
|
end
|
@@ -7,46 +7,27 @@ describe SnapImage::Request do
|
|
7
7
|
|
8
8
|
describe "#bad_request?" do
|
9
9
|
it "returns true if the request is not a post" do
|
10
|
-
json = { action: "test", resource_identifier: "123" }.to_json
|
11
10
|
@request.stub(:post?).and_return(false)
|
12
|
-
@request.stub(:POST).and_return({"
|
11
|
+
@request.stub(:POST).and_return({ "file" => "abc", "directory" => "123" })
|
13
12
|
@request.bad_request?.should be_true
|
14
13
|
end
|
15
14
|
|
16
|
-
it "returns true if the request does not include
|
15
|
+
it "returns true if the request does not include file" do
|
17
16
|
@request.stub(:post?).and_return(true)
|
18
|
-
@request.stub(:POST).and_return({})
|
17
|
+
@request.stub(:POST).and_return({ "directory" => "123" })
|
19
18
|
@request.bad_request?.should be_true
|
20
19
|
end
|
21
20
|
|
22
|
-
it "returns true if the request does not include
|
23
|
-
json = { resource_identifier: "123" }.to_json
|
21
|
+
it "returns true if the request does not include directory" do
|
24
22
|
@request.stub(:post?).and_return(true)
|
25
|
-
@request.stub(:POST).and_return({"
|
26
|
-
@request.bad_request?.should be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns true if the request does not include a resource_identifier" do
|
30
|
-
json = { action: "test" }.to_json
|
31
|
-
@request.stub(:post?).and_return(true)
|
32
|
-
@request.stub(:POST).and_return({"json" => json})
|
23
|
+
@request.stub(:POST).and_return({ "file" => "abc" })
|
33
24
|
@request.bad_request?.should be_true
|
34
25
|
end
|
35
26
|
|
36
27
|
it "returns false if the request is valid" do
|
37
|
-
json = { action: "test", resource_identifier: "123" }.to_json
|
38
28
|
@request.stub(:post?).and_return(true)
|
39
|
-
@request.stub(:POST).and_return({"
|
29
|
+
@request.stub(:POST).and_return({ "file" => "abc", "directory" => "123" })
|
40
30
|
@request.bad_request?.should be_false
|
41
31
|
end
|
42
32
|
end
|
43
|
-
|
44
|
-
describe "#json" do
|
45
|
-
it "returns the json object" do
|
46
|
-
@request.stub(:bad_request?).and_return(false)
|
47
|
-
@request.stub(:POST).and_return({"json" => '{"data":"value"}'})
|
48
|
-
json = @request.json
|
49
|
-
json["data"].should eq "value"
|
50
|
-
end
|
51
|
-
end
|
52
33
|
end
|
@@ -1,67 +1,67 @@
|
|
1
|
-
require "spec_helper"
|
1
|
+
#require "spec_helper"
|
2
2
|
|
3
|
-
describe SnapImage::ServerActions::Authorize do
|
4
|
-
before do
|
5
|
-
class TestServerActions
|
6
|
-
include SnapImage::ServerActions::Authorize
|
3
|
+
#describe SnapImage::ServerActions::Authorize do
|
4
|
+
#before do
|
5
|
+
#class TestServerActions
|
6
|
+
#include SnapImage::ServerActions::Authorize
|
7
7
|
|
8
|
-
attr_accessor :config
|
8
|
+
#attr_accessor :config
|
9
9
|
|
10
|
-
def initialize(request)
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
10
|
+
#def initialize(request)
|
11
|
+
#@request = request
|
12
|
+
#@config = {"security_salt" => "abc123"}
|
13
|
+
#end
|
14
|
+
#end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
16
|
+
#@request = double("request")
|
17
|
+
#@actions = TestServerActions.new(@request)
|
18
|
+
#end
|
19
19
|
|
20
|
-
describe "#token_available?" do
|
21
|
-
before do
|
22
|
-
|
23
|
-
end
|
24
|
-
it "returns true when role's token is set" do
|
25
|
-
|
26
|
-
end
|
20
|
+
#describe "#token_available?" do
|
21
|
+
#before do
|
22
|
+
#@request.stub(:json).and_return({"client_security_token" => "abc123"})
|
23
|
+
#end
|
24
|
+
#it "returns true when role's token is set" do
|
25
|
+
#@actions.token_available?(:client).should be_true
|
26
|
+
#end
|
27
27
|
|
28
|
-
it "returns false when role's token is not set" do
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
28
|
+
#it "returns false when role's token is not set" do
|
29
|
+
#@actions.token_available?(:server).should be_false
|
30
|
+
#end
|
31
|
+
#end
|
32
32
|
|
33
|
-
describe "#generate_tokens" do
|
34
|
-
before do
|
35
|
-
|
36
|
-
end
|
33
|
+
#describe "#generate_tokens" do
|
34
|
+
#before do
|
35
|
+
#@request.stub(:json).and_return({"resource_identifier" => "123"})
|
36
|
+
#end
|
37
37
|
|
38
|
-
it "generates three token" do
|
39
|
-
now = Time.now
|
40
|
-
yesterday = (now - 24*60*60).strftime("%Y-%m-%d")
|
41
|
-
today = now.strftime("%Y-%m-%d")
|
42
|
-
tomorrow = (now + 24*60*60).strftime("%Y-%m-%d")
|
43
|
-
yesterday_token = Digest::SHA1.hexdigest("client:#{yesterday}:abc123:123")
|
44
|
-
today_token = Digest::SHA1.hexdigest("client:#{today}:abc123:123")
|
45
|
-
tomorrow_token = Digest::SHA1.hexdigest("client:#{tomorrow}:abc123:123")
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
38
|
+
#it "generates three token" do
|
39
|
+
#now = Time.now
|
40
|
+
#yesterday = (now - 24*60*60).strftime("%Y-%m-%d")
|
41
|
+
#today = now.strftime("%Y-%m-%d")
|
42
|
+
#tomorrow = (now + 24*60*60).strftime("%Y-%m-%d")
|
43
|
+
#yesterday_token = Digest::SHA1.hexdigest("client:#{yesterday}:abc123:123")
|
44
|
+
#today_token = Digest::SHA1.hexdigest("client:#{today}:abc123:123")
|
45
|
+
#tomorrow_token = Digest::SHA1.hexdigest("client:#{tomorrow}:abc123:123")
|
46
|
+
#@actions.generate_tokens(:client).should eq [yesterday_token, today_token, tomorrow_token]
|
47
|
+
#end
|
48
|
+
#end
|
49
49
|
|
50
|
-
describe "#authorize" do
|
51
|
-
it "returns true when the security_salt is not set" do
|
52
|
-
|
53
|
-
|
54
|
-
end
|
50
|
+
#describe "#authorize" do
|
51
|
+
#it "returns true when the security_salt is not set" do
|
52
|
+
#@actions.config = {}
|
53
|
+
#@actions.authorize(:client).should be_true
|
54
|
+
#end
|
55
55
|
|
56
|
-
it "raises an error when the token is not available" do
|
57
|
-
|
58
|
-
expect { @actions.authorize(:client) }.should raise_error SnapImage::AuthorizationRequired
|
59
|
-
end
|
56
|
+
#it "raises an error when the token is not available" do
|
57
|
+
#@actions.stub(:token_available?).and_return(false)
|
58
|
+
#expect { @actions.authorize(:client) }.should raise_error SnapImage::AuthorizationRequired
|
59
|
+
#end
|
60
60
|
|
61
|
-
it "raises an error when the token does not match" do
|
62
|
-
|
63
|
-
|
64
|
-
expect { @actions.authorize(:client) }.should raise_error SnapImage::AuthorizationFailed
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
61
|
+
#it "raises an error when the token does not match" do
|
62
|
+
#@request.stub(:json).and_return({"client_security_token" => "abc123", "resource_identifier" => "123"})
|
63
|
+
#@actions.stub(:token_available?).and_return(true)
|
64
|
+
#expect { @actions.authorize(:client) }.should raise_error SnapImage::AuthorizationFailed
|
65
|
+
#end
|
66
|
+
#end
|
67
|
+
#end
|
@@ -1,146 +1,146 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe SnapImage::ServerActions::GenerateImage do
|
4
|
-
before do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#source_image_defined?" do
|
15
|
-
it "returns false if file and url are not defined" do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns true when file is defined" do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns true when url is defined" do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#get_max_width?" do
|
35
|
-
it "returns the server max width when JSON 'max_width' is not defined" do
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns the server max width when JSON 'max_width' is larger" do
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns the JSON 'max_width' when server max width is larger" do
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#get_max_height?" do
|
52
|
-
it "returns the server max height when JSON 'max_height' is not defined" do
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
it "returns the server max height when JSON 'max_height' is larger" do
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns the JSON 'max_height' when server max height is larger" do
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#get_image_for_modification" do
|
69
|
-
context "upload" do
|
70
|
-
before do
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
it "uploads the image and returns it when a file is specified" do
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
it "downloads the image and returns it when a local url is specified" do
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "modify" do
|
90
|
-
before do
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
it "gets the base image" do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "#modify_image" do
|
103
|
-
before do
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
it "does nothing when there are no modifications" do
|
108
|
-
|
109
|
-
result = @generate_image.send(:modify_image, @image)
|
110
|
-
result[:image].should be @image
|
111
|
-
result[:name].should eq "12345678-300x200.png"
|
112
|
-
end
|
113
|
-
|
114
|
-
it "crops" do
|
115
|
-
|
116
|
-
result = @generate_image.send(:modify_image, @image)
|
117
|
-
result[:image].width.should eq 50
|
118
|
-
result[:image].height.should eq 100
|
119
|
-
result[:name].should eq "12345678-300x200-10x20x50x100-50x100-0.png"
|
120
|
-
end
|
121
|
-
|
122
|
-
it "resizes" do
|
123
|
-
|
124
|
-
result = @generate_image.send(:modify_image, @image)
|
125
|
-
result[:image].width.should eq 400
|
126
|
-
result[:image].height.should eq 50
|
127
|
-
result[:name].should eq "12345678-300x200-0x0x300x200-400x50-0.png"
|
128
|
-
end
|
129
|
-
|
130
|
-
it "resizes to fit" do
|
131
|
-
|
132
|
-
result = @generate_image.send(:modify_image, @image)
|
133
|
-
result[:image].width.should eq 1024
|
134
|
-
result[:image].height.should eq 50
|
135
|
-
result[:name].should eq "12345678-300x200-0x0x300x200-1024x50-0.png"
|
136
|
-
end
|
137
|
-
|
138
|
-
it "sharpens" do
|
139
|
-
|
140
|
-
result = @generate_image.send(:modify_image, @image)
|
141
|
-
result[:image].width.should eq 300
|
142
|
-
result[:image].height.should eq 200
|
143
|
-
result[:name].should eq "12345678-300x200-0x0x300x200-300x200-1.png"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
1
|
+
#require "spec_helper"
|
2
|
+
|
3
|
+
#describe SnapImage::ServerActions::GenerateImage 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
|
+
#@generate_image = SnapImage::ServerActions::GenerateImage.new(@config, @request, @response)
|
12
|
+
#end
|
13
|
+
|
14
|
+
#describe "#source_image_defined?" do
|
15
|
+
#it "returns false if file and url are not defined" do
|
16
|
+
#@request.stub(:file).and_return(nil)
|
17
|
+
#@request.stub(:json).and_return({})
|
18
|
+
#@generate_image.send(:source_image_defined?).should be_false
|
19
|
+
#end
|
20
|
+
|
21
|
+
#it "returns true when file is defined" do
|
22
|
+
#@request.stub(:file).and_return("file")
|
23
|
+
#@request.stub(:json).and_return({})
|
24
|
+
#@generate_image.send(:source_image_defined?).should be_true
|
25
|
+
#end
|
26
|
+
|
27
|
+
#it "returns true when url is defined" do
|
28
|
+
#@request.stub(:file).and_return(nil)
|
29
|
+
#@request.stub(:json).and_return({"url" => "something"})
|
30
|
+
#@generate_image.send(:source_image_defined?).should be_true
|
31
|
+
#end
|
32
|
+
#end
|
33
|
+
|
34
|
+
#describe "#get_max_width?" do
|
35
|
+
#it "returns the server max width when JSON 'max_width' is not defined" do
|
36
|
+
#@request.stub(:json).and_return({})
|
37
|
+
#@generate_image.send(:get_max_width).should eq 1024
|
38
|
+
#end
|
39
|
+
|
40
|
+
#it "returns the server max width when JSON 'max_width' is larger" do
|
41
|
+
#@request.stub(:json).and_return({"max_width" => "4096"})
|
42
|
+
#@generate_image.send(:get_max_width).should eq 1024
|
43
|
+
#end
|
44
|
+
|
45
|
+
#it "returns the JSON 'max_width' when server max width is larger" do
|
46
|
+
#@request.stub(:json).and_return({"max_width" => "640"})
|
47
|
+
#@generate_image.send(:get_max_width).should eq 640
|
48
|
+
#end
|
49
|
+
#end
|
50
|
+
|
51
|
+
#describe "#get_max_height?" do
|
52
|
+
#it "returns the server max height when JSON 'max_height' is not defined" do
|
53
|
+
#@request.stub(:json).and_return({})
|
54
|
+
#@generate_image.send(:get_max_height).should eq 2048
|
55
|
+
#end
|
56
|
+
|
57
|
+
#it "returns the server max height when JSON 'max_height' is larger" do
|
58
|
+
#@request.stub(:json).and_return({"max_height" => "4096"})
|
59
|
+
#@generate_image.send(:get_max_height).should eq 2048
|
60
|
+
#end
|
61
|
+
|
62
|
+
#it "returns the JSON 'max_height' when server max height is larger" do
|
63
|
+
#@request.stub(:json).and_return({"max_height" => "640"})
|
64
|
+
#@generate_image.send(:get_max_height).should eq 640
|
65
|
+
#end
|
66
|
+
#end
|
67
|
+
|
68
|
+
#describe "#get_image_for_modification" do
|
69
|
+
#context "upload" do
|
70
|
+
#before do
|
71
|
+
#@generate_image.stub(:upload?).and_return(true)
|
72
|
+
#end
|
73
|
+
|
74
|
+
#it "uploads the image and returns it when a file is specified" do
|
75
|
+
#@request.stub(:file).and_return("file")
|
76
|
+
#@request.stub(:json).and_return({"resource_identifier" => "abc123"})
|
77
|
+
#@storage.should_receive(:add_upload).with("file", "abc123").once.and_return("image")
|
78
|
+
#@generate_image.send(:get_image_for_modification).should eq "image"
|
79
|
+
#end
|
80
|
+
|
81
|
+
#it "downloads the image and returns it when a local url is specified" do
|
82
|
+
#@request.stub(:file).and_return(nil)
|
83
|
+
#@request.stub(:json).and_return({"url" => "http://example.com/12345678-1024x768.png", "resource_identifier" => "abc123"})
|
84
|
+
#@storage.should_receive(:add_url).with("http://example.com/12345678-1024x768.png", "abc123").once.and_return("image")
|
85
|
+
#@generate_image.send(:get_image_for_modification).should eq "image"
|
86
|
+
#end
|
87
|
+
#end
|
88
|
+
|
89
|
+
#context "modify" do
|
90
|
+
#before do
|
91
|
+
#@generate_image.stub(:upload?).and_return(false)
|
92
|
+
#end
|
93
|
+
|
94
|
+
#it "gets the base image" do
|
95
|
+
#@request.stub(:json).and_return("url" => "http://example.com/fi3k2od0-1027x768-1x2x640x480-300x200-1.png")
|
96
|
+
#@storage.should_receive(:get).with("http://example.com/fi3k2od0-1027x768.png").once.and_return("image")
|
97
|
+
#@generate_image.send(:get_image_for_modification).should eq "image"
|
98
|
+
#end
|
99
|
+
#end
|
100
|
+
#end
|
101
|
+
|
102
|
+
#describe "#modify_image" do
|
103
|
+
#before do
|
104
|
+
#@image = SnapImage::Image.from_path(@image_path, "http://example.com/12345678-300x200.png")
|
105
|
+
#end
|
106
|
+
|
107
|
+
#it "does nothing when there are no modifications" do
|
108
|
+
#@request.stub(:json).and_return({})
|
109
|
+
#result = @generate_image.send(:modify_image, @image)
|
110
|
+
#result[:image].should be @image
|
111
|
+
#result[:name].should eq "12345678-300x200.png"
|
112
|
+
#end
|
113
|
+
|
114
|
+
#it "crops" do
|
115
|
+
#@request.stub(:json).and_return({"crop_x" => 10, "crop_y" => 20, "crop_width" => 50, "crop_height" => 100})
|
116
|
+
#result = @generate_image.send(:modify_image, @image)
|
117
|
+
#result[:image].width.should eq 50
|
118
|
+
#result[:image].height.should eq 100
|
119
|
+
#result[:name].should eq "12345678-300x200-10x20x50x100-50x100-0.png"
|
120
|
+
#end
|
121
|
+
|
122
|
+
#it "resizes" do
|
123
|
+
#@request.stub(:json).and_return({"width" => 400, "height" => 50})
|
124
|
+
#result = @generate_image.send(:modify_image, @image)
|
125
|
+
#result[:image].width.should eq 400
|
126
|
+
#result[:image].height.should eq 50
|
127
|
+
#result[:name].should eq "12345678-300x200-0x0x300x200-400x50-0.png"
|
128
|
+
#end
|
129
|
+
|
130
|
+
#it "resizes to fit" do
|
131
|
+
#@request.stub(:json).and_return({"width" => 2048, "height" => 100})
|
132
|
+
#result = @generate_image.send(:modify_image, @image)
|
133
|
+
#result[:image].width.should eq 1024
|
134
|
+
#result[:image].height.should eq 50
|
135
|
+
#result[:name].should eq "12345678-300x200-0x0x300x200-1024x50-0.png"
|
136
|
+
#end
|
137
|
+
|
138
|
+
#it "sharpens" do
|
139
|
+
#@request.stub(:json).and_return({"sharpen" => true})
|
140
|
+
#result = @generate_image.send(:modify_image, @image)
|
141
|
+
#result[:image].width.should eq 300
|
142
|
+
#result[:image].height.should eq 200
|
143
|
+
#result[:name].should eq "12345678-300x200-0x0x300x200-300x200-1.png"
|
144
|
+
#end
|
145
|
+
#end
|
146
|
+
#end
|