reagent-fleakr 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,179 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Api
4
+
5
+ class OptionTest < Test::Unit::TestCase
6
+
7
+ def self.should_know_the_class_for(type, options)
8
+ it "should know the class for the :#{type} type" do
9
+ Option.class_for(type).should == options[:is]
10
+ end
11
+ end
12
+
13
+ describe "The Option class" do
14
+ should_know_the_class_for :title, :is => Fleakr::Api::SimpleOption
15
+ should_know_the_class_for :description, :is => Fleakr::Api::SimpleOption
16
+ should_know_the_class_for :tags, :is => Fleakr::Api::TagOption
17
+ should_know_the_class_for :viewable_by, :is => Fleakr::Api::ViewOption
18
+ should_know_the_class_for :level, :is => Fleakr::Api::LevelOption
19
+ should_know_the_class_for :type, :is => Fleakr::Api::TypeOption
20
+ should_know_the_class_for :hide?, :is => Fleakr::Api::HiddenOption
21
+
22
+ it "should be able to create an option for a type" do
23
+ option = stub()
24
+
25
+ Option.expects(:class_for).with(:title).returns(Fleakr::Api::SimpleOption)
26
+ Fleakr::Api::SimpleOption.expects(:new).with(:title, 'blip').returns(option)
27
+
28
+ Option.for(:title, 'blip').should == option
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ class SimpleOptionTest < Test::Unit::TestCase
35
+
36
+ describe "An instance of the SimpleOption class" do
37
+ it "should have a type" do
38
+ so = SimpleOption.new(:title, 'blip')
39
+ so.type.should == :title
40
+ end
41
+
42
+ it "should have a value" do
43
+ so = SimpleOption.new(:title, 'blip')
44
+ so.value.should == 'blip'
45
+ end
46
+
47
+ it "should be able to generate a hash representation of itself" do
48
+ so = SimpleOption.new(:title, 'blip')
49
+ so.to_hash.should == {:title => 'blip'}
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ class TagOptionTest < Test::Unit::TestCase
56
+
57
+ describe "An instance of the TagOption class" do
58
+
59
+ it "should normalize the input value to an array" do
60
+ to = TagOption.new(:tags, 'blip')
61
+ to.value.should == ['blip']
62
+ end
63
+
64
+ it "should be able to generate a hash representation of itself with tags joined on spaces" do
65
+ to = TagOption.new(:tags, %w(bop bip))
66
+ to.to_hash.should == {:tags => '"bop" "bip"'}
67
+ end
68
+
69
+ it "should quote tag values with spaces" do
70
+ to = TagOption.new(:tags, ['tag', 'one with spaces'])
71
+ to.to_hash.should == {:tags => '"tag" "one with spaces"'}
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ class ViewOptionTest < Test::Unit::TestCase
78
+
79
+ describe "An instance of the ViewOption class" do
80
+ it "should be able to generate a hash representation for viewing by :everyone" do
81
+ vo = ViewOption.new(:viewable_by, :everyone)
82
+ vo.to_hash.should == {:is_public => 1, :is_family => 0, :is_friend => 0}
83
+ end
84
+
85
+ it "should be able to generate a hash representation for viewing by :family" do
86
+ vo = ViewOption.new(:viewable_by, :family)
87
+ vo.to_hash.should == {:is_public => 0, :is_family => 1, :is_friend => 0}
88
+ end
89
+
90
+ it "should be able to generate a hash representation for viewing by :friends" do
91
+ vo = ViewOption.new(:viewable_by, :friends)
92
+ vo.to_hash.should == {:is_public => 0, :is_family => 0, :is_friend => 1}
93
+ end
94
+
95
+ it "should know the visibility is public if value is set to :everyone" do
96
+ vo = ViewOption.new(:viewable_by, :everyone)
97
+ vo.public?.should be(true)
98
+ end
99
+
100
+ it "should know the visibility is not public if :everyone is not the only value" do
101
+ vo = ViewOption.new(:viewable_by, [:everyone, :family])
102
+ vo.public?.should be(false)
103
+ end
104
+
105
+ it "should know that its visible to friends and family if specified as such" do
106
+ vo = ViewOption.new(:viewable_by, [:friends, :family])
107
+ vo.friends?.should be(true)
108
+ vo.family?.should be(true)
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+ class LevelOptionTest < Test::Unit::TestCase
116
+
117
+ describe "An instance of the LevelOption class" do
118
+
119
+ it "should be able to generate a hash representation for the :safe level" do
120
+ lo = LevelOption.new(:level, :safe)
121
+ lo.to_hash.should == {:safety_level => 1}
122
+ end
123
+
124
+ it "should be able to generate a hash representation for the :moderate level" do
125
+ lo = LevelOption.new(:level, :moderate)
126
+ lo.to_hash.should == {:safety_level => 2}
127
+ end
128
+
129
+ it "should be able to generate a hash representation for the :restricted level" do
130
+ lo = LevelOption.new(:level, :restricted)
131
+ lo.to_hash.should == {:safety_level => 3}
132
+ end
133
+
134
+ end
135
+
136
+ end
137
+
138
+ class TypeOptionTest < Test::Unit::TestCase
139
+
140
+ describe "An instance of the TypeOption class" do
141
+
142
+ it "should be able to generate a hash representation for the :photo type" do
143
+ to = TypeOption.new(:type, :photo)
144
+ to.to_hash.should == {:content_type => 1}
145
+ end
146
+
147
+ it "should be able to generate a hash representation for the :screenshot type" do
148
+ to = TypeOption.new(:type, :screenshot)
149
+ to.to_hash.should == {:content_type => 2}
150
+ end
151
+
152
+ it "should be able to generate a hash representation for the :other type" do
153
+ to = TypeOption.new(:type, :other)
154
+ to.to_hash.should == {:content_type => 3}
155
+ end
156
+
157
+ end
158
+
159
+ end
160
+
161
+ class HiddenOptionTest < Test::Unit::TestCase
162
+
163
+ describe "An instance of the HiddenOption class" do
164
+
165
+ it "should be able to generate a hash representation when set to true" do
166
+ ho = HiddenOption.new(:hide?, true)
167
+ ho.to_hash.should == {:hidden => 2}
168
+ end
169
+
170
+ it "should be able to generate a hash representation when set to false" do
171
+ ho = HiddenOption.new(:hide?, false)
172
+ ho.to_hash.should == {:hidden => 1}
173
+ end
174
+
175
+ end
176
+
177
+ end
178
+
179
+ end
@@ -9,7 +9,6 @@ module Fleakr::Api
9
9
  @api_key = 'key'
