fleakr 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,6 @@ module Fleakr::Api
5
5
 
6
6
  context "An instance of the UploadRequest class" do
7
7
 
8
- setup do
9
- @secret = 'sekrit'
10
- Fleakr.stubs(:shared_secret).with().returns(@secret)
11
- end
12
-
13
8
  should "have a collection of upload_options" do
14
9
  request = UploadRequest.new('foo', :create, {:title => 'foo', :tags => %w(a b)})
15
10
 
@@ -23,15 +18,10 @@ module Fleakr::Api
23
18
 
24
19
  should "create a file parameter on initialization" do
25
20
  filename = '/path/to/image.jpg'
26
-
27
- parameter = stub()
28
- FileParameter.expects(:new).with('photo', filename).returns(parameter)
29
-
30
- parameter_list = mock()
31
- parameter_list.expects(:<<).with(parameter)
32
21
 
33
- ParameterList.expects(:new).with({}).returns(parameter_list)
34
-
22
+ parameter_list = mock() {|p| p.expects(:add_upload_option).with(:photo, filename) }
23
+ UploadRequest.any_instance.stubs(:parameters).with().returns(parameter_list)
24
+
35
25
  UploadRequest.new(filename)
36
26
  end
37
27
 
@@ -41,14 +31,14 @@ module Fleakr::Api
41
31
 
42
32
  Option.expects(:for).with(:title, 'foo').returns(option)
43
33
 
44
- ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:<<))
34
+ ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:add_upload_option))
45
35
 
46
36
  UploadRequest.new('filename', :create, {:title => 'foo'})
47
37
  end
48
38
 
49
39
  context "after initialization" do
50
40
 
51
- setup { ParameterList.stubs(:new).returns(stub(:<< => nil)) }
41
+ setup { ParameterList.stubs(:new).returns(stub(:add_upload_option => nil)) }
52
42
 
53
43
  should "default the type to :create" do
54
44
  request = UploadRequest.new('file')
@@ -41,6 +41,15 @@ module Fleakr::Objects
41
41
 
42
42
  context "An instance of the AuthenticationToken class" do
43
43
 
44
+ should "have an associated user" do
45
+ token = AuthenticationToken.new
46
+ token.stubs(:user_id).with().returns('1')
47
+
48
+ User.expects(:find_by_id).with('1').returns('user')
49
+
50
+ token.user.should == 'user'
51
+ end
52
+
44
53
  context "when populating from an XML document" do
45
54
 
46
55
  setup do
@@ -4,16 +4,19 @@ module Fleakr::Objects
4
4
  class SetTest < Test::Unit::TestCase
5
5
 
6
6
  should_have_many :photos, :comments
7
+
8
+ should_autoload_when_accessing :user_id, :with => :load_info
7
9
 
8
10
  context "The Set class" do
9
11
 
10
12
  should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
13
+ should_find_one :set, :by => :id, :with => :photoset_id, :call => 'photosets.getInfo', :path => 'rsp/photoset'
11
14
 
12
15
  end
13
16
 
14
17
  context "An instance of the Set class" do
15
18
 
16
- context "when populating from an XML document" do
19
+ context "when populating from photosets.getList" do
17
20
  setup do
18
21
  @object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
19
22
  end
@@ -26,6 +29,32 @@ module Fleakr::Objects
26
29
 
27
30
  end
28
31
 
32
+ context "when populating from photosets.getInfo" do
33
+ setup do
34
+ @object = Set.new
35
+ @object.populate_from(Hpricot.XML(read_fixture('photosets.getInfo')))
36
+ end
37
+
38
+ should_have_a_value_for :user_id => '43955217@N05'
39
+ end
40
+
41
+ should "know the URL for the photoset" do
42
+ s = Set.new
43
+ s.stubs(:user_id).with().returns('123')
44
+ s.stubs(:id).with().returns('456')
45
+
46
+ s.url.should == "http://www.flickr.com/photos/123/sets/456/"
47
+ end
48
+
49
+ should "be able to retrieve the user for the set" do
50
+ s = Set.new
51
+ s.stubs(:user_id).with().returns('1')
52
+
53
+ User.expects(:find_by_id).with('1').returns('user')
54
+
55
+ s.user.should == 'user'
56
+ end
57
+
29
58
  should "know the primary photo in the set" do
30
59
  id = '1'
31
60
  photo = stub()
@@ -36,18 +36,19 @@ module Fleakr
36
36
  flickr_object = stub()
37
37
 
38
38
  response = mock_request_cycle :for => 'people.getInfo', :with => {:id => id}
39
- FlickrObject.expects(:new).with(response.body).returns(flickr_object)
39
+ FlickrObject.expects(:new).with(response.body, :id => id).returns(flickr_object)
40
40
 
41
41
  FlickrObject.find_by_id(id).should == flickr_object
