mbbx6spp-twitter4r 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +124 -0
- data/MIT-LICENSE +20 -0
- data/README +32 -0
- data/TODO +9 -0
- data/lib/twitter/client/account.rb +24 -0
- data/lib/twitter/client/auth.rb +27 -0
- data/lib/twitter/client/base.rb +87 -0
- data/lib/twitter/client/blocks.rb +35 -0
- data/lib/twitter/client/favorites.rb +53 -0
- data/lib/twitter/client/friendship.rb +35 -0
- data/lib/twitter/client/messaging.rb +79 -0
- data/lib/twitter/client/status.rb +46 -0
- data/lib/twitter/client/timeline.rb +72 -0
- data/lib/twitter/client/user.rb +65 -0
- data/lib/twitter/client.rb +21 -0
- data/lib/twitter/config.rb +71 -0
- data/lib/twitter/console.rb +28 -0
- data/lib/twitter/core.rb +137 -0
- data/lib/twitter/ext/stdlib.rb +51 -0
- data/lib/twitter/ext.rb +2 -0
- data/lib/twitter/extras.rb +39 -0
- data/lib/twitter/meta.rb +56 -0
- data/lib/twitter/model.rb +348 -0
- data/lib/twitter/rails.rb +92 -0
- data/lib/twitter/version.rb +19 -0
- data/lib/twitter.rb +31 -0
- data/spec/twitter/client/auth_spec.rb +34 -0
- data/spec/twitter/client/base_spec.rb +242 -0
- data/spec/twitter/client/blocks_spec.rb +76 -0
- data/spec/twitter/client/favorites_spec.rb +183 -0
- data/spec/twitter/client/friendship_spec.rb +76 -0
- data/spec/twitter/client/messaging_spec.rb +135 -0
- data/spec/twitter/client/status_spec.rb +92 -0
- data/spec/twitter/client/timeline_spec.rb +79 -0
- data/spec/twitter/client/user_spec.rb +203 -0
- data/spec/twitter/client_spec.rb +2 -0
- data/spec/twitter/config_spec.rb +86 -0
- data/spec/twitter/console_spec.rb +15 -0
- data/spec/twitter/core_spec.rb +127 -0
- data/spec/twitter/ext/stdlib_spec.rb +42 -0
- data/spec/twitter/extras_spec.rb +46 -0
- data/spec/twitter/meta_spec.rb +90 -0
- data/spec/twitter/model_spec.rb +464 -0
- data/spec/twitter/rails_spec.rb +110 -0
- data/spec/twitter/version_spec.rb +19 -0
- metadata +108 -0
@@ -0,0 +1,242 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "Twitter::Client" do
|
4
|
+
before(:each) do
|
5
|
+
@init_hash = { :login => 'user', :password => 'pass' }
|
6
|
+
end
|
7
|
+
|
8
|
+
it ".new should accept login and password as initializer hash keys and set the values to instance values" do
|
9
|
+
client = nil
|
10
|
+
lambda do
|
11
|
+
client = Twitter::Client.new(@init_hash)
|
12
|
+
end.should_not raise_error
|
13
|
+
client.send(:login).should eql(@init_hash[:login])
|
14
|
+
client.send(:password).should eql(@init_hash[:password])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Twitter::Client, "#inspect" do
|
19
|
+
before(:each) do
|
20
|
+
@client = Twitter::Client.new(:login => "NippleEquality", :password => "3rdnipple")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should block out password attribute values" do
|
24
|
+
@client.inspect.should_not match(/@password="3rdnipple"/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Twitter::Client, "#http_header" do
|
29
|
+
before(:each) do
|
30
|
+
@user_agent = 'myapp'
|
31
|
+
@application_name = @user_agent
|
32
|
+
@application_version = '1.2.3'
|
33
|
+
@application_url = 'http://myapp.url'
|
34
|
+
Twitter::Client.configure do |conf|
|
35
|
+
conf.user_agent = @user_agent
|
36
|
+
conf.application_name = @application_name
|
37
|
+
conf.application_version = @application_version
|
38
|
+
conf.application_url = @application_url
|
39
|
+
end
|
40
|
+
@expected_headers = {
|
41
|
+
'Accept' => 'text/x-json',
|
42
|
+
'X-Twitter-Client' => @application_name,
|
43
|
+
'X-Twitter-Client-Version' => @application_version,
|
44
|
+
'X-Twitter-Client-URL' => @application_url,
|
45
|
+
'User-Agent' => "Twitter4R v#{Twitter::Version.to_version} [#{@user_agent}]",
|
46
|
+
}
|
47
|
+
@twitter = client_context
|
48
|
+
# reset @@http_header class variable in Twitter::Client class
|
49
|
+
Twitter::Client.class_eval("@@http_header = nil")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should always return expected HTTP headers" do
|
53
|
+
headers = @twitter.send(:http_header)
|
54
|
+
headers.should === @expected_headers
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should cache HTTP headers Hash in class variable after first invocation" do
|
58
|
+
cache = Twitter::Client.class_eval("@@http_header")
|
59
|
+
cache.should be_nil
|
60
|
+
@twitter.send(:http_header)
|
61
|
+
cache = Twitter::Client.class_eval("@@http_header")
|
62
|
+
cache.should_not be_nil
|
63
|
+
cache.should === @expected_headers
|
64
|
+
end
|
65
|
+
|
66
|
+
after(:each) do
|
67
|
+
nilize(@user_agent, @application_name, @application_version, @application_url, @twitter, @expected_headers)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Twitter::Client, "#create_http_get_request" do
|
72
|
+
before(:each) do
|
73
|
+
@uri = '/some/path'
|
74
|
+
@expected_get_request = mock(Net::HTTP::Get)
|
75
|
+
@twitter = client_context
|
76
|
+
@default_header = @twitter.send(:http_header)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should create new Net::HTTP::Get object with expected initialization arguments" do
|
80
|
+
Net::HTTP::Get.should_receive(:new).with(@uri, @default_header).and_return(@expected_get_request)
|
81
|
+
@twitter.send(:create_http_get_request, @uri)
|
82
|
+
end
|
83
|
+
|
84
|
+
after(:each) do
|
85
|
+
nilize(@twitter, @uri, @expected_get_request, @default_header)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe Twitter::Client, "#create_http_post_request" do
|
90
|
+
before(:each) do
|
91
|
+
@uri = '/some/path'
|
92
|
+
@expected_post_request = mock(Net::HTTP::Post)
|
93
|
+
@twitter = client_context
|
94
|
+
@default_header = @twitter.send(:http_header)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should create new Net::HTTP::Post object with expected initialization arguments" do
|
98
|
+
Net::HTTP::Post.should_receive(:new).with(@uri, @default_header).and_return(@expected_post_request)
|
99
|
+
@twitter.send(:create_http_post_request, @uri)
|
100
|
+
end
|
101
|
+
|
102
|
+
after(:each) do
|
103
|
+
nilize(@twitter, @uri, @expected_post_request, @default_header)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe Twitter::Client, "#create_http_delete_request" do
|
108
|
+
before(:each) do
|
109
|
+
@uri = '/a/stupid/path/that/is/not/restful/since/twitter.com/cannot/do/consistent/restful/apis'
|
110
|
+
@expected_delete_request = mock(Net::HTTP::Delete)
|
111
|
+
@twitter = client_context
|
112
|
+
@default_header = @twitter.send(:http_header)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should create new Net::HTTP::Delete object with expected initialization arguments" do
|
116
|
+
Net::HTTP::Delete.should_receive(:new).with(@uri, @default_header).and_return(@expected_delete_request)
|
117
|
+
@twitter.send(:create_http_delete_request, @uri)
|
118
|
+
end
|
119
|
+
|
120
|
+
after(:each) do
|
121
|
+
nilize(@twitter, @uri, @expected_delete_request, @default_header)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe Twitter::Client, "#http_connect" do
|
126
|
+
before(:each) do
|
127
|
+
@request = mas_net_http_get(:basic_auth => nil)
|
128
|
+
@good_response = mas_net_http_response(:success)
|
129
|
+
@bad_response = mas_net_http_response(:server_error)
|
130
|
+
@http_stubs = {:is_a? => true}
|
131
|
+
@block = Proc.new do |conn|
|
132
|
+
conn.is_a?(Net::HTTP).should be(true)
|
133
|
+
@has_yielded = true
|
134
|
+
@request
|
135
|
+
end
|
136
|
+
@twitter = client_context
|
137
|
+
@has_yielded = false
|
138
|
+
end
|
139
|
+
|
140
|
+
def generate_bad_response
|
141
|
+
@http = mas_net_http(@bad_response, @http_stubs)
|
142
|
+
Net::HTTP.stub!(:new).and_return(@http)
|
143
|
+
end
|
144
|
+
|
145
|
+
def generate_good_response
|
146
|
+
@http = mas_net_http(@good_response, @http_stubs)
|
147
|
+
Net::HTTP.stub!(:new).and_return(@http)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should yield HTTP connection when response is good" do
|
151
|
+
generate_good_response
|
152
|
+
@http.should_receive(:is_a?).with(Net::HTTP).and_return(true)
|
153
|
+
lambda do
|
154
|
+
@twitter.send(:http_connect, &@block)
|
155
|
+
end.should_not raise_error
|
156
|
+
@has_yielded.should be(true)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should yield HTTP connection when response is bad" do
|
160
|
+
generate_bad_response
|
161
|
+
@http.should_receive(:is_a?).with(Net::HTTP).and_return(true)
|
162
|
+
lambda {
|
163
|
+
@twitter.send(:http_connect, &@block)
|
164
|
+
}.should raise_error(Twitter::RESTError)
|
165
|
+
@has_yielded.should be(true)
|
166
|
+
end
|
167
|
+
|
168
|
+
after(:each) do
|
169
|
+
nilize(@good_response, @bad_response, @http)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe Twitter::Client, "#bless_model" do
|
174
|
+
before(:each) do
|
175
|
+
@twitter = client_context
|
176
|
+
@model = Twitter::User.new
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should recieve #client= message on given model to self" do
|
180
|
+
@model.should_receive(:client=).with(@twitter)
|
181
|
+
model = @twitter.send(:bless_model, @model)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should set client attribute on given model to self" do
|
185
|
+
model = @twitter.send(:bless_model, @model)
|
186
|
+
model.client.should eql(@twitter)
|
187
|
+
end
|
188
|
+
|
189
|
+
# if model is nil, it doesn't not necessarily signify an exceptional case for this method's usage.
|
190
|
+
it "should return nil when receiving nil and not raise any exceptions" do
|
191
|
+
model = @twitter.send(:bless_model, nil)
|
192
|
+
model.should be_nil
|
193
|
+
end
|
194
|
+
|
195
|
+
# needed to alert developer that the model needs to respond to #client= messages appropriately.
|
196
|
+
it "should raise an error if passing in a non-nil object that doesn't not respond to the :client= message" do
|
197
|
+
lambda {
|
198
|
+
@twitter.send(:bless_model, Object.new)
|
199
|
+
}.should raise_error(NoMethodError)
|
200
|
+
end
|
201
|
+
|
202
|
+
after(:each) do
|
203
|
+
nilize(@twitter)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe Twitter::Client, "#bless_models" do
|
208
|
+
before(:each) do
|
209
|
+
@twitter = client_context
|
210
|
+
@models = [
|
211
|
+
Twitter::Status.new(:text => 'message #1'),
|
212
|
+
Twitter::Status.new(:text => 'message #2'),
|
213
|
+
]
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should set client attributes for each model in given Array to self" do
|
217
|
+
models = @twitter.send(:bless_models, @models)
|
218
|
+
models.each {|model| model.client.should eql(@twitter) }
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should set client attribute for singular model given to self" do
|
222
|
+
model = @twitter.send(:bless_models, @models[0])
|
223
|
+
model.client.should eql(@twitter)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should delegate to bless_model for singular model case" do
|
227
|
+
model = @models[0]
|
228
|
+
@twitter.should_receive(:bless_model).with(model).and_return(model)
|
229
|
+
@twitter.send(:bless_models, model)
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should return nil when receiving nil and not raise any exceptions" do
|
233
|
+
lambda {
|
234
|
+
value = @twitter.send(:bless_models, nil)
|
235
|
+
value.should be_nil
|
236
|
+
}.should_not raise_error
|
237
|
+
end
|
238
|
+
|
239
|
+
after(:each) do
|
240
|
+
nilize(@twitter, @models)
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Twitter::Client, "#block" do
|
4
|
+
before(:each) do
|
5
|
+
@twitter = client_context
|
6
|
+
@id = 1234567
|
7
|
+
@screen_name = 'dummylogin'
|
8
|
+
@friend = Twitter::User.new(:id => @id, :screen_name => @screen_name)
|
9
|
+
@uris = Twitter::Client.class_eval("@@BLOCK_URIS")
|
10
|
+
@request = mas_net_http_get(:basic_auth => nil)
|
11
|
+
@response = mas_net_http_response(:success)
|
12
|
+
@connection = mas_net_http(@response)
|
13
|
+
Net::HTTP.stub!(:new).and_return(@connection)
|
14
|
+
Twitter::User.stub!(:unmarshal).and_return(@friend)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_uri(action, id)
|
18
|
+
"#{@uris[action]}/#{id}.json"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create expected HTTP GET request for :add case using integer user ID" do
|
22
|
+
# the integer user ID scenario...
|
23
|
+
@twitter.should_receive(:create_http_get_request).with(create_uri(:add, @id)).and_return(@request)
|
24
|
+
@twitter.block(:add, @id)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create expected HTTP GET request for :add case using screen name" do
|
28
|
+
# the screen name scenario...
|
29
|
+
@twitter.should_receive(:create_http_get_request).with(create_uri(:add, @screen_name)).and_return(@request)
|
30
|
+
@twitter.block(:add, @screen_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create expected HTTP GET request for :add case using Twitter::User object" do
|
34
|
+
# the Twitter::User object scenario...
|
35
|
+
@twitter.should_receive(:create_http_get_request).with(create_uri(:add, @friend.to_i)).and_return(@request)
|
36
|
+
@twitter.block(:add, @friend)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create expected HTTP GET request for :remove case using integer user ID" do
|
40
|
+
# the integer user ID scenario...
|
41
|
+
@twitter.should_receive(:create_http_get_request).with(create_uri(:remove, @id)).and_return(@request)
|
42
|
+
@twitter.block(:remove, @id)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create expected HTTP GET request for :remove case using screen name" do
|
46
|
+
# the screen name scenario...
|
47
|
+
@twitter.should_receive(:create_http_get_request).with(create_uri(:remove, @screen_name)).and_return(@request)
|
48
|
+
@twitter.block(:remove, @screen_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create expected HTTP GET request for :remove case using Twitter::User object" do
|
52
|
+
# the Twitter::User object scenario...
|
53
|
+
@twitter.should_receive(:create_http_get_request).with(create_uri(:remove, @friend.to_i)).and_return(@request)
|
54
|
+
@twitter.block(:remove, @friend)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should bless user model returned for :add case" do
|
58
|
+
@twitter.should_receive(:bless_model).with(@friend)
|
59
|
+
@twitter.block(:add, @friend)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should bless user model returned for :remove case" do
|
63
|
+
@twitter.should_receive(:bless_model).with(@friend)
|
64
|
+
@twitter.block(:remove, @friend)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should raise ArgumentError if action given is not valid" do
|
68
|
+
lambda {
|
69
|
+
@twitter.block(:crap, @friend)
|
70
|
+
}.should raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
after(:each) do
|
74
|
+
nilize(@twitter, @id, @uris, @request, @response, @connection)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Twitter::Client, "#favorites" do
|
4
|
+
before(:each) do
|
5
|
+
@uri = '/favorites.json'
|
6
|
+
@request = mas_net_http_get(:basic_auth => nil)
|
7
|
+
@twitter = client_context
|
8
|
+
@default_header = @twitter.send(:http_header)
|
9
|
+
@response = mas_net_http_response(:success)
|
10
|
+
@connection = mas_net_http(@response)
|
11
|
+
@options = { :page => 4 }
|
12
|
+
Net::HTTP.stub!(:new).and_return(@connection)
|
13
|
+
@favorites = []
|
14
|
+
Twitter::Status.stub!(:unmarshal).and_return(@favorites)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create expected HTTP GET request when not giving options" do
|
18
|
+
@twitter.should_receive(:create_http_get_request).with(@uri).and_return(@request)
|
19
|
+
@twitter.favorites
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should create expected HTTP GET request when giving :page options" do
|
23
|
+
@twitter.should_receive(:create_http_get_request).with("#{@uri}?#{@options.to_http_str}").and_return(@request)
|
24
|
+
@twitter.favorites(@options)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise Twitter::RESTError when 401 HTTP response received without giving options" do
|
28
|
+
@connection = mas_net_http(mas_net_http_response(:not_authorized))
|
29
|
+
lambda {
|
30
|
+
@twitter.favorites
|
31
|
+
}.should raise_error(Twitter::RESTError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise Twitter::RESTError when 401 HTTP response received when giving page options" do
|
35
|
+
@connection = mas_net_http(mas_net_http_response(:not_authorized))
|
36
|
+
lambda {
|
37
|
+
@twitter.favorites(@options)
|
38
|
+
}.should raise_error(Twitter::RESTError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise Twitter::RESTError when 403 HTTP response received without giving options" do
|
42
|
+
@connection = mas_net_http(mas_net_http_response(:forbidden))
|
43
|
+
lambda {
|
44
|
+
@twitter.favorites
|
45
|
+
}.should raise_error(Twitter::RESTError)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise Twitter::RESTError when 403 HTTP response received when giving page options" do
|
49
|
+
@connection = mas_net_http(mas_net_http_response(:forbidden))
|
50
|
+
lambda {
|
51
|
+
@twitter.favorites(@options)
|
52
|
+
}.should raise_error(Twitter::RESTError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should raise Twitter::RESTError when 500 HTTP response received without giving options" do
|
56
|
+
@connection = mas_net_http(mas_net_http_response(:server_error))
|
57
|
+
lambda {
|
58
|
+
@twitter.favorites
|
59
|
+
}.should raise_error(Twitter::RESTError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should raise Twitter::RESTError when 500 HTTP response received when giving page options" do
|
63
|
+
@connection = mas_net_http(mas_net_http_response(:server_error))
|
64
|
+
lambda {
|
65
|
+
@twitter.favorites(@options)
|
66
|
+
}.should raise_error(Twitter::RESTError)
|
67
|
+
end
|
68
|
+
|
69
|
+
after(:each) do
|
70
|
+
nilize(@uri, @request, @twitter, @default_header, @response, @error_response, @connection)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module FavoriteSpecMixin
|
75
|
+
def init
|
76
|
+
@base_uri = '/favourings'
|
77
|
+
@request = mas_net_http_get(:basic_auth => nil)
|
78
|
+
@twitter = client_context
|
79
|
+
@default_header = @twitter.send(:http_header)
|
80
|
+
@response = mas_net_http_response(:success)
|
81
|
+
@connection = mas_net_http(@response)
|
82
|
+
Net::HTTP.stub!(:new).and_return(@connection)
|
83
|
+
@id = 234923423
|
84
|
+
@status = mas_twitter_status(:id => @id, :to_i => @id)
|
85
|
+
Twitter::Status.stub!(:unmarshal).and_return(@status)
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_uri(method, id)
|
89
|
+
"#{@base_uri}/#{method.to_s}/#{id.to_i.to_s}.json"
|
90
|
+
end
|
91
|
+
|
92
|
+
def connection=(connection)
|
93
|
+
@connection = connection
|
94
|
+
end
|
95
|
+
|
96
|
+
def finalize
|
97
|
+
nilize(@uri, @request, @twitter, @default_header, @response, @error_response, @connection)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "Twitter::Client#favorite error handling", :shared => true do
|
102
|
+
it "should raise a Twitter::RESTError exception when a 401 HTTP response is received" do
|
103
|
+
connection = mas_net_http(mas_net_http_response(:not_authorized))
|
104
|
+
lambda {
|
105
|
+
execute_method
|
106
|
+
}.should raise_error(Twitter::RESTError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should raise a Twitter::RESTError exception when a 403 HTTP response is received" do
|
110
|
+
connection = mas_net_http(mas_net_http_response(:forbidden))
|
111
|
+
lambda {
|
112
|
+
execute_method
|
113
|
+
}.should raise_error(Twitter::RESTError)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should raise a Twitter::RESTError exception when a 404 HTTP response is received" do
|
117
|
+
connection = mas_net_http(mas_net_http_response(:file_not_found))
|
118
|
+
lambda {
|
119
|
+
execute_method
|
120
|
+
}.should raise_error(Twitter::RESTError)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should raise a Twitter::RESTError exception when a 500 HTTP response is received" do
|
124
|
+
connection = mas_net_http(mas_net_http_response(:server_error))
|
125
|
+
lambda {
|
126
|
+
execute_method
|
127
|
+
}.should raise_error(Twitter::RESTError)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe Twitter::Client, "#favorite(:add, status)" do
|
132
|
+
include FavoriteSpecMixin
|
133
|
+
it_should_behave_like "Twitter::Client#favorite error handling"
|
134
|
+
|
135
|
+
before(:each) do
|
136
|
+
init
|
137
|
+
end
|
138
|
+
|
139
|
+
def execute_method
|
140
|
+
@twitter.favorite(:add, @id)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should create expected POST request for :add action supplying integer id of status" do
|
144
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:create, @id)).and_return(@request)
|
145
|
+
@twitter.favorite(:add, @id)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should create expected POST request for :add action supplying status object" do
|
149
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:create, @id)).and_return(@request)
|
150
|
+
@twitter.favorite(:add, @status)
|
151
|
+
end
|
152
|
+
|
153
|
+
after(:each) do
|
154
|
+
finalize
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe Twitter::Client, "#favorite(:remove, status)" do
|
159
|
+
include FavoriteSpecMixin
|
160
|
+
it_should_behave_like "Twitter::Client#favorite error handling"
|
161
|
+
|
162
|
+
before(:each) do
|
163
|
+
init
|
164
|
+
end
|
165
|
+
|
166
|
+
def execute_method
|
167
|
+
@twitter.favorite(:remove, @id)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should create expected DELETE request for :remove action supplying integer id of status" do
|
171
|
+
@twitter.should_receive(:create_http_delete_request).with(create_uri(:destroy, @id)).and_return(@request)
|
172
|
+
@twitter.favorite(:remove, @id)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should create expected DELETE request for :remove action supplying status object" do
|
176
|
+
@twitter.should_receive(:create_http_delete_request).with(create_uri(:destroy, @id)).and_return(@request)
|
177
|
+
@twitter.favorite(:remove, @status)
|
178
|
+
end
|
179
|
+
|
180
|
+
after(:each) do
|
181
|
+
finalize
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Twitter::Client, "#friend" do
|
4
|
+
before(:each) do
|
5
|
+
@twitter = client_context
|
6
|
+
@id = 1234567
|
7
|
+
@screen_name = 'dummylogin'
|
8
|
+
@friend = Twitter::User.new(:id => @id, :screen_name => @screen_name)
|
9
|
+
@uris = Twitter::Client.class_eval("@@FRIENDSHIP_URIS")
|
10
|
+
@request = mas_net_http_post(:basic_auth => nil)
|
11
|
+
@response = mas_net_http_response(:success)
|
12
|
+
@connection = mas_net_http(@response)
|
13
|
+
Net::HTTP.stub!(:new).and_return(@connection)
|
14
|
+
Twitter::User.stub!(:unmarshal).and_return(@friend)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_uri(action, id)
|
18
|
+
"#{@uris[action]}/#{id}.json"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create expected HTTP GET request for :add case using integer user ID" do
|
22
|
+
# the integer user ID scenario...
|
23
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:add, @id)).and_return(@request)
|
24
|
+
@twitter.friend(:add, @id)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create expected HTTP GET request for :add case using screen name" do
|
28
|
+
# the screen name scenario...
|
29
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:add, @screen_name)).and_return(@request)
|
30
|
+
@twitter.friend(:add, @screen_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create expected HTTP GET request for :add case using Twitter::User object" do
|
34
|
+
# the Twitter::User object scenario...
|
35
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:add, @friend.to_i)).and_return(@request)
|
36
|
+
@twitter.friend(:add, @friend)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create expected HTTP GET request for :remove case using integer user ID" do
|
40
|
+
# the integer user ID scenario...
|
41
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:remove, @id)).and_return(@request)
|
42
|
+
@twitter.friend(:remove, @id)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create expected HTTP GET request for :remove case using screen name" do
|
46
|
+
# the screen name scenario...
|
47
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:remove, @screen_name)).and_return(@request)
|
48
|
+
@twitter.friend(:remove, @screen_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create expected HTTP GET request for :remove case using Twitter::User object" do
|
52
|
+
# the Twitter::User object scenario...
|
53
|
+
@twitter.should_receive(:create_http_post_request).with(create_uri(:remove, @friend.to_i)).and_return(@request)
|
54
|
+
@twitter.friend(:remove, @friend)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should bless user model returned for :add case" do
|
58
|
+
@twitter.should_receive(:bless_model).with(@friend)
|
59
|
+
@twitter.friend(:add, @friend)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should bless user model returned for :remove case" do
|
63
|
+
@twitter.should_receive(:bless_model).with(@friend)
|
64
|
+
@twitter.friend(:remove, @friend)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should raise ArgumentError if action given is not valid" do
|
68
|
+
lambda {
|
69
|
+
@twitter.friend(:crap, @friend)
|
70
|
+
}.should raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
after(:each) do
|
74
|
+
nilize(@twitter, @id, @uris, @request, @response, @connection)
|
75
|
+
end
|
76
|
+
end
|