fleakr 0.3.0 → 0.4.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.
Files changed (51) hide show
  1. data/README.rdoc +114 -19
  2. data/Rakefile +1 -1
  3. data/lib/fleakr/api/file_parameter.rb +47 -0
  4. data/lib/fleakr/api/method_request.rb +57 -0
  5. data/lib/fleakr/api/parameter.rb +35 -0
  6. data/lib/fleakr/api/parameter_list.rb +96 -0
  7. data/lib/fleakr/api/response.rb +2 -2
  8. data/lib/fleakr/api/upload_request.rb +64 -0
  9. data/lib/fleakr/api/value_parameter.rb +36 -0
  10. data/lib/fleakr/api.rb +7 -0
  11. data/lib/fleakr/core_ext/hash.rb +22 -0
  12. data/lib/fleakr/core_ext.rb +1 -0
  13. data/lib/fleakr/objects/authentication_token.rb +43 -0
  14. data/lib/fleakr/objects/contact.rb +5 -5
  15. data/lib/fleakr/objects/error.rb +2 -2
  16. data/lib/fleakr/objects/group.rb +2 -2
  17. data/lib/fleakr/objects/image.rb +7 -7
  18. data/lib/fleakr/objects/photo.rb +69 -5
  19. data/lib/fleakr/objects/search.rb +3 -6
  20. data/lib/fleakr/objects/set.rb +11 -5
  21. data/lib/fleakr/objects/user.rb +14 -26
  22. data/lib/fleakr/objects.rb +9 -0
  23. data/lib/fleakr/support/attribute.rb +30 -12
  24. data/lib/fleakr/support/object.rb +20 -4
  25. data/lib/fleakr/support.rb +2 -0
  26. data/lib/fleakr/version.rb +1 -1
  27. data/lib/fleakr.rb +66 -7
  28. data/test/fixtures/auth.checkToken.xml +8 -0
  29. data/test/fixtures/auth.getFullToken.xml +8 -0
  30. data/test/fixtures/people.getInfo.xml +1 -1
  31. data/test/fixtures/photos.getInfo.xml +20 -0
  32. data/test/test_helper.rb +18 -3
  33. data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
  34. data/test/unit/fleakr/api/method_request_test.rb +103 -0
  35. data/test/unit/fleakr/api/parameter_list_test.rb +161 -0
  36. data/test/unit/fleakr/api/parameter_test.rb +34 -0
  37. data/test/unit/fleakr/api/upload_request_test.rb +133 -0
  38. data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
  39. data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
  40. data/test/unit/fleakr/objects/authentication_token_test.rb +47 -0
  41. data/test/unit/fleakr/objects/image_test.rb +10 -5
  42. data/test/unit/fleakr/objects/photo_test.rb +96 -36
  43. data/test/unit/fleakr/objects/search_test.rb +1 -1
  44. data/test/unit/fleakr/objects/set_test.rb +12 -1
  45. data/test/unit/fleakr/objects/user_test.rb +2 -16
  46. data/test/unit/fleakr/support/attribute_test.rb +82 -24
  47. data/test/unit/fleakr/support/object_test.rb +26 -3
  48. data/test/unit/fleakr_test.rb +65 -6
  49. metadata +28 -5
  50. data/lib/fleakr/api/request.rb +0 -58
  51. data/test/unit/fleakr/api/request_test.rb +0 -93