42
42
  end
43
43
 
44
44
  should "be able to pass parameters to the :find_by_id method" do
45
- id = 1
46
- params = {:authenticate? => true}
45
+ id = 1
46
+ params = {:authenticate? => true}
47
+ full_params = {:id => id, :authenticate? => true}
47
48
  flickr_object = stub()
48
-
49
- response = mock_request_cycle :for => 'people.getInfo', :with => {:id => id, :authenticate? => true}
50
- FlickrObject.expects(:new).with(response.body).returns(flickr_object)
49
+
50
+ response = mock_request_cycle :for => 'people.getInfo', :with => full_params
51
+ FlickrObject.expects(:new).with(response.body, full_params).returns(flickr_object)
51
52
 
52
53
  FlickrObject.find_by_id(id, params).should == flickr_object
53
54
  end
@@ -62,6 +63,11 @@ module Fleakr
62
63
  end
63
64
  end
64
65
 
66
+ should "be able to capture the :auth_token from options sent along to the new object" do
67
+ object = EmptyObject.new(nil, {:foo => 'bar', :auth_token => 'toke'})
68
+ object.authentication_options.should == {:auth_token => 'toke'}
69
+ end
70
+
65
71
  context "when populating data from an XML document" do
66
72
  setup do
67
73
  xml = <<-XML
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class BasicRequest
4
+ include Fleakr::Support::Request
5
+
6
+ def endpoint_url
7
+ 'http://example.com'
8
+ end
9
+
10
+ end
11
+
12
+ module Fleakr
13
+ class RequestTest < Test::Unit::TestCase
14
+
15
+ context "An instance of the BasicRequest class with the Request mix-in" do
16
+
17
+ should "have a collection of parameters" do
18
+ params = {:perms => 'read'}
19
+ Fleakr::Api::ParameterList.expects(:new).with(params, true).returns('params')
20
+
21
+ request = BasicRequest.new(params)
22
+ request.parameters.should == 'params'
23
+ end
24
+
25
+ should "know not to authenticate the request if asked not to" do
26
+ Fleakr::Api::ParameterList.expects(:new).with({:perms => 'read'}, false).returns('params')
27
+
28
+ request = BasicRequest.new(:perms => 'read', :authenticate? => false)
29
+ request.parameters.should == 'params'
30
+ end
31
+
32
+ should "know the endpoint with full URL parameters" do
33
+ request = BasicRequest.new
34
+ request.parameters.stubs(:to_query).with().returns('query')
35
+
36
+ request.endpoint_uri.to_s.should == 'http://example.com?query'
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -4,7 +4,7 @@ class FleakrTest < Test::Unit::TestCase
4
4
 
5
5
  context "The Fleakr module" do
6
6
 
7
- [:api_key, :shared_secret, :mini_token, :auth_token].each do |attribute|
7
+ [:api_key, :shared_secret, :auth_token].each do |attribute|
8
8
  should "be able to set a value for :#{attribute}" do
9
9
  value = 'value'
10
10
 
@@ -15,7 +15,7 @@ class FleakrTest < Test::Unit::TestCase
15
15
 
16
16
  should "provide a means to find a user by his username" do
17
17
  user = stub()
18
- Fleakr::Objects::User.expects(:find_by_username).with('username').returns(user)
18
+ Fleakr::Objects::User.expects(:find_by_username).with('username', {}).returns(user)
19
19
  Fleakr.user('username').should == user
20
20
  end
21
21
 
@@ -23,8 +23,8 @@ class FleakrTest < Test::Unit::TestCase
23
23
  user = stub()
24
24
  email = 'user@host.com'
25
25
 
26
- Fleakr::Objects::User.stubs(:find_by_username).with(email).raises(Fleakr::ApiError)
27
- Fleakr::Objects::User.expects(:find_by_email).with(email).returns(user)
26
+ Fleakr::Objects::User.stubs(:find_by_username).with(email, {}).raises(Fleakr::ApiError)
27
+ Fleakr::Objects::User.expects(:find_by_email).with(email, {}).returns(user)
28
28
 
29
29
  Fleakr.user(email).should == user
30
30
  end
@@ -33,9 +33,9 @@ class FleakrTest < Test::Unit::TestCase
33
33
  user = stub()
34
34
  url = 'http://flickr.com/photos/user'
35
35
 
36
- Fleakr::Objects::User.stubs(:find_by_username).with(url).raises(Fleakr::ApiError)
37
- Fleakr::Objects::User.stubs(:find_by_email).with(url).raises(Fleakr::ApiError)
38
- Fleakr::Objects::User.expects(:find_by_url).with(url).returns(user)
36
+ Fleakr::Objects::User.stubs(:find_by_username).with(url, {}).raises(Fleakr::ApiError)
37
+ Fleakr::Objects::User.stubs(:find_by_email).with(url, {}).raises(Fleakr::ApiError)
38
+ Fleakr::Objects::User.expects(:find_by_url).with(url, {}).returns(user)
39
39
 
