mbbx6spp-twitter4r 0.3.1
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.
- 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,464 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
module Test
|
4
|
+
class Model
|
5
|
+
include Twitter::ModelMixin
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Twitter::Status, "unmarshaling" do
|
10
|
+
before(:each) do
|
11
|
+
@json_hash = { "text" => "Thinking Zipcar is lame...",
|
12
|
+
"id" => 46672912,
|
13
|
+
"user" => {"name" => "Angie",
|
14
|
+
"description" => "TV junkie...",
|
15
|
+
"location" => "NoVA",
|
16
|
+
"profile_image_url" => "http:\/\/assets0.twitter.com\/system\/user\/profile_image\/5483072\/normal\/eye.jpg?1177462492",
|
17
|
+
"url" => nil,
|
18
|
+
"id" => 5483072,
|
19
|
+
"protected" => false,
|
20
|
+
"screen_name" => "ang_410"},
|
21
|
+
"created_at" => "Wed May 02 03:04:54 +0000 2007"}
|
22
|
+
@user = Twitter::User.new @json_hash["user"]
|
23
|
+
@status = Twitter::Status.new @json_hash
|
24
|
+
@status.user = @user
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should respond to unmarshal class method" do
|
28
|
+
Twitter::Status.should respond_to(:unmarshal)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return expected Twitter::Status object for singular case" do
|
32
|
+
status = Twitter::Status.unmarshal(JSON.unparse(@json_hash))
|
33
|
+
status.should_not be(nil)
|
34
|
+
status.should eql(@status)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return expected array of Twitter::Status objects for plural case" do
|
38
|
+
statuses = Twitter::Status.unmarshal(JSON.unparse([@json_hash]))
|
39
|
+
statuses.should_not be(nil)
|
40
|
+
statuses.should have(1).entries
|
41
|
+
statuses.first.should eql(@status)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe Twitter::User, "unmarshaling" do
|
46
|
+
before(:each) do
|
47
|
+
@json_hash = { "name" => "Lucy Snowe",
|
48
|
+
"description" => "School Mistress Entrepreneur",
|
49
|
+
"location" => "Villette",
|
50
|
+
"url" => "http://villetteschoolforgirls.com",
|
51
|
+
"id" => 859303,
|
52
|
+
"protected" => true,
|
53
|
+
"screen_name" => "LucyDominatrix", }
|
54
|
+
@user = Twitter::User.new @json_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should respond to unmarshal class method" do
|
58
|
+
Twitter::User.should respond_to(:unmarshal)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return expected arry of Twitter::User objects for plural case" do
|
62
|
+
users = Twitter::User.unmarshal(JSON.unparse([@json_hash]))
|
63
|
+
users.should have(1).entries
|
64
|
+
users.first.should eql(@user)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return expected Twitter::User object for singular case" do
|
68
|
+
user = Twitter::User.unmarshal(JSON.unparse(@json_hash))
|
69
|
+
user.should_not be(nil)
|
70
|
+
user.should eql(@user)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "Twitter::ModelMixin#to_hash" do
|
75
|
+
before(:all) do
|
76
|
+
class Model
|
77
|
+
include Twitter::ModelMixin
|
78
|
+
@@ATTRIBUTES = [:id, :name, :value, :unused_attr]
|
79
|
+
attr_accessor *@@ATTRIBUTES
|
80
|
+
def self.attributes; @@ATTRIBUTES; end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Hash
|
84
|
+
def eql?(other)
|
85
|
+
return false unless other # trivial nil case.
|
86
|
+
return false unless self.keys.eql?(other.keys)
|
87
|
+
self.each do |key,val|
|
88
|
+
return false unless self[key].eql?(other[key])
|
89
|
+
end
|
90
|
+
true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
@attributes = {:id => 14, :name => 'State', :value => 'Illinois'}
|
97
|
+
@model = Model.new(@attributes)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return expected hash representation of given model object" do
|
101
|
+
@model.to_hash.should eql(@attributes)
|
102
|
+
end
|
103
|
+
|
104
|
+
after(:each) do
|
105
|
+
nilize(@attributes, @model)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe Twitter::User, ".find" do
|
110
|
+
before(:each) do
|
111
|
+
@twitter = Twitter::Client.from_config 'config/twitter.yml'
|
112
|
+
@id = 2423423
|
113
|
+
@screen_name = 'ascreenname'
|
114
|
+
@expected_user = Twitter::User.new(:id => @id, :screen_name => @screen_name)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should invoke given Twitter::Client's #user method with expected arguments" do
|
118
|
+
# case where id => @id
|
119
|
+
@twitter.should_receive(:user).with(@id).and_return(@expected_user)
|
120
|
+
user = Twitter::User.find(@id, @twitter)
|
121
|
+
user.should eql(@expected_user)
|
122
|
+
|
123
|
+
# case where id => @screen_name, which is also valid
|
124
|
+
@twitter.should_receive(:user).with(@screen_name).and_return(@expected_user)
|
125
|
+
user = Twitter::User.find(@screen_name, @twitter)
|
126
|
+
user.should eql(@expected_user)
|
127
|
+
end
|
128
|
+
|
129
|
+
after(:each) do
|
130
|
+
nilize(@twitter, @id, @screen_name, @expected_user)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe Twitter::Status, ".find" do
|
135
|
+
before(:each) do
|
136
|
+
@twitter = Twitter::Client.from_config 'config/twitter.yml'
|
137
|
+
@id = 9439843
|
138
|
+
@text = 'My crummy status message'
|
139
|
+
@user = Twitter::User.new(:id => @id, :screen_name => @screen_name)
|
140
|
+
@expected_status = Twitter::Status.new(:id => @id, :text => @text, :user => @user)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should invoke given Twitter::Client's #status method with expected arguments" do
|
144
|
+
@twitter.should_receive(:status).with(:get, @id).and_return(@expected_status)
|
145
|
+
status = Twitter::Status.find(@id, @twitter)
|
146
|
+
status.should eql(@expected_status)
|
147
|
+
end
|
148
|
+
|
149
|
+
after(:each) do
|
150
|
+
nilize(@twitter, @id, @text, @user, @expected_status)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe Test::Model, "#bless" do
|
155
|
+
before(:each) do
|
156
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
157
|
+
@model = Test::Model.new
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should delegate to #basic_bless" do
|
161
|
+
@model.should_receive(:basic_bless).and_return(@twitter)
|
162
|
+
@model.bless(@twitter)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should set client attribute of self" do
|
166
|
+
@model.should_receive(:client=).once
|
167
|
+
@model.bless(@twitter)
|
168
|
+
end
|
169
|
+
|
170
|
+
after(:each) do
|
171
|
+
nilize(@model, @twitter)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe Twitter::User, "#is_me?" do
|
176
|
+
before(:each) do
|
177
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
178
|
+
@user_not_me = Twitter::User.new(:screen_name => 'notmylogin')
|
179
|
+
@user_me = Twitter::User.new(:screen_name => @twitter.instance_eval("@login"))
|
180
|
+
@user_not_me.bless(@twitter)
|
181
|
+
@user_me.bless(@twitter)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should return true when Twitter::User object represents authenticated user of client context" do
|
185
|
+
@user_me.is_me?.should be_true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return false when Twitter::User object does not represent authenticated user of client context" do
|
189
|
+
@user_not_me.is_me?.should be_false
|
190
|
+
end
|
191
|
+
|
192
|
+
after(:each) do
|
193
|
+
nilize(@twitter, @user_not_me, @user_me)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe Twitter::User, "#friends" do
|
198
|
+
before(:each) do
|
199
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
200
|
+
@id = 5701682
|
201
|
+
@user = Twitter::User.new(:id => @id, :screen_name => 'twitter4r')
|
202
|
+
@user.bless(@twitter)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should delegate to @client.user(@id, :friends)" do
|
206
|
+
@twitter.should_receive(:user).with(@id, :friends)
|
207
|
+
@user.friends
|
208
|
+
end
|
209
|
+
|
210
|
+
after(:each) do
|
211
|
+
nilize(@twitter, @id, @user)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe Twitter::User, "#followers" do
|
216
|
+
before(:each) do
|
217
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
218
|
+
@id = 5701682
|
219
|
+
@user = Twitter::User.new(:id => @id, :screen_name => 'twitter4r')
|
220
|
+
@user.bless(@twitter)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should delegate to @client.my(:followers)" do
|
224
|
+
@twitter.should_receive(:my).with(:followers, {})
|
225
|
+
@user.followers
|
226
|
+
end
|
227
|
+
|
228
|
+
after(:each) do
|
229
|
+
nilize(@twitter, @id, @user)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe Test::Model, "#to_i" do
|
234
|
+
before(:each) do
|
235
|
+
@id = 234324285
|
236
|
+
class Test::Model
|
237
|
+
attr_accessor :id
|
238
|
+
end
|
239
|
+
@model = Test::Model.new(:id => @id)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should return @id attribute" do
|
243
|
+
@model.to_i.should eql(@id)
|
244
|
+
end
|
245
|
+
|
246
|
+
after(:each) do
|
247
|
+
nilize(@model, @id)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe Test::Model, "#to_s" do
|
252
|
+
before(:each) do
|
253
|
+
class Test::Model
|
254
|
+
attr_accessor :text
|
255
|
+
end
|
256
|
+
@text = 'Some text for the message body here'
|
257
|
+
@model = Test::Model.new(:text => @text)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return expected text when a @text attribute exists for the model" do
|
261
|
+
@model.to_s.should eql(@text)
|
262
|
+
end
|
263
|
+
|
264
|
+
after(:each) do
|
265
|
+
nilize(@model)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe Twitter::Message, ".find" do
|
270
|
+
it "should raise NotImplementedError due to Twitter (as opposed to Twitter4R) API limitation" do
|
271
|
+
lambda {
|
272
|
+
Twitter::Message.find(123, nil)
|
273
|
+
}.should raise_error(NotImplementedError)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe Twitter::Status, ".create" do
|
278
|
+
before(:each) do
|
279
|
+
@twitter = client_context
|
280
|
+
@text = 'My status update'
|
281
|
+
@status = Twitter::Status.new(:text => @text, :client => @twitter)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should invoke #status(:post, text) on client context given" do
|
285
|
+
@twitter.should_receive(:status).with(:post, @text).and_return(@status)
|
286
|
+
Twitter::Status.create(:text => @text, :client => @twitter)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should raise an ArgumentError when no client is given in params" do
|
290
|
+
lambda {
|
291
|
+
Twitter::Status.create(:text => @text)
|
292
|
+
}.should raise_error(ArgumentError)
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should raise an ArgumentError when no text is given in params" do
|
296
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
297
|
+
lambda {
|
298
|
+
Twitter::Status.create(:client => @twitter)
|
299
|
+
}.should raise_error(ArgumentError)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should raise an ArgumentError when text given in params is not a String" do
|
303
|
+
lambda {
|
304
|
+
Twitter::Status.create(:client => @twitter, :text => 234493)
|
305
|
+
}.should raise_error(ArgumentError)
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should raise an ArgumentError when client context given in params is not a Twitter::Client object" do
|
309
|
+
lambda {
|
310
|
+
Twitter::Status.create(:client => 'a string instead of a Twitter::Client', :text => @text)
|
311
|
+
}.should raise_error(ArgumentError)
|
312
|
+
end
|
313
|
+
|
314
|
+
after(:each) do
|
315
|
+
nilize(@twitter, @text, @status)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe Twitter::Message, ".create" do
|
320
|
+
before(:each) do
|
321
|
+
@twitter = client_context
|
322
|
+
@text = 'Just between you and I, Lantana and Gosford Park are two of my favorite movies'
|
323
|
+
@recipient = Twitter::User.new(:id => 234958)
|
324
|
+
@message = Twitter::Message.new(:text => @text, :recipient => @recipient)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should invoke #message(:post, text, recipient) on client context given" do
|
328
|
+
@twitter.should_receive(:message).with(:post, @text, @recipient).and_return(@message)
|
329
|
+
Twitter::Message.create(:client => @twitter, :text => @text, :recipient => @recipient)
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should raise an ArgumentError if no client context is given in params" do
|
333
|
+
lambda {
|
334
|
+
Twitter::Message.create(:text => @text, :recipient => @recipient)
|
335
|
+
}.should raise_error(ArgumentError)
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should raise an ArgumentError if client conext given in params is not a Twitter::Client object" do
|
339
|
+
lambda {
|
340
|
+
Twitter::Message.create(
|
341
|
+
:client => 3.14159,
|
342
|
+
:text => @text,
|
343
|
+
:recipient => @recipient)
|
344
|
+
}.should raise_error(ArgumentError)
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should raise an ArgumentError if no text is given in params" do
|
348
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
349
|
+
lambda {
|
350
|
+
Twitter::Message.create(
|
351
|
+
:client => @twitter,
|
352
|
+
:recipient => @recipient)
|
353
|
+
}.should raise_error(ArgumentError)
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should raise an ArgumentError if text given in params is not a String" do
|
357
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
358
|
+
lambda {
|
359
|
+
Twitter::Message.create(
|
360
|
+
:client => @twitter,
|
361
|
+
:text => Object.new,
|
362
|
+
:recipient => @recipient)
|
363
|
+
}.should raise_error(ArgumentError)
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should raise an ArgumentError if no recipient is given in params" do
|
367
|
+
@text.should_receive(:is_a?).with(String)
|
368
|
+
lambda {
|
369
|
+
Twitter::Message.create(
|
370
|
+
:client => @twitter,
|
371
|
+
:text => @text)
|
372
|
+
}.should raise_error(ArgumentError)
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should raise an ArgumentError if recipient given in params is not a Twitter::User, Integer or String object" do
|
376
|
+
@text.should_receive(:is_a?).with(String)
|
377
|
+
lambda {
|
378
|
+
Twitter::Message.create(
|
379
|
+
:client => @twitter,
|
380
|
+
:text => @text,
|
381
|
+
:recipient => 3.14159)
|
382
|
+
}.should raise_error(ArgumentError)
|
383
|
+
end
|
384
|
+
|
385
|
+
after(:each) do
|
386
|
+
nilize(@twitter, @text, @recipient, @message)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe Twitter::User, "#befriend" do
|
391
|
+
before(:each) do
|
392
|
+
@twitter = client_context
|
393
|
+
@user = Twitter::User.new(
|
394
|
+
:id => 1234,
|
395
|
+
:screen_name => 'mylogin',
|
396
|
+
:client => @twitter)
|
397
|
+
@friend = Twitter::User.new(
|
398
|
+
:id => 5678,
|
399
|
+
:screen_name => 'friend',
|
400
|
+
:client => @twitter)
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should invoke #friend(:add, user) on client context" do
|
404
|
+
@twitter.should_receive(:friend).with(:add, @friend).and_return(@friend)
|
405
|
+
@user.befriend(@friend)
|
406
|
+
end
|
407
|
+
|
408
|
+
after(:each) do
|
409
|
+
nilize(@twitter, @user, @friend)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
describe Twitter::User, "#defriend" do
|
414
|
+
before(:each) do
|
415
|
+
@twitter = client_context
|
416
|
+
@user = Twitter::User.new(
|
417
|
+
:id => 1234,
|
418
|
+
:screen_name => 'mylogin',
|
419
|
+
:client => @twitter)
|
420
|
+
@friend = Twitter::User.new(
|
421
|
+
:id => 5678,
|
422
|
+
:screen_name => 'friend',
|
423
|
+
:client => @twitter)
|
424
|
+
end
|
425
|
+
|
426
|
+
it "should invoke #friend(:remove, user) on client context" do
|
427
|
+
@twitter.should_receive(:friend).with(:remove, @friend).and_return(@friend)
|
428
|
+
@user.defriend(@friend)
|
429
|
+
end
|
430
|
+
|
431
|
+
after(:each) do
|
432
|
+
nilize(@twitter, @user, @friend)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
describe Twitter::Status, "#to_s" do
|
437
|
+
before(:each) do
|
438
|
+
@text = 'Aloha'
|
439
|
+
@status = Twitter::Status.new(:text => @text)
|
440
|
+
end
|
441
|
+
|
442
|
+
it "should render text attribute" do
|
443
|
+
@status.to_s.should be(@text)
|
444
|
+
end
|
445
|
+
|
446
|
+
after(:each) do
|
447
|
+
nilize(@text, @status)
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
describe Twitter::Message, "#to_s" do
|
452
|
+
before(:each) do
|
453
|
+
@text = 'Aloha'
|
454
|
+
@message = Twitter::Message.new(:text => @text)
|
455
|
+
end
|
456
|
+
|
457
|
+
it "should render text attribute" do
|
458
|
+
@message.to_s.should be(@text)
|
459
|
+
end
|
460
|
+
|
461
|
+
after(:each) do
|
462
|
+
nilize(@text, @message)
|
463
|
+
end
|
464
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe String, "representing a class name" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@class_name = Twitter::User.class.name
|
7
|
+
@xmlized_name = @class_name.downcase # simple case for the moment...since Rails' support for namespaced models sucks!
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be downcased (minus module namespaces) when xmlized" do
|
11
|
+
@class_name.xmlize.should eql(@xmlized_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
nilize(@class_name, @xmlized_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Rails model extensions for model classes", :shared => true do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@id = 3242334
|
23
|
+
@id_s = @id.to_s
|
24
|
+
@model = model(@id)
|
25
|
+
@model_hash = @model.to_hash
|
26
|
+
@json = JSON.unparse(@model_hash)
|
27
|
+
@serializer = ActiveRecord::XmlSerializer.new(@model, {:root => @model.class.name.downcase})
|
28
|
+
@xml = @serializer.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should invoke #to_param as expected" do
|
32
|
+
@model.should_receive(:id).and_return(@id)
|
33
|
+
@model.to_param
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return string representation for id for #to_param" do
|
37
|
+
@model.to_param.class.should eql(String)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return output from JSON.unparse for #to_json" do
|
41
|
+
@model.should_receive(:to_hash).and_return(@model_hash)
|
42
|
+
JSON.should_receive(:unparse).and_return(@json)
|
43
|
+
@model.to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return XmlSerializer string output for #to_xml" do
|
47
|
+
ActiveRecord::XmlSerializer.should_receive(:new).and_return(@serializer)
|
48
|
+
@serializer.should_receive(:to_s).and_return(@xml)
|
49
|
+
@model.to_xml
|
50
|
+
end
|
51
|
+
|
52
|
+
after(:each) do
|
53
|
+
nilize(@id, @model)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe Twitter::User, "Rails extensions" do
|
58
|
+
|
59
|
+
def model(id)
|
60
|
+
Twitter::User.new(:id => id)
|
61
|
+
end
|
62
|
+
|
63
|
+
it_should_behave_like "Rails model extensions for model classes"
|
64
|
+
end
|
65
|
+
|
66
|
+
describe Twitter::Status, "Rails extensions" do
|
67
|
+
|
68
|
+
def model(id)
|
69
|
+
Twitter::Status.new(:id => id)
|
70
|
+
end
|
71
|
+
|
72
|
+
it_should_behave_like "Rails model extensions for model classes"
|
73
|
+
end
|
74
|
+
|
75
|
+
describe Twitter::Message, "Rails extensions" do
|
76
|
+
|
77
|
+
def model(id)
|
78
|
+
Twitter::Message.new(:id => id)
|
79
|
+
end
|
80
|
+
|
81
|
+
it_should_behave_like "Rails model extensions for model classes"
|
82
|
+
end
|
83
|
+
|
84
|
+
describe Twitter::RESTError, "Rails extensions" do
|
85
|
+
|
86
|
+
before(:each) do
|
87
|
+
@attributes = { :code => 200, :message => 'Success', :uri => 'http://twitter.com/statuses' }
|
88
|
+
@model = Twitter::RESTError.new(@attributes)
|
89
|
+
@json = "JSON" # doesn't really matter what the value is
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return a Hash of attribute name-value pairs for #to_hash" do
|
93
|
+
@model.to_hash.should === @attributes
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should invoke XmlSerializer for #to_xml" do
|
97
|
+
|
98
|
+
@model.to_xml
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return expected JSON for #to_json" do
|
102
|
+
@model.to_hash
|
103
|
+
JSON.should_receive(:unparse).and_return(@json)
|
104
|
+
@model.to_json
|
105
|
+
end
|
106
|
+
|
107
|
+
after(:each) do
|
108
|
+
nilize(@attributes, @model)
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
VERSION_LIST = [Twitter::Version::MAJOR, Twitter::Version::MINOR, Twitter::Version::REVISION]
|
4
|
+
|
5
|
+
EXPECTED_VERSION = VERSION_LIST.join('.')
|
6
|
+
EXPECTED_NAME = VERSION_LIST.join('_')
|
7
|
+
|
8
|
+
describe Twitter::Version, ".to_version" do
|
9
|
+
it "should return #{EXPECTED_VERSION}" do
|
10
|
+
Twitter::Version.to_version.should eql(EXPECTED_VERSION)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Twitter::Version, ".to_name" do
|
15
|
+
it "should return #{EXPECTED_NAME}" do
|
16
|
+
Twitter::Version.to_name.should eql(EXPECTED_NAME)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mbbx6spp-twitter4r
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Susan Potter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.1
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: twitter4r-users@googlegroups.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- CHANGES
|
33
|
+
- TODO
|
34
|
+
- MIT-LICENSE
|
35
|
+
files:
|
36
|
+
- lib/twitter/extras.rb
|
37
|
+
- lib/twitter/config.rb
|
38
|
+
- lib/twitter/core.rb
|
39
|
+
- lib/twitter/client/blocks.rb
|
40
|
+
- lib/twitter/client/account.rb
|
41
|
+
- lib/twitter/client/timeline.rb
|
42
|
+
- lib/twitter/client/messaging.rb
|
43
|
+
- lib/twitter/client/base.rb
|
44
|
+
- lib/twitter/client/favorites.rb
|
45
|
+
- lib/twitter/client/status.rb
|
46
|
+
- lib/twitter/client/friendship.rb
|
47
|
+
- lib/twitter/client/auth.rb
|
48
|
+
- lib/twitter/client/user.rb
|
49
|
+
- lib/twitter/rails.rb
|
50
|
+
- lib/twitter/client.rb
|
51
|
+
- lib/twitter/console.rb
|
52
|
+
- lib/twitter/version.rb
|
53
|
+
- lib/twitter/model.rb
|
54
|
+
- lib/twitter/meta.rb
|
55
|
+
- lib/twitter/ext.rb
|
56
|
+
- lib/twitter/ext/stdlib.rb
|
57
|
+
- lib/twitter.rb
|
58
|
+
- spec/twitter/config_spec.rb
|
59
|
+
- spec/twitter/core_spec.rb
|
60
|
+
- spec/twitter/model_spec.rb
|
61
|
+
- spec/twitter/client/status_spec.rb
|
62
|
+
- spec/twitter/client/timeline_spec.rb
|
63
|
+
- spec/twitter/client/auth_spec.rb
|
64
|
+
- spec/twitter/client/user_spec.rb
|
65
|
+
- spec/twitter/client/messaging_spec.rb
|
66
|
+
- spec/twitter/client/base_spec.rb
|
67
|
+
- spec/twitter/client/favorites_spec.rb
|
68
|
+
- spec/twitter/client/friendship_spec.rb
|
69
|
+
- spec/twitter/client/blocks_spec.rb
|
70
|
+
- spec/twitter/version_spec.rb
|
71
|
+
- spec/twitter/rails_spec.rb
|
72
|
+
- spec/twitter/client_spec.rb
|
73
|
+
- spec/twitter/meta_spec.rb
|
74
|
+
- spec/twitter/console_spec.rb
|
75
|
+
- spec/twitter/extras_spec.rb
|
76
|
+
- spec/twitter/ext/stdlib_spec.rb
|
77
|
+
- README
|
78
|
+
- CHANGES
|
79
|
+
- TODO
|
80
|
+
- MIT-LICENSE
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://twitter4r.rubyforge.org
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
version:
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project: twitter4r
|
103
|
+
rubygems_version: 1.2.0
|
104
|
+
signing_key:
|
105
|
+
specification_version: 2
|
106
|
+
summary: A clean Twitter client API in pure Ruby. Will include Twitter add-ons also in Ruby.
|
107
|
+
test_files: []
|
108
|
+
|