10
10
  @secret = 'foobar'
11
11
 
12
- Fleakr.stubs(:shared_secret).with().returns(@secret)
13
12
  Fleakr.stubs(:api_key).with().returns(@api_key)
14
13
  @parameter_list = ParameterList.new
15
14
  end
@@ -24,7 +23,7 @@ module Fleakr::Api
24
23
  parameter_list = ParameterList.new(:one => 'two')
25
24
  parameter_list[:one].value.should == 'two'
26
25
  end
27
-
26
+
28
27
  it "should be able to add parameters to its list" do
29
28
  parameter = ValueParameter.new('foo', 'bar')
30
29
 
@@ -47,11 +46,15 @@ module Fleakr::Api
47
46
  end
48
47
 
49
48
  it "should be able to calculate the signature of the parameters" do
49
+ Fleakr.stubs(:shared_secret).with().returns(@secret)
50
+
50
51
  @parameter_list << ValueParameter.new('foo', 'bar')
51
52
  @parameter_list.signature.should == Digest::MD5.hexdigest("#{@secret}api_key#{@api_key}foobar")
52
53
  end
53
54
 
54
55
  it "should use the correct order when signing a list of multiple parameters" do
56
+ Fleakr.stubs(:shared_secret).with().returns(@secret)
57
+
55
58
  @parameter_list << ValueParameter.new('z', 'a')