@@ -0,0 +1,103 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Api
4
+ class MethodRequestTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of MethodRequest" do
7
+
8
+ context "with API credentials" do
9
+
10
+ before do
11
+ @api_key = 'f00b4r'
12
+ Fleakr.stubs(:api_key).with().returns(@api_key)
13
+ Fleakr.stubs(:shared_secret).with().returns('sekrit')
14
+ end
15
+
16
+ it "should know the full query parameters" do
17
+ request = MethodRequest.new('flickr.people.findByUsername', :username => 'foobar')
18
+
19
+ request.parameters[:api_key].value.should == @api_key
20
+ request.parameters[:method].value.should == 'flickr.people.findByUsername'
21
+ request.parameters[:username].value.should == 'foobar'
22
+ end
23
+
24
+ it "should translate a shorthand API call" do
25
+ request = MethodRequest.new('people.findByUsername')
26
+ request.parameters[:method].value.should == 'flickr.people.findByUsername'
27
+ end
28
+
29
+ it "should know that it needs to sign the request" do
30
+ ParameterList.expects(:new).with(:sign? => true).returns(stub(:<< => nil))
31
+ request = MethodRequest.new('people.findByUsername', :sign? => true)
32
+ end
33
+
34
+ it "should know that it needs to authenticate the request" do
35
+ ParameterList.expects(:new).with(:authenticate? => true).returns(stub(:<< => nil))
36
+ request = MethodRequest.new('activity.userPhotos', :authenticate? => true)
37
+ end
38
+
39
+ it "should know the endpoint with full parameters" do
40
+ query_parameters = 'foo=bar'
41
+
42
+ request = MethodRequest.new('people.getInfo')
43
+ request.parameters.stubs(:to_query).returns(query_parameters)
44
+
45
+ uri_mock = mock() {|m| m.expects(:query=).with(query_parameters)}
46
+ URI.expects(:parse).with("http://api.flickr.com/services/rest/").returns(uri_mock)
47
+
48
+ request.__send__(:endpoint_uri).should == uri_mock
49
+ end
50
+
51
+ it "should be able to make a request" do
52
+ endpoint_uri = stub()
53
+
54
+ request = MethodRequest.new('people.findByUsername')
55
+ request.stubs(:endpoint_uri).with().returns(endpoint_uri)
56
+
57
+ Net::HTTP.expects(:get).with(endpoint_uri).returns('<xml>')
58
+
59
+ request.send
60
+ end
61
+
62
+ it "should create a response from the request" do
63
+ response_xml = '<xml>'
64
+ response_stub = stub()
65
+
66
+ Net::HTTP.stubs(:get).returns(response_xml)
67
+ Response.expects(:new).with(response_xml).returns(response_stub)
68
+
69
+ request = MethodRequest.new('people.findByUsername')
70
+ request.stubs(:endpoint_uri)
71
+
72
+ request.send.should == response_stub
73
+ end
74
+
75
+ it "should be able to make a full request and response cycle" do
76
+ method = 'flickr.people.findByUsername'
77
+ params = {:username => 'foobar'}
78
+
79
+ response = stub(:error? => false)
80
+
81
+ MethodRequest.expects(:new).with(method, params).returns(stub(:send => response))
82
+
83
+ MethodRequest.with_response!(method, params).should == response
84
+ end
85
+
86
+ it "should raise an exception when the full request / response cycle has errors" do
87
+ method = 'flickr.people.findByUsername'
88
+ params = {:username => 'foobar'}
89
+
90
+ response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
91
+
92
+ MethodRequest.expects(:new).with(method, params).returns(stub(:send => response))
93
+
94
+ lambda do
95
+ MethodRequest.with_response!('flickr.people.findByUsername', :username => 'foobar')
96
+ end.should raise_error(Fleakr::ApiError)
97
+ end
98
+
99
+ end
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Api
4
+ class ParameterListTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the ParameterList class" do
7
+
8
+ before do
9
+ @api_key = 'key'
10
+ @secret = 'foobar'
11
+
12
+ Fleakr.stubs(:shared_secret).with().returns(@secret)
13
+ Fleakr.stubs(:api_key).with().returns(@api_key)
14
+ @parameter_list = ParameterList.new
15
+ end
16
+
17
+ it "should contain the :api_key by default" do
18
+ @parameter_list[:api_key].name.should == 'api_key'
19
+ @parameter_list[:api_key].value.should == @api_key
20
+ @parameter_list[:api_key].include_in_signature?.should be(true)
21
+ end
22
+
23
+ it "should be able to create an initial list of parameters" do
24
+ parameter_list = ParameterList.new(:one => 'two')
25
+ parameter_list[:one].value.should == 'two'
26
+ end
27
+
28
+ it "should be able to add parameters to its list" do
29
+ parameter = ValueParameter.new('foo', 'bar')
30
+
31
+ @parameter_list << parameter
32
+ @parameter_list['foo'].should == parameter
33
+ end
34
+
35
+ it "should allow access to parameters by symbol" do
36
+ parameter = ValueParameter.new('foo', 'bar')
37
+ @parameter_list << parameter
38
+
39
+ @parameter_list[:foo].should == parameter
40
+ end
41
+
42
+ it "should overwrite existing values when a duplicate is added" do
43
+ length = @parameter_list.instance_variable_get(:@list).length
44
+ 2.times {@parameter_list << ValueParameter.new('foo', 'bar') }
45
+
46
+ @parameter_list.instance_variable_get(:@list).length.should == length + 1
47
+ end
48
+
49
+ it "should be able to calculate the signature of the parameters" do
50
+ @parameter_list << ValueParameter.new('foo', 'bar')
51
+ @parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}foobar")
52
+ end
53
+
54
+ it "should use the correct order when signing a list of multiple parameters" do
55
+ @parameter_list << ValueParameter.new('z', 'a')
56
+ @parameter_list << ValueParameter.new('a', 'z')
57
+
58
+ @parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}azapi_key#{@api_key}za")
59
+ end
60
+
61
+ it "should ignore the parameters that aren't included in the signature" do
62
+ @parameter_list << ValueParameter.new('foo', 'bar')
63
+ @parameter_list << ValueParameter.new('yes', 'no', false)
64
+
65
+ @parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}foobar")
66
+ end
67
+
68
+ it "should be able to generate a boundary for post data" do
69
+ rand = '0.123'
70
+
71
+ @parameter_list.stubs(:rand).with().returns(stub(:to_s => rand))
72
+ @parameter_list.boundary.should == Digest::MD5.hexdigest(rand)
73
+ end
74
+
75
+ it "should know that it doesn't need to sign the request by default" do
76
+ @parameter_list.sign?.should be(false)
77
+ end
78
+
79
+ it "should know that it needs to sign the request when asked" do
80
+ parameter_list = ParameterList.new(:sign? => true)
81
+ parameter_list.sign?.should be(true)
82
+ end
83
+
84
+ it "should know that it doesn't need to authenticate the request by default" do
85
+ @parameter_list.authenticate?.should be(false)
86
+ end
87
+
88
+ it "should know to authenticate the request when asked" do
89
+ Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
90
+
91
+ parameter_list = ParameterList.new(:authenticate? => true)
92
+ parameter_list.authenticate?.should be(true)
93
+ end
94
+
95
+ it "should contain the :auth_token parameter in the list if the request is to be authenticated" do
96
+ Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
97
+
98
+ parameter_list = ParameterList.new(:authenticate? => true)
99
+ auth_param = parameter_list[:auth_token]
100
+
101
+ auth_param.name.should == 'auth_token'
102
+ auth_param.value.should == 'toke'
103
+ auth_param.include_in_signature?.should be(true)
104
+ end
105
+
106
+ it "should know that it needs to sign the request when it is to be authenticated" do
107
+ Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
108
+
109
+ parameter_list = ParameterList.new(:authenticate? => true)
110
+ parameter_list.sign?.should be(true)
111
+ end
112
+
113
+ it "should include the signature in the list of parameters if the request is to be signed" do
114
+ parameter_list = ParameterList.new(:sign? => true)
115
+ parameter_list.stubs(:signature).with().returns('sig')
116
+
117
+ signature_param = parameter_list[:api_sig]
118
+
119
+ signature_param.name.should == 'api_sig'
120
+ signature_param.value.should == 'sig'
121
+ signature_param.include_in_signature?.should be(false)
122
+ end
123
+
124
+ context "with associated parameters" do
125
+
126
+ before do
127
+ @p1 = ValueParameter.new('a', 'b')
128
+ @p2 = ValueParameter.new('c', 'd')
129
+
130
+ @p1.stubs(:to_query).with().returns('q1')
131
+ @p1.stubs(:to_form).with().returns('f1')
132
+
133
+ @p2.stubs(:to_query).with().returns('q2')
134
+ @p2.stubs(:to_form).with().returns('f2')
135
+
136
+ @parameter_list.stubs(:list).with().returns('a' => @p1, 'c' => @p2)
137
+ end
138
+
139
+ it "should be able to generate a query representation of itself" do
140
+ @parameter_list.to_query.should == 'q1&q2'
141
+ end
142
+
143
+ it "should be able to represent a form representation of itself" do
144
+ @parameter_list.stubs(:boundary).returns('bound')
145
+
146
+ expected =
147
+ "--bound\r\n" +
148
+ "f1" +
149
+ "--bound\r\n" +
150
+ "f2" +
151
+ "--bound--"
152
+
153
+ @parameter_list.to_form.should == expected
154
+ end
155
+
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Api
4
+ class ParameterTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the Parameter class" do
7
+
8
+ it "should have a name" do
9
+ parameter = Parameter.new('foo')
10
+ parameter.name.should == 'foo'
11
+ end
12
+
13
+ it "should know to include it in the signature by default" do
14
+ parameter = Parameter.new('foo')
15
+ parameter.include_in_signature?.should be(true)
16
+ end
17
+
18
+ it "should know not to include it in the signature" do
19
+ parameter = Parameter.new('foo', false)
20
+ parameter.include_in_signature?.should be(false)
21
+ end
22
+
23
+ it "should be able to compare itself to another parameter instance" do
24
+ p1 = Parameter.new('z', 'a')
25
+ p2 = Parameter.new('a', 'z')
26
+
27
+ (p1 <=> p2).should == 1
28
+ end
29
+
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,133 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Api
4
+ class UploadRequestTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the UploadRequest class" do
7
+
8
+ before do
9
+ @secret = 'sekrit'
10
+ Fleakr.stubs(:shared_secret).with().returns(@secret)
11
+ end
12
+
13
+ it "should create a file parameter on initialization" do
14
+ filename = '/path/to/image.jpg'
15
+
16
+ parameter = stub()
17
+ FileParameter.expects(:new).with('photo', filename).returns(parameter)
18
+
19
+ parameter_list = mock() {|m| m.expects(:<<).with(parameter) }
20
+ ParameterList.expects(:new).with(:authenticate? => true).returns(parameter_list)
21
+
22
+ UploadRequest.new(filename)
23
+ end
24
+
25
+ it "should allow setting additional parameters on initialization" do
26
+ params = {:is_public => 1}
27
+
28
+ ParameterList.expects(:new).with({:is_public => 1, :authenticate? => true}).returns(stub(:<<))
29
+
30
+ UploadRequest.new('filename', params)
31
+ end
32
+
33
+ context "after initialization" do
34
+
35
+ before { ParameterList.stubs(:new).returns(stub(:<< => nil)) }
36
+
37
+ it "should default the type to :create" do
38
+ request = UploadRequest.new('file')
39
+ request.type.should == :create
40
+ end
41
+
42
+ it "should allow setting the type to :update" do
43
+ request = UploadRequest.new('file', :type => :update)
44
+ request.type.should == :update
45
+ end
46
+
47
+ it "should know the endpoint_uri" do
48
+ request = UploadRequest.new('filename')
49
+ request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/upload/')
50
+ end
51
+
52
+ it "should know the endpoint_uri for an :update request" do
53
+ request = UploadRequest.new('filename', :type => :update)
54
+ request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/replace/')
55
+ end
56
+
57
+ it "should only parse the endpoint URI once" do
58
+ request = UploadRequest.new('filename')
59
+ URI.expects(:parse).with(kind_of(String)).once.returns('uri')
60
+
61
+ 2.times { request.__send__(:endpoint_uri) }
62
+ end
63
+
64
+ it "should have a collection of required headers" do
65
+ form_data = 'data'
66
+
67
+ request = UploadRequest.new('filename')
68
+ request.parameters.stubs(:boundary).with().returns('bound')
69
+ request.parameters.stubs(:to_form).with().returns(form_data)
70
+
71
+ expected = {
72
+ 'Content-Type' => 'multipart/form-data; boundary=bound'
73
+ }
74
+
75
+ request.headers.should == expected
76
+ end
77
+
78
+ it "should be able to send a POST request to the API service" do
79
+ request = UploadRequest.new('filename')
80
+
81
+ uri = stub do |s|
82
+ s.stubs(:host).with().returns('host')
83
+ s.stubs(:path).with().returns('path')
84
+ s.stubs(:port).with().returns(80)
85
+ end
86
+
87
+ request.stubs(:endpoint_uri).with().returns(uri)
88
+
89
+ request.stubs(:headers).with().returns('header' => 'value')
90
+ request.parameters.stubs(:to_form).with().returns('form')
91
+
92
+ http = mock {|m| m.expects(:post).with('path', 'form', {'header' => 'value'}) }
93
+
94
+ Net::HTTP.expects(:start).with('host', 80).yields(http).returns(stub(:body))
95
+
96
+ request.send
97
+ end
98
+
99
+ it "should get back a response from a POST operation" do
100
+ response = stub()
101
+
102
+ Net::HTTP.expects(:start).with(kind_of(String), kind_of(Fixnum)).returns(stub(:body => '<xml>'))
103
+ Response.expects(:new).with('<xml>').returns(response)
104
+
105
+ request = UploadRequest.new('filename')
106
+ request.send.should == response
107
+ end
108
+
109
+ it "should be able to make a full request and response cycle" do
110
+ filename = 'filename'
111
+ response = stub(:error? => false)
112
+
113
+ UploadRequest.expects(:new).with(filename, {}).returns(stub(:send => response))
114
+ UploadRequest.with_response!(filename).should == response
115
+ end
116
+
117
+ it "should raise an exception when the full request / response cycle has errors" do
118
+ filename = 'filename'
119
+ response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
120
+
121
+ UploadRequest.expects(:new).with(filename, {}).returns(stub(:send => response))
122
+
123
+ lambda do
124
+ UploadRequest.with_response!(filename)
125
+ end.should raise_error(Fleakr::ApiError)
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Api
4
+ class ValueParameterTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the ValueParameter class" do
7
+
8
+ it "should have a value" do
9
+ parameter = ValueParameter.new('foo', 'bar')
10
+ parameter.value.should == 'bar'
11
+ end
12
+
13
+ it "should know how to generate the query representation of itself" do
14
+ parameter = ValueParameter.new('foo', 'bar')
15
+ parameter.to_query.should == 'foo=bar'
16
+ end
17
+
18
+ it "should escape the value when generating the query representation" do
19
+ parameter = ValueParameter.new('foo', 'Mr. Crystal?')
20
+ parameter.to_query.should == 'foo=Mr.+Crystal%3F'
21
+ end
22
+
23
+ it "should use an empty string when generating a query if the parameter value is nil" do
24
+ parameter = ValueParameter.new('foo', nil)
25
+ parameter.to_query.should == 'foo='
26
+ end
27
+
28
+ it "should know how to generate the form representation of itself" do
29
+ parameter = ValueParameter.new('foo', 'bar')
30
+ expected =
31
+ 'Content-Disposition: form-data; name="foo"' + "\r\n" +
32
+ "\r\n" +
33
+ "bar\r\n"
34
+
35
+ parameter.to_form.should == expected
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class HashTest < Test::Unit::TestCase
4
+
5
+ describe "An instance of Hash" do
6
+ context "when extracting key/value pairs" do
7
+
8
+ before do
9
+ @hash = {:one => 'two', :three => 'four'}
10
+ end
11
+
12
+ it "should return a hash with the matching key/value pairs" do
13
+ @hash.extract!(:one).should == {:one => 'two'}
14
+ end
15
+
16
+ it "should return an empty hash if the key isn't found" do
17
+ @hash.extract!(:foo).should == {}
18
+ end
19
+
20
+ it "should alter the original hash when a value is extracted" do
21
+ @hash.extract!(:one)
22
+ @hash.should == {:three => 'four'}
23
+ end
24
+
25
+ it "should be able to extract multiple keys" do
26
+ @hash.extract!(:one, :three, :missing).should == {:one => 'two', :three => 'four'}
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class AuthenticationTokenTest < Test::Unit::TestCase
5
+
6
+ describe "The AuthenticationToken class" do
7
+
8
+ it "should be able to create an instance from a mini_token" do
9
+ token = '123-123-123'
10
+ auth_token = stub()
11
+
12
+ response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :sign? => true}
13
+
14
+ AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
15
+
16
+ AuthenticationToken.from_mini_token(token).should == auth_token
17
+ end
18
+
19
+ it "should be able to create an instance from an auth_token" do
20
+ token = 'abc123'
21
+ auth_token = stub()
22
+
23
+ response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :sign? => true}
24
+
25
+ AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
26
+ AuthenticationToken.from_auth_token(token).should == auth_token
27
+ end
28
+
29
+ end
30
+
31
+ describe "An instance of the AuthenticationToken class" do
32
+
33
+ context "when populating from an XML document" do
34
+
35
+ before do
36
+ @object = AuthenticationToken.new(Hpricot.XML(read_fixture('auth.getFullToken')))
37
+ end
38
+
39
+ should_have_a_value_for :value => 'abc-123'
40
+ should_have_a_value_for :permissions => 'delete'
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -45,6 +45,9 @@ module Fleakr::Objects
45
45
  @image = Image.new