40
40
  Fleakr.user(url).should == user
41
41
  end
@@ -43,13 +43,19 @@ class FleakrTest < Test::Unit::TestCase
43
43
  should "not return nil if a user cannot be found" do
44
44
  data = 'data'
45
45
 
46
- Fleakr::Objects::User.stubs(:find_by_username).with(data).raises(Fleakr::ApiError)
47
- Fleakr::Objects::User.stubs(:find_by_email).with(data).raises(Fleakr::ApiError)
48
- Fleakr::Objects::User.stubs(:find_by_url).with(data).raises(Fleakr::ApiError)
46
+ Fleakr::Objects::User.stubs(:find_by_username).with(data, {}).raises(Fleakr::ApiError)
47
+ Fleakr::Objects::User.stubs(:find_by_email).with(data, {}).raises(Fleakr::ApiError)
48
+ Fleakr::Objects::User.stubs(:find_by_url).with(data, {}).raises(Fleakr::ApiError)
49
49
 
50
50
  Fleakr.user(data).should be_nil
51
51
  end
52
52
 
53
+ should "provide additional options to the finder call if supplied" do
54
+ user = stub()
55
+ Fleakr::Objects::User.expects(:find_by_username).with('username', :auth_token => 'toke').returns(user)
56
+ Fleakr.user('username', :auth_token => 'toke').should == user
57
+ end
58
+
53
59
  should "find all contacts for the authenticated user" do
54
60
  Fleakr::Objects::Contact.expects(:find_all).with({}).returns('contacts')
55
61
  Fleakr.contacts.should == 'contacts'
@@ -110,96 +116,36 @@ class FleakrTest < Test::Unit::TestCase
110
116
  Fleakr.upload(filename, :title => 'bop bip').should == [new_image]
111
117
  end
112
118
 
113
- should "be able to reset the cached token" do
114
- @token = stub()
115
- Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
116
- Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').times(2).returns(@token)
117
- Fleakr.token # once
118
- Fleakr.reset_token
119
- Fleakr.token # twice
120
- end
121
-
122
- should "not have a token by default" do
123
- Fleakr.expects(:mini_token).with().returns(nil)
124
- Fleakr.expects(:auth_token).with().returns(nil)
125
- Fleakr.expects(:frob).with().returns(nil)
119
+ should "be able to generate the authorization_url with default permissions" do
120
+ request = stub() {|r| r.stubs(:authorization_url).with().returns('auth_url') }
121
+ Fleakr::Api::AuthenticationRequest.expects(:new).with(:perms => :read).returns(request)
126
122
 
127
- Fleakr.token.should be(nil)
123
+ Fleakr.authorization_url.should == 'auth_url'
128
124
  end
129
125
 
130
- [:mini_token, :auth_token, :frob].each do |attribute|
131
- should "reset_token when :#{attribute} is set" do
132
- Fleakr.expects(:reset_token).with().at_least_once
133
- Fleakr.send("#{attribute}=".to_sym, 'value')
134
- end
135
- end
136
-
137
- context "when generating an AuthenticationToken from an auth_token string" do
138
-
139
- setup do
140
- @token = stub()
141
-
142
- Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
143
- Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').returns(@token)
144
- end
145
-
146
- # Make sure to clear the cache
147
- teardown { Fleakr.auth_token = nil }
148
-
149
- should "return the token" do
150
- Fleakr.token.should == @token
151
- end
126
+ should "be able to specify different permissions when generating the authorization_url" do
127
+ request = stub() {|r| r.stubs(:authorization_url).with().returns('auth_url') }
128
+ Fleakr::Api::AuthenticationRequest.expects(:new).with(:perms => :delete).returns(request)
152
129
 
153
- should "cache the result" do
154
- 2.times { Fleakr.token }
155
- end
156
-
130
+ Fleakr.authorization_url(:delete).should == 'auth_url'
131
+ end
132
+
133
+ should "be able to retrieve a token from the provided frob" do
134
+ Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('frob').returns('toke')
135
+ Fleakr.token_from_frob('frob').should == 'toke'
157
136
  end
158
137
 
159
- context "when generating an AuthenticationToken from a frob string" do
160
-
161
- setup do
162
- @token = stub()
163
-
164
- Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
165
- Fleakr.expects(:frob).with().at_least_once.returns('abc123')
166
- Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
167
- end
168
-
169
- # Make sure to clear the cache
170
- teardown { Fleakr.frob = nil }
171
-
172
- should "return the token" do
173
- Fleakr.token.should == @token
174
- end
175
-
176
- should "cache the result" do
177
- 2.times { Fleakr.token }
178
- end
179
-
138
+ should "be able to retrieve a token from the provided mini-token" do
139
+ Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('mini_token').returns('toke')
140
+ Fleakr.token_from_mini_token('mini_token').should == 'toke'
180
141
  end