56
59
  @parameter_list << ValueParameter.new('a', 'z')
57
60
 
@@ -59,6 +62,8 @@ module Fleakr::Api
59
62
  end
60
63
 
61
64
  it "should ignore the parameters that aren't included in the signature" do
65
+ Fleakr.stubs(:shared_secret).with().returns(@secret)
66
+
62
67
  @parameter_list << ValueParameter.new('foo', 'bar')
63
68
  @parameter_list << ValueParameter.new('yes', 'no', false)
64
69
 
@@ -76,15 +81,30 @@ module Fleakr::Api
76
81
  @parameter_list.sign?.should be(false)
77
82
  end
78
83
 
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)
84
+ it "should know that it needs to sign the request when a shared secret is available" do
85
+ Fleakr.expects(:shared_secret).with().returns(@secret)
86
+ @parameter_list.sign?.should be(true)
82
87
  end
83
88
 
84
89
  it "should know that it doesn't need to authenticate the request by default" do
85
90
  @parameter_list.authenticate?.should be(false)
86
91
  end
87
92
 
93
+ it "should know to authenticate the request when a token is available" do
94
+ Fleakr.stubs(:token).with().returns(stub(:value => 'toke'))
95
+ parameter_list = ParameterList.new
96
+
97
+ parameter_list.authenticate?.should be(true)
98
+ end
99
+
100
+ it "should not authenticate the request if it's been specifically told not to" do
101
+ Fleakr.expects(:token).with().never
102
+
103
+ parameter_list = ParameterList.new(:authenticate? => false)
104
+ parameter_list.authenticate?.should be(false)
105
+ end
106
+
107
+
88
108
  it "should know to authenticate the request when asked" do
89
109
  Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
90
110
 
@@ -103,15 +123,10 @@ module Fleakr::Api
103
123
  auth_param.include_in_signature?.should be(true)
104
124
  end
105
125
 
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
126
  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)
127
+ parameter_list = ParameterList.new
128
+
129
+ parameter_list.stubs(:sign?).with().returns(true)
115
130
  parameter_list.stubs(:signature).with().returns('sig')
116
131
 
117
132
  signature_param = parameter_list[:api_sig]
@@ -122,24 +137,24 @@ module Fleakr::Api
122
137
  end
123
138
 
124
139
  context "with associated parameters" do
125
-
140
+
126
141
  before do
127
142
  @p1 = ValueParameter.new('a', 'b')
128
143
  @p2 = ValueParameter.new('c', 'd')
129
-
144
+
130
145
  @p1.stubs(:to_query).with().returns('q1')
131
146
  @p1.stubs(:to_form).with().returns('f1')
132
147
 
133
148
  @p2.stubs(:to_query).with().returns('q2')
134
149
  @p2.stubs(:to_form).with().returns('f2')
135
-
150
+
136
151
  @parameter_list.stubs(:list).with().returns('a' => @p1, 'c' => @p2)
137
152
  end
138
-
153
+
139
154
  it "should be able to generate a query representation of itself" do
140
155
  @parameter_list.to_query.should == 'q1&q2'
141
156
  end
142
-
157
+
143
158
  it "should be able to represent a form representation of itself" do
144
159
  @parameter_list.stubs(:boundary).returns('bound')
145
160
 
@@ -10,6 +10,17 @@ module Fleakr::Api
10
10
  Fleakr.stubs(:shared_secret).with().returns(@secret)
11
11
  end
12
12
 
13
+ it "should have a collection of upload_options" do
14
+ request = UploadRequest.new('foo', :create, {:title => 'foo', :tags => %w(a b)})
15
+
16
+ option_1, option_2 = [stub(:to_hash => {:one => 'value_1'}), stub(:to_hash => {:two => 'value_2'})]
17
+
18
+ Option.expects(:for).with(:title, 'foo').returns(option_1)
19
+ Option.expects(:for).with(:tags, %w(a b)).returns(option_2)
20
+
21
+ request.upload_options.should == {:one => 'value_1', :two => 'value_2'}
22
+ end
23
+
13
24
  it "should create a file parameter on initialization" do