46
46
  @image.stubs(:url).with().returns(@url)
47
47
  @image.stubs(:filename).with().returns(@image_filename)
48
+
49
+ @image_data = 'image_data'
50
+ Net::HTTP.expects(:get).with(URI.parse(@url)).returns(@image_data)
48
51
  end
49
52
 
50
53
  after do
@@ -52,20 +55,22 @@ module Fleakr::Objects
52
55
  end
53
56
 
54
57
  should "be able to save to a directory with the original filename" do
55
- Net::HTTP.expects(:get).with(URI.parse(@url)).returns('image_data')
56
-
57
58
  @image.save_to(@tmp_dir)
58
- File.read("#{@tmp_dir}/image.jpg").should == 'image_data'
59
+ File.read("#{@tmp_dir}/image.jpg").should == @image_data
59
60
  end
60
61
 
61
62
  should "be able to save to a specified file" do
62
- Net::HTTP.expects(:get).with(URI.parse(@url)).returns('image_data')
63
63
  existing_file = "#{@tmp_dir}/existing_file.jpg"
64
64
 
65
65
  FileUtils.touch(existing_file)
66
66
 
67
67
  @image.save_to(existing_file)
68
- File.read(existing_file).should == 'image_data'
68
+ File.read(existing_file).should == @image_data
69
+ end
70
+
71
+ should "be able to save the file using a specified prefix" do
72
+ @image.save_to(@tmp_dir, '001_')
73
+ File.read("#{@tmp_dir}/001_image.jpg").should == @image_data
69
74
  end
70
75
 
71
76
  end