fleakr 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/README.rdoc +6 -1
  2. data/Rakefile +1 -1
  3. data/lib/fleakr.rb +2 -1
  4. data/lib/fleakr/api/option.rb +6 -6
  5. data/lib/fleakr/version.rb +2 -2
  6. data/test/test_helper.rb +9 -8
  7. data/test/unit/fleakr/api/file_parameter_test.rb +8 -8
  8. data/test/unit/fleakr/api/method_request_test.rb +11 -10
  9. data/test/unit/fleakr/api/option_test.rb +29 -29
  10. data/test/unit/fleakr/api/parameter_list_test.rb +22 -22
  11. data/test/unit/fleakr/api/parameter_test.rb +5 -5
  12. data/test/unit/fleakr/api/response_test.rb +6 -6
  13. data/test/unit/fleakr/api/upload_request_test.rb +28 -24
  14. data/test/unit/fleakr/api/value_parameter_test.rb +6 -6
  15. data/test/unit/fleakr/core_ext/false_class_test.rb +2 -2
  16. data/test/unit/fleakr/core_ext/hash_test.rb +6 -6
  17. data/test/unit/fleakr/core_ext/true_class_test.rb +2 -2
  18. data/test/unit/fleakr/objects/authentication_token_test.rb +6 -6
  19. data/test/unit/fleakr/objects/comment_test.rb +8 -8
  20. data/test/unit/fleakr/objects/contact_test.rb +8 -5
  21. data/test/unit/fleakr/objects/error_test.rb +2 -2
  22. data/test/unit/fleakr/objects/group_test.rb +5 -5
  23. data/test/unit/fleakr/objects/image_test.rb +6 -6
  24. data/test/unit/fleakr/objects/photo_context_test.rb +11 -11
  25. data/test/unit/fleakr/objects/photo_test.rb +32 -29
  26. data/test/unit/fleakr/objects/search_test.rb +9 -9
  27. data/test/unit/fleakr/objects/set_test.rb +9 -9
  28. data/test/unit/fleakr/objects/tag_test.rb +12 -12
  29. data/test/unit/fleakr/objects/user_test.rb +10 -10
  30. data/test/unit/fleakr/support/attribute_test.rb +21 -21
  31. data/test/unit/fleakr/support/object_test.rb +17 -17
  32. data/test/unit/fleakr_test.rb +24 -24
  33. metadata +3 -3
@@ -3,24 +3,24 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Api
4
4
  class ParameterTest < Test::Unit::TestCase
5
5
 
6
- describe "An instance of the Parameter class" do
6
+ context "An instance of the Parameter class" do
7
7
 
8
- it "should have a name" do
8
+ should "have a name" do
9
9
  parameter = Parameter.new('foo')
10
10
  parameter.name.should == 'foo'
11
11
  end
12
12
 
13
- it "should know to include it in the signature by default" do
13
+ should "know to include it in the signature by default" do
14
14
  parameter = Parameter.new('foo')
15
15
  parameter.include_in_signature?.should be(true)
16
16
  end
17
17
 
18
- it "should know not to include it in the signature" do
18
+ should "know not to include it in the signature" do
19
19
  parameter = Parameter.new('foo', false)
20
20
  parameter.include_in_signature?.should be(false)
21
21
  end
22
22
 
23
- it "should be able to compare itself to another parameter instance" do
23
+ should "be able to compare itself to another parameter instance" do
24
24
  p1 = Parameter.new('z', 'a')
25
25
  p2 = Parameter.new('a', 'z')
26
26
 
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Api
4
4
  class ResponseTest < Test::Unit::TestCase
5
5
 
6
- describe "An instance of Response" do
6
+ context "An instance of Response" do
7
7
 
8
- it "should provide the response body as an Hpricot element" do
8
+ should "provide the response body as an Hpricot element" do
9
9
  response_xml = '<xml>'
10
10
  hpricot_stub = stub()
11
11
 
@@ -15,7 +15,7 @@ module Fleakr::Api
15
15
  response.body.should == hpricot_stub
16
16
  end
17
17
 