14
25
  filename = '/path/to/image.jpg'
15
26
 
@@ -17,17 +28,18 @@ module Fleakr::Api
17
28
  FileParameter.expects(:new).with('photo', filename).returns(parameter)
18
29
 
19
30
  parameter_list = mock() {|m| m.expects(:<<).with(parameter) }
20
- ParameterList.expects(:new).with(:authenticate? => true).returns(parameter_list)
31
+ ParameterList.expects(:new).with({}).returns(parameter_list)
21
32
 
22
33
  UploadRequest.new(filename)
23
34
  end
24
35
 
25
- it "should allow setting additional parameters on initialization" do
26
- params = {:is_public => 1}
36
+ it "should allow setting options on initialization" do
37
+ option = stub {|s| s.stubs(:to_hash).with().returns({:title => 'foo'})}
38
+ Option.expects(:for).with(:title, 'foo').returns(option)
27
39
 
28
- ParameterList.expects(:new).with({:is_public => 1, :authenticate? => true}).returns(stub(:<<))
40
+ ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:<<))
29
41
 
30
- UploadRequest.new('filename', params)
42
+ UploadRequest.new('filename', :create, {:title => 'foo'})
31
43
  end
32
44
 
33
45
  context "after initialization" do
@@ -40,7 +52,7 @@ module Fleakr::Api
40
52
  end
41
53
 
42
54
  it "should allow setting the type to :update" do
43
- request = UploadRequest.new('file', :type => :update)
55
+ request = UploadRequest.new('file', :update)
44
56
  request.type.should == :update
45
57
  end
46
58
 
@@ -50,7 +62,7 @@ module Fleakr::Api
50
62
  end
51
63
 
52
64
  it "should know the endpoint_uri for an :update request" do
53
- request = UploadRequest.new('filename', :type => :update)
65
+ request = UploadRequest.new('filename', :update)
54
66
  request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/replace/')
55
67
  end
56
68
 
@@ -110,7 +122,7 @@ module Fleakr::Api
110
122
  filename = 'filename'
111
123
  response = stub(:error? => false)
112
124
 
113
- UploadRequest.expects(:new).with(filename, {}).returns(stub(:send => response))
125
+ UploadRequest.expects(:new).with(filename, :create, {}).returns(stub(:send => response))
114
126
  UploadRequest.with_response!(filename).should == response
115
127
  end
116
128
 
@@ -118,7 +130,7 @@ module Fleakr::Api
118
130
  filename = 'filename'
119
131
  response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
120
132
 
121
- UploadRequest.expects(:new).with(filename, {}).returns(stub(:send => response))
133
+ UploadRequest.expects(:new).with(filename, :create, {}).returns(stub(:send => response))
122
134
 
123
135
  lambda do
124
136
  UploadRequest.with_response!(filename)
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class FalseClassTest < Test::Unit::TestCase
4
+
5
+ describe "An instance of the FalseClass class" do
6
+
7
+ it "should have 0 as its integer value" do
8
+ false.to_i.should == 0
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class TrueClassTest < Test::Unit::TestCase
4
+
5
+ describe "An instance of the TrueClass class" do
6
+
7
+ it "should have 1 as its integer value" do
8
+ true.to_i.should == 1
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -9,7 +9,7 @@ module Fleakr::Objects
9
9
  token = '123-123-123'
10
10
  auth_token = stub()
11
11
 
12
- response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :sign? => true}
12
+ response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :authenticate? => false}
13
13
 
14
14
  AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
15
15
 
@@ -20,12 +20,23 @@ module Fleakr::Objects
20
20
  token = 'abc123'
21
21
  auth_token = stub()
22
22
 
23
- response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :sign? => true}
23
+ response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :authenticate? => false}
24
24
 
25
25
  AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
26
26
  AuthenticationToken.from_auth_token(token).should == auth_token
27
27
  end