181
142
 
182
- context "when generating an AuthenticationToken from a mini_token string" do
183
-
184
- setup do
185
- @token = stub()
186
-
187
- Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
188
- Fleakr.expects(:mini_token).with().at_least_once.returns('123-123-123')
189
- Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('123-123-123').returns(@token)
190
- end
143
+ should "be able to get the user for the provided auth token" do
144
+ token = stub() {|t| t.stubs(:user).with().returns('user') }
191
145
 
192
- # Make sure to clear the cache
193
- teardown { Fleakr.mini_token = nil }
194
-
195
- should "return the token" do
196
- Fleakr.token.should == @token
197
- end
198
-
199
- should "cache the result" do
200
- 2.times { Fleakr.token }
201
- end
146
+ Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('toke').returns(token)
202
147
 
148
+ Fleakr.user_for_token('toke').should == 'user'
203
149
  end
204
150
 
205
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fleakr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Reagan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-18 00:00:00 -04:00
12
+ date: 2009-10-25 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -53,10 +53,10 @@ extra_rdoc_files:
53
53
  files:
54
54
  - README.rdoc
55
55
  - Rakefile
56
+ - lib/fleakr/api/authentication_request.rb
56
57
  - lib/fleakr/api/file_parameter.rb
57
58
  - lib/fleakr/api/method_request.rb
58
59
  - lib/fleakr/api/option.rb
59
- - lib/fleakr/api/parameter.rb
60
60
  - lib/fleakr/api/parameter_list.rb
61
61
  - lib/fleakr/api/response.rb
62
62
  - lib/fleakr/api/upload_request.rb
@@ -82,6 +82,7 @@ files:
82
82
  - lib/fleakr/objects.rb
83
83
  - lib/fleakr/support/attribute.rb
84
84
  - lib/fleakr/support/object.rb
85
+ - lib/fleakr/support/request.rb
85
86
  - lib/fleakr/support.rb
86
87
  - lib/fleakr/version.rb
87
88
  - lib/fleakr.rb
@@ -104,6 +105,7 @@ files:
104
105
  - test/fixtures/photos.getSizes.xml
105
106
  - test/fixtures/photos.search.xml
106
107
  - test/fixtures/photosets.comments.getList.xml
108
+ - test/fixtures/photosets.getInfo.xml
107
109
  - test/fixtures/photosets.getList.xml
108
110
  - test/fixtures/photosets.getPhotos.xml
109
111
  - test/fixtures/tags.getListPhoto.xml
@@ -111,11 +113,11 @@ files:
111
113
  - test/fixtures/tags.getRelated.xml
112
114
  - test/fixtures/urls.lookupUser.xml
113
115
  - test/test_helper.rb
116
+ - test/unit/fleakr/api/authentication_request_test.rb
114
117
  - test/unit/fleakr/api/file_parameter_test.rb
115
118
  - test/unit/fleakr/api/method_request_test.rb
116
119
  - test/unit/fleakr/api/option_test.rb
117
120
  - test/unit/fleakr/api/parameter_list_test.rb
118
- - test/unit/fleakr/api/parameter_test.rb
119
121
  - test/unit/fleakr/api/response_test.rb
120
122
  - test/unit/fleakr/api/upload_request_test.rb
121
123
  - test/unit/fleakr/api/value_parameter_test.rb
@@ -137,6 +139,7 @@ files:
137
139
  - test/unit/fleakr/objects/user_test.rb
138
140
  - test/unit/fleakr/support/attribute_test.rb
139
141
  - test/unit/fleakr/support/object_test.rb
142
+ - test/unit/fleakr/support/request_test.rb
140
143
  - test/unit/fleakr_test.rb
141
144
  has_rdoc: true
142
145
  homepage: http://sneaq.net
@@ -1,35 +0,0 @@
1
- module Fleakr
2
- module Api # :nodoc:
3
-
4
- # = Parameter
5
- #
6
- # Base class for other parameters that get passed to the Flickr API - see
7
- # #FileParameter and #ValueParameter for examples
8
- #
9
- class Parameter
10
-
11
- attr_reader :name
12
-
13
- # A new named parameter (never used directly)
14
- #
15
- def initialize(name, include_in_signature = true)
16
- @name = name
17
- @include_in_signature = include_in_signature
18
- end
19
-
20
- # Should this parameter be used when generating the signature?
21
- #
22
- def include_in_signature?
23
- (@include_in_signature == true) ? true : false
24
- end
25
-
26
- # Used for sorting when generating a signature
27
- #
28
- def <=>(other)
29
- self.name <=> other.name
30
- end
31
-
32
- end
33
-
34
- end
35
- end