18
- it "should memoize the Hpricot document" do
18
+ should "memoize the Hpricot document" do
19
19
  response = Response.new('<xml>')
20
20
 
21
21
  Hpricot.expects(:XML).with(kind_of(String)).once.returns(stub())
@@ -23,19 +23,19 @@ module Fleakr::Api
23
23
  2.times { response.body }
24
24
  end
25
25
 
26
- it "should know if there are errors in the response" do
26
+ should "know if there are errors in the response" do
27
27
  response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
28
28
  response = Response.new(response_xml)
29
29
 
30
30
  response.error?.should be(true)
31
31
  end
32
32
 
33
- it "should not have an error if there are no errors in the XML" do
33
+ should "not have an error if there are no errors in the XML" do
34
34
  response = Response.new(read_fixture('people.findByUsername'))
35
35
  response.error.should be(nil)
36
36
  end
37
37
 
38
- it "should have an error if there is an error in the response" do
38
+ should "have an error if there is an error in the response" do
39
39
  response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
40
40
  response = Response.new(response_xml)
41
41
 
@@ -3,14 +3,14 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Api
4
4
  class UploadRequestTest < Test::Unit::TestCase
5
5
 
6
- describe "An instance of the UploadRequest class" do
6
+ context "An instance of the UploadRequest class" do
7
7
 
8
- before do
8
+ setup do
9
9
  @secret = 'sekrit'
10
10
  Fleakr.stubs(:shared_secret).with().returns(@secret)
11
11
  end
12
12
 
13
- it "should have a collection of upload_options" do
13
+ should "have a collection of upload_options" do
14
14
  request = UploadRequest.new('foo', :create, {:title => 'foo', :tags => %w(a b)})
15
15
 
16
16
  option_1, option_2 = [stub(:to_hash => {:one => 'value_1'}), stub(:to_hash => {:two => 'value_2'})]
@@ -21,20 +21,24 @@ module Fleakr::Api
21
21
  request.upload_options.should == {:one => 'value_1', :two => 'value_2'}
22
22
  end
23
23
 
24
- it "should create a file parameter on initialization" do
24
+ should "create a file parameter on initialization" do
25
25
  filename = '/path/to/image.jpg'
26
26
 
27
27
  parameter = stub()
28
28
  FileParameter.expects(:new).with('photo', filename).returns(parameter)
29
29
 
30
- parameter_list = mock() {|m| m.expects(:<<).with(parameter) }
30
+ parameter_list = mock()
31
+ parameter_list.expects(:<<).with(parameter)
32
+
31
33
  ParameterList.expects(:new).with({}).returns(parameter_list)
32
34
 
33
35
  UploadRequest.new(filename)
34
36
  end
35
37
 
36
- it "should allow setting options on initialization" do
37
- option = stub {|s| s.stubs(:to_hash).with().returns({:title => 'foo'})}
38
+ should "allow setting options on initialization" do
39
+ option = stub()
40
+ option.stubs(:to_hash).with().returns({:title => 'foo'})
41
+
38
42
  Option.expects(:for).with(:title, 'foo').returns(option)
39
43
 
40
44
  ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:<<))
@@ -44,36 +48,36 @@ module Fleakr::Api
44
48
 
45
49
  context "after initialization" do
46
50
 
47
- before { ParameterList.stubs(:new).returns(stub(:<< => nil)) }
51
+ setup { ParameterList.stubs(:new).returns(stub(:<< => nil)) }
48
52
 
49
- it "should default the type to :create" do
53
+ should "default the type to :create" do
50
54
  request = UploadRequest.new('file')
51
55
  request.type.should == :create
52
56
  end
53
57
 
54
- it "should allow setting the type to :update" do
58
+ should "allow setting the type to :update" do
55
59
  request = UploadRequest.new('file', :update)
56
60
  request.type.should == :update
57
61
  end
58
62
 
59
- it "should know the endpoint_uri" do
63
+ should "know the endpoint_uri" do
60
64
  request = UploadRequest.new('filename')
61
65
  request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/upload/')
62
66
  end
63
67
 
64
- it "should know the endpoint_uri for an :update request" do
68
+ should "know the endpoint_uri for an :update request" do
65
69
  request = UploadRequest.new('filename', :update)