28
28
 
29
+
30
+ it "should be able to create an instance from a frob" do
31
+ frob = '12345678901234567-abcde89012fg3456-7890123'
32
+ auth_token = stub()
33
+
34
+ response = mock_request_cycle :for => 'auth.getToken', :with => {:frob => frob, :authenticate? => false}
35
+
36
+ AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
37
+ AuthenticationToken.from_frob(frob).should == auth_token
38
+ end
39
+
29
40
  end
30
41
 
31
42
  describe "An instance of the AuthenticationToken class" do
@@ -38,6 +49,9 @@ module Fleakr::Objects
38
49
 
39
50
  should_have_a_value_for :value => 'abc-123'
40
51
  should_have_a_value_for :permissions => 'delete'
52
+ should_have_a_value_for :user_id => '31066442@N69'
53
+ should_have_a_value_for :full_name => 'Sir Froot Pants'
54
+ should_have_a_value_for :user_name => 'frootpantz'
41
55
 
42
56
  end
43
57
 
@@ -16,7 +16,7 @@ module Fleakr::Objects
16
16
 
17
17
  should_find_one :photo, :by => :id, :with => :photo_id, :call => 'photos.getInfo'
18
18
 
19
-
19
+ # TODO: refactor these 2 tests
20
20
  it "should be able to upload a photo and return the new photo information" do
21
21
  filename = '/path/to/mugshot.jpg'
22
22
  photo = stub()
@@ -25,11 +25,25 @@ module Fleakr::Objects
25
25
  s.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
26
26
  end
27
27
 
28
- Fleakr::Api::UploadRequest.expects(:with_response!).with(filename).returns(response)
29
- Photo.expects(:find_by_id).with('123', :authenticate? => true).returns(photo)
28
+ Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {}).returns(response)
29
+ Photo.expects(:find_by_id).with('123').returns(photo)
30
30
 
31
31
  Photo.upload(filename).should == photo
32
32
  end
33
+
34
+ it "should be able to pass additional options when uploading a new file" do
35
+ filename = '/path/to/mugshot.jpg'
36
+ photo = stub()
37
+
38
+ response = stub do |s|
39
+ s.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
40
+ end
41
+
42
+ Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {:title => 'foo'}).returns(response)
43
+ Photo.expects(:find_by_id).with('123').returns(photo)
44
+
45
+ Photo.upload(filename, :title => 'foo').should == photo
46
+ end
33
47
 
34
48
  end
35
49
 
@@ -39,9 +53,9 @@ module Fleakr::Objects
39
53
  filename = '/path/to/file.jpg'
40
54
  response = stub(:body => 'body')
41
55
 
42
- params = {:type => :update, :photo_id => '1'}
56
+ params = {:photo_id => '1'}
43
57
 
44
- Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, params).returns(response)
58
+ Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :update, params).returns(response)
45
59
 
46
60
  photo = Photo.new
47
61
  photo.stubs(:id).returns('1')
@@ -110,17 +124,17 @@ module Fleakr::Objects
110
124
 
111
125
  it "should have a value for :posted_at" do
112
126
  @photo.expects(:posted).with().returns("#{@time.to_i}")
113
- @photo.posted_at.should == @time
127
+ @photo.posted_at.to_s.should == @time.to_s
114
128
  end
115
129
 
116
130
  it "should have a value for :taken_at" do
117
131
  @photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
118
- @photo.taken_at.should == @time
132
+ @photo.taken_at.to_s.should == @time.to_s
119
133
  end
120
134
 
121
135
  it "should have a value for :updated_at" do
122
136
  @photo.expects(:updated).with().returns("#{@time.to_i}")
123
- @photo.updated_at.should == @time
137
+ @photo.updated_at.to_s.should == @time.to_s
124
138
  end
125
139
 
126
140
  it "should have a collection of images by size" do
@@ -41,18 +41,63 @@ class FleakrTest < Test::Unit::TestCase
41
41
  Fleakr.search(:tags => %w(one two))
42
42
  end
43
43
 