66
70
  request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/replace/')
67
71
  end
68
72
 
69
- it "should only parse the endpoint URI once" do
73
+ should "only parse the endpoint URI once" do
70
74
  request = UploadRequest.new('filename')
71
75
  URI.expects(:parse).with(kind_of(String)).once.returns('uri')
72
76
 
73
77
  2.times { request.__send__(:endpoint_uri) }
74
78
  end
75
79
 
76
- it "should have a collection of required headers" do
80
+ should "have a collection of required headers" do
77
81
  form_data = 'data'
78
82
 
79
83
  request = UploadRequest.new('filename')
@@ -87,28 +91,28 @@ module Fleakr::Api
87
91
  request.headers.should == expected
88
92
  end
89
93
 
90
- it "should be able to send a POST request to the API service" do
94
+ should "be able to send a POST request to the API service" do
91
95
  request = UploadRequest.new('filename')
92
96
 
93
- uri = stub do |s|
94
- s.stubs(:host).with().returns('host')
95
- s.stubs(:path).with().returns('path')
96
- s.stubs(:port).with().returns(80)
97
- end
97
+ uri = stub()
98
+ uri.stubs(:host).with().returns('host')
99
+ uri.stubs(:path).with().returns('path')
100
+ uri.stubs(:port).with().returns(80)
98
101
 
99
102
  request.stubs(:endpoint_uri).with().returns(uri)
100
103
 
101
104
  request.stubs(:headers).with().returns('header' => 'value')
102
105
  request.parameters.stubs(:to_form).with().returns('form')
103
106
 
104
- http = mock {|m| m.expects(:post).with('path', 'form', {'header' => 'value'}) }
107
+ http = mock()
108
+ http.expects(:post).with('path', 'form', {'header' => 'value'})
105
109
 
106
110
  Net::HTTP.expects(:start).with('host', 80).yields(http).returns(stub(:body))
107
111
 
108
112
  request.send
109
113
  end
110
114
 
111
- it "should get back a response from a POST operation" do
115
+ should "get back a response from a POST operation" do
112
116
  response = stub()
113
117
 
114
118
  Net::HTTP.expects(:start).with(kind_of(String), kind_of(Fixnum)).returns(stub(:body => '<xml>'))
@@ -118,7 +122,7 @@ module Fleakr::Api
118
122
  request.send.should == response
119
123
  end
120
124
 
121
- it "should be able to make a full request and response cycle" do
125
+ should "be able to make a full request and response cycle" do
122
126
  filename = 'filename'
123
127
  response = stub(:error? => false)
124
128
 
@@ -126,7 +130,7 @@ module Fleakr::Api
126
130
  UploadRequest.with_response!(filename).should == response
127
131
  end
128
132
 
129
- it "should raise an exception when the full request / response cycle has errors" do
133
+ should "raise an exception when the full request / response cycle has errors" do
130
134
  filename = 'filename'
131
135
  response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
132
136
 
@@ -3,29 +3,29 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Api
4
4
  class ValueParameterTest < Test::Unit::TestCase
5
5
 
6
- describe "An instance of the ValueParameter class" do
6
+ context "An instance of the ValueParameter class" do
7
7
 
8
- it "should have a value" do
8
+ should "have a value" do
9
9
  parameter = ValueParameter.new('foo', 'bar')
10
10
  parameter.value.should == 'bar'
11
11
  end
12
12
 
13
- it "should know how to generate the query representation of itself" do
13
+ should "know how to generate the query representation of itself" do
14
14
  parameter = ValueParameter.new('foo', 'bar')
15
15
  parameter.to_query.should == 'foo=bar'
16
16
  end
17
17
 
18
- it "should escape the value when generating the query representation" do
18
+ should "escape the value when generating the query representation" do
19
19
  parameter = ValueParameter.new('foo', 'Mr. Crystal?')
20
20
  parameter.to_query.should == 'foo=Mr.+Crystal%3F'
21
21
  end
22
22
 
23
- it "should use an empty string when generating a query if the parameter value is nil" do
23
+ should "use an empty string when generating a query if the parameter value is nil" do
24
24
  parameter = ValueParameter.new('foo', nil)
25
25
  parameter.to_query.should == 'foo='
26
26
  end
27
27
 
28
- it "should know how to generate the form representation of itself" do
28
+ should "know how to generate the form representation of itself" do
29
29
  parameter = ValueParameter.new('foo', 'bar')
30
30
  expected =
31
31
  'Content-Disposition: form-data; name="foo"' + "\r\n" +
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
2
2
 
3
3
  class FalseClassTest < Test::Unit::TestCase
4
4
 
5
- describe "An instance of the FalseClass class" do
5
+ context "An instance of the FalseClass class" do
6
6
 
7
- it "should have 0 as its integer value" do
7
+ should "have 0 as its integer value" do
8
8
  false.to_i.should == 0
9
9
  end
10
10
 
@@ -2,27 +2,27 @@ require File.dirname(__FILE__) + '/../../../test_helper'
2
2
 
3
3
  class HashTest < Test::Unit::TestCase
4
4
 
5
- describe "An instance of Hash" do
5
+ context "An instance of Hash" do
6
6
  context "when extracting key/value pairs" do
7
7
 
8
- before do
8
+ setup do
9
9
  @hash = {:one => 'two', :three => 'four'}
10
10
  end
11
11
 
12
- it "should return a hash with the matching key/value pairs" do
12
+ should "return a hash with the matching key/value pairs" do
13
13
  @hash.extract!(:one).should == {:one => 'two'}
14
14
  end
15
15
 
16
- it "should return an empty hash if the key isn't found" do
16
+ should "return an empty hash if the key isn't found" do
17
17
  @hash.extract!(:foo).should == {}
18
18
  end
19
19
 
20
- it "should alter the original hash when a value is extracted" do
20
+ should "alter the original hash when a value is extracted" do
21
21
  @hash.extract!(:one)
22
22
  @hash.should == {:three => 'four'}
23
23
  end
24
24
 
25
- it "should be able to extract multiple keys" do
25
+ should "be able to extract multiple keys" do
26
26
  @hash.extract!(:one, :three, :missing).should == {:one => 'two', :three => 'four'}
27
27
  end
28
28
 
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
2
2
 
3
3
  class TrueClassTest < Test::Unit::TestCase
4
4
 
5
- describe "An instance of the TrueClass class" do
5
+ context "An instance of the TrueClass class" do
6
6
 
7
- it "should have 1 as its integer value" do
7
+ should "have 1 as its integer value" do
8
8
  true.to_i.should == 1
9
9
  end
10
10
 
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Objects
4
4
  class AuthenticationTokenTest < Test::Unit::TestCase
5
5
 
6
- describe "The AuthenticationToken class" do
6
+ context "The AuthenticationToken class" do
7
7
 
8
- it "should be able to create an instance from a mini_token" do
8
+ should "be able to create an instance from a mini_token" do
9
9
  token = '123-123-123'
10
10
  auth_token = stub()
11
11
 
@@ -16,7 +16,7 @@ module Fleakr::Objects
16
16
  AuthenticationToken.from_mini_token(token).should == auth_token
17
17
  end
18
18
 
19
- it "should be able to create an instance from an auth_token" do
19
+ should "be able to create an instance from an auth_token" do
20
20
  token = 'abc123'
21
21
  auth_token = stub()
22
22
 
@@ -27,7 +27,7 @@ module Fleakr::Objects
27
27
  end
28
28
 
29
29
 
30
- it "should be able to create an instance from a frob" do
30
+ should "be able to create an instance from a frob" do
31
31
  frob = '12345678901234567-abcde89012fg3456-7890123'
32
32
  auth_token = stub()
33
33
 
@@ -39,11 +39,11 @@ module Fleakr::Objects
39
39
 
40
40
  end
41
41
 
42
- describe "An instance of the AuthenticationToken class" do
42
+ context "An instance of the AuthenticationToken class" do
43
43
 
44
44
  context "when populating from an XML document" do
45
45
 
46
- before do
46
+ setup do
47
47
  @object = AuthenticationToken.new(Hpricot.XML(read_fixture('auth.getFullToken')))