44
+ # TODO: refactor uploading tests?
44
45
  it "should be able to upload a collection of images" do
45
46
  glob = '*.jpg'
46
47
  filenames = %w(one.jpg two.jpg)
47
48
 
48
49
  Dir.expects(:[]).with(glob).returns(filenames)
49
50
 
50
- Fleakr::Objects::Photo.expects(:upload).with('one.jpg')
51
- Fleakr::Objects::Photo.expects(:upload).with('two.jpg')
51
+ Fleakr::Objects::Photo.expects(:upload).with('one.jpg', {})
52
+ Fleakr::Objects::Photo.expects(:upload).with('two.jpg', {})
52
53
 
53
54
  Fleakr.upload(glob)
54
55
  end
55
56
 
57
+ it "should return recently uploaded photos" do
58
+ filename = '/path/to/image.jpg'
59
+ new_image = stub()
60
+
61
+ Dir.expects(:[]).with(filename).returns([filename])
62
+ Fleakr::Objects::Photo.expects(:upload).with(filename, {}).returns(new_image)
63
+
64
+ Fleakr.upload(filename).should == [new_image]
65
+ end
66
+
67
+ it "should be able to pass options for the uploaded files" do
68
+ filename = '/path/to/image.jpg'
69
+ new_image = stub()
70
+
71
+ Dir.expects(:[]).with(filename).returns([filename])
72
+ Fleakr::Objects::Photo.expects(:upload).with(filename, :title => 'bop bip').returns(new_image)
73
+
74
+ Fleakr.upload(filename, :title => 'bop bip').should == [new_image]
75
+ end
76
+
77
+ it "should be able to reset the cached token" do
78
+ @token = stub()
79
+ Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
80
+ Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').times(2).returns(@token)
81
+ Fleakr.token # once
82
+ Fleakr.reset_token
83
+ Fleakr.token # twice
84
+ end
85
+
86
+ it "should not have a token by default" do
87
+ Fleakr.expects(:mini_token).with().returns(nil)
88
+ Fleakr.expects(:auth_token).with().returns(nil)
89
+ Fleakr.expects(:frob).with().returns(nil)
90
+
91
+ Fleakr.token.should be(nil)
92
+ end
93
+
94
+ [:mini_token, :auth_token, :frob].each do |attribute|
95
+ it "should reset_token when :#{attribute} is set" do
96
+ Fleakr.expects(:reset_token).with().at_least_once
97
+ Fleakr.send("#{attribute}=".to_sym, 'value')
98
+ end
99
+ end
100
+
56
101
  context "when generating an AuthenticationToken from an auth_token string" do
57
102
 
58
103
  before do
@@ -63,7 +108,30 @@ class FleakrTest < Test::Unit::TestCase
63
108
  end
64
109
 
65
110
  # Make sure to clear the cache
66
- after { Fleakr.instance_variable_set(:@token, nil) }
111
+ after { Fleakr.auth_token = nil }
112
+
113
+ it "should return the token" do
114
+ Fleakr.token.should == @token
115
+ end
116
+
117
+ it "should cache the result" do
118
+ 2.times { Fleakr.token }
119
+ end
120
+
121
+ end
122
+
123
+ context "when generating an AuthenticationToken from a frob string" do
124
+
125
+ before do
126
+ @token = stub()
127
+
128
+ Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
129
+ Fleakr.expects(:frob).with().at_least_once.returns('abc123')
130
+ Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
131
+ end
132
+
133
+ # Make sure to clear the cache
134
+ after { Fleakr.frob = nil }
67
135
 
68
136
  it "should return the token" do
69
137
  Fleakr.token.should == @token
@@ -86,7 +154,7 @@ class FleakrTest < Test::Unit::TestCase
86
154
  end
87
155
 
88
156
  # Make sure to clear the cache
89
- after { Fleakr.instance_variable_set(:@token, nil) }
157
+ after { Fleakr.mini_token = nil }
90
158
 
91
159
  it "should return the token" do
92
160
  Fleakr.token.should == @token