48
48
  end
49
49
 
@@ -3,17 +3,17 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Objects
4
4
  class CommentTest < Test::Unit::TestCase
5
5
 
6
- describe "The Comment class" do
6
+ context "The Comment class" do
7
7
 
8
8
  should_find_all :comments, :by => :photo_id, :call => 'photos.comments.getList', :path => 'rsp/comments/comment'
9
9
  should_find_all :comments, :by => :set_id, :using => :photoset_id, :call => 'photosets.comments.getList', :path => 'rsp/comments/comment'
10
10
 
11
11
  end
12
12
 
13
- describe "An instance of the Comment class" do
13
+ context "An instance of the Comment class" do
14
14
 
15
15
  context "when populating from the photos_comments_getList XML data" do
16
- before do
16
+ setup do
17
17
  @object = Comment.new(Hpricot.XML(read_fixture('photos.comments.getList')).at('rsp/comments/comment'))
18
18
  end
19
19
 
@@ -27,21 +27,21 @@ module Fleakr::Objects
27
27
 
28
28
  context "in general" do
29
29
 
30
- before { @comment = Comment.new }
30
+ setup { @comment = Comment.new }
31
31
 
32
- it "should have a value for :created_at" do
32
+ should "have a value for :created_at" do
33
33
  @comment.expects(:created).with().returns('1239217523')
34
34
  Time.expects(:at).with(1239217523).returns('time')
35
35
 
36
36
  @comment.created_at.should == 'time'
37
37
  end
38
38
 
39
- it "should use the body as the string representation" do
39
+ should "use the body as the string representation" do
40
40
  @comment.expects(:body).with().returns('bod')
41
41
  @comment.to_s.should == 'bod'
42
42
  end
43
43
 
44
- it "should be able to find the author of the comment" do
44
+ should "be able to find the author of the comment" do
45
45
  author = stub()
46
46
 
47
47
 
@@ -51,7 +51,7 @@ module Fleakr::Objects
51
51
  @comment.author.should == author
52
52
  end
53
53
 
54
- it "should memoize the owner information" do
54
+ should "memoize the owner information" do
55
55
  @comment.stubs(:author_id).with().returns('1')
56
56
 
57
57
  User.expects(:find_by_id).with('1').once.returns(stub())
@@ -3,15 +3,18 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Objects
4
4
  class ContactTest < Test::Unit::TestCase
5
5
 
6
- describe "The Contact class" do
6
+ context "The Contact class" do
7
7
 
8
8
  should "return a list of users for a specified user's contacts" do
9
- user_1, user_2 = [stub(), stub()]
9
+ # user_1, user_2 = [stub(), stub()]
10
+ user_1 = stub()
11
+ user_2 = stub()
12
+
10
13
  contact_1, contact_2 = [stub(:to_user => user_1), stub(:to_user => user_2)]
11
14
 
12
15
  response = mock_request_cycle :for => 'contacts.getPublicList', :with => {:user_id => '1'}
13
16
 
14
- contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').map
17
+ contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').to_a
15
18
 
16
19
  Contact.stubs(:new).with(contact_1_doc).returns(contact_1)
17
20
  Contact.stubs(:new).with(contact_2_doc).returns(contact_2)
@@ -21,9 +24,9 @@ module Fleakr::Objects
21
24
 
22
25
  end
23
26
 
24
- describe "An instance of the Contact class" do
27
+ context "An instance of the Contact class" do
25
28
  context "when populating from an XML document" do
26
- before do
29
+ setup do
27
30
  @object = Contact.new(Hpricot.XML(read_fixture('contacts.getPublicList')).at('contacts/contact'))
28
31
  end
29
32
 
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
3
3
  module Fleakr::Objects
4
4
  class ErrorTest < Test::Unit::TestCase
5
5
 
6
- describe "An instance of the Error class" do
6
+ context "An instance of the Error class" do
7
7
 
8
- it "should have a code and a message" do
8
+ should "have a code and a message" do
9
9
  response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
10
10
 
11
11
  error = Error.new(Hpricot.XML(response_xml))