twitter 5.1.1 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +10 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +30 -20
- data/Rakefile +26 -5
- data/lib/twitter/arguments.rb +0 -1
- data/lib/twitter/base.rb +13 -16
- data/lib/twitter/basic_user.rb +3 -3
- data/lib/twitter/client.rb +7 -8
- data/lib/twitter/configuration.rb +5 -5
- data/lib/twitter/core_ext/enumerable.rb +0 -2
- data/lib/twitter/core_ext/kernel.rb +0 -2
- data/lib/twitter/creatable.rb +0 -1
- data/lib/twitter/cursor.rb +7 -10
- data/lib/twitter/direct_message.rb +1 -1
- data/lib/twitter/entity/uri.rb +2 -2
- data/lib/twitter/enumerable.rb +1 -2
- data/lib/twitter/error.rb +4 -6
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +1 -1
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/factory.rb +2 -6
- data/lib/twitter/geo.rb +1 -1
- data/lib/twitter/geo/point.rb +3 -5
- data/lib/twitter/geo_factory.rb +1 -5
- data/lib/twitter/geo_results.rb +5 -8
- data/lib/twitter/identity.rb +1 -2
- data/lib/twitter/list.rb +4 -5
- data/lib/twitter/media/photo.rb +1 -2
- data/lib/twitter/media_factory.rb +1 -5
- data/lib/twitter/null_object.rb +4 -6
- data/lib/twitter/oembed.rb +1 -1
- data/lib/twitter/place.rb +4 -5
- data/lib/twitter/profile_banner.rb +1 -3
- data/lib/twitter/rate_limit.rb +1 -3
- data/lib/twitter/relationship.rb +1 -2
- data/lib/twitter/rest/api/direct_messages.rb +13 -14
- data/lib/twitter/rest/api/favorites.rb +10 -11
- data/lib/twitter/rest/api/friends_and_followers.rb +36 -36
- data/lib/twitter/rest/api/help.rb +8 -9
- data/lib/twitter/rest/api/lists.rb +62 -63
- data/lib/twitter/rest/api/oauth.rb +3 -4
- data/lib/twitter/rest/api/places_and_geo.rb +9 -10
- data/lib/twitter/rest/api/saved_searches.rb +5 -6
- data/lib/twitter/rest/api/search.rb +2 -3
- data/lib/twitter/rest/api/spam_reporting.rb +1 -2
- data/lib/twitter/rest/api/suggested_users.rb +4 -5
- data/lib/twitter/rest/api/timelines.rb +17 -18
- data/lib/twitter/rest/api/trends.rb +10 -11
- data/lib/twitter/rest/api/tweets.rb +15 -16
- data/lib/twitter/rest/api/undocumented.rb +6 -7
- data/lib/twitter/rest/api/users.rb +51 -52
- data/lib/twitter/rest/api/utils.rb +23 -30
- data/lib/twitter/rest/client.rb +8 -9
- data/lib/twitter/rest/request/multipart_with_file.rb +0 -1
- data/lib/twitter/rest/response/parse_error_json.rb +0 -2
- data/lib/twitter/rest/response/parse_json.rb +0 -2
- data/lib/twitter/rest/response/raise_error.rb +1 -3
- data/lib/twitter/search_results.rb +12 -15
- data/lib/twitter/settings.rb +2 -2
- data/lib/twitter/size.rb +2 -2
- data/lib/twitter/source_user.rb +1 -1
- data/lib/twitter/streaming/client.rb +71 -18
- data/lib/twitter/streaming/connection.rb +1 -3
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +8 -8
- data/lib/twitter/streaming/friend_list.rb +2 -9
- data/lib/twitter/streaming/message_parser.rb +13 -7
- data/lib/twitter/streaming/response.rb +0 -2
- data/lib/twitter/streaming/stall_warning.rb +7 -0
- data/lib/twitter/suggestion.rb +0 -1
- data/lib/twitter/token.rb +2 -3
- data/lib/twitter/trend_results.rb +5 -8
- data/lib/twitter/tweet.rb +16 -24
- data/lib/twitter/user.rb +30 -32
- data/lib/twitter/version.rb +2 -5
- data/spec/fixtures/track_streaming_user.json +2 -1
- data/spec/helper.rb +6 -2
- data/spec/twitter/base_spec.rb +9 -9
- data/spec/twitter/basic_user_spec.rb +6 -6
- data/spec/twitter/configuration_spec.rb +4 -4
- data/spec/twitter/cursor_spec.rb +27 -27
- data/spec/twitter/direct_message_spec.rb +36 -36
- data/spec/twitter/entity/uri_spec.rb +27 -27
- data/spec/twitter/error_spec.rb +21 -21
- data/spec/twitter/geo/point_spec.rb +9 -9
- data/spec/twitter/geo/polygon_spec.rb +5 -5
- data/spec/twitter/geo_factory_spec.rb +7 -7
- data/spec/twitter/geo_results_spec.rb +11 -11
- data/spec/twitter/geo_spec.rb +5 -5
- data/spec/twitter/identifiable_spec.rb +9 -9
- data/spec/twitter/list_spec.rb +38 -38
- data/spec/twitter/media/photo_spec.rb +54 -54
- data/spec/twitter/media_factory_spec.rb +5 -5
- data/spec/twitter/null_object_spec.rb +6 -6
- data/spec/twitter/oembed_spec.rb +65 -65
- data/spec/twitter/place_spec.rb +89 -60
- data/spec/twitter/profile_banner_spec.rb +3 -3
- data/spec/twitter/rate_limit_spec.rb +18 -18
- data/spec/twitter/relationship_spec.rb +16 -16
- data/spec/twitter/rest/api/direct_messages_spec.rb +61 -61
- data/spec/twitter/rest/api/favorites_spec.rb +93 -93
- data/spec/twitter/rest/api/friends_and_followers_spec.rb +349 -349
- data/spec/twitter/rest/api/geo_spec.rb +33 -33
- data/spec/twitter/rest/api/help_spec.rb +24 -24
- data/spec/twitter/rest/api/lists_spec.rb +487 -487
- data/spec/twitter/rest/api/oauth_spec.rb +30 -30
- data/spec/twitter/rest/api/saved_searches_spec.rb +40 -40
- data/spec/twitter/rest/api/search_spec.rb +16 -16
- data/spec/twitter/rest/api/spam_reporting_spec.rb +9 -9
- data/spec/twitter/rest/api/suggested_users_spec.rb +23 -23
- data/spec/twitter/rest/api/timelines_spec.rb +58 -58
- data/spec/twitter/rest/api/trends_spec.rb +26 -26
- data/spec/twitter/rest/api/tweets_spec.rb +284 -284
- data/spec/twitter/rest/api/undocumented_spec.rb +51 -51
- data/spec/twitter/rest/api/users_spec.rb +360 -360
- data/spec/twitter/rest/client_spec.rb +99 -103
- data/spec/twitter/saved_search_spec.rb +16 -16
- data/spec/twitter/search_results_spec.rb +44 -44
- data/spec/twitter/settings_spec.rb +8 -8
- data/spec/twitter/size_spec.rb +5 -5
- data/spec/twitter/source_user_spec.rb +6 -6
- data/spec/twitter/streaming/client_spec.rb +53 -49
- data/spec/twitter/streaming/deleted_tweet_spec.rb +23 -0
- data/spec/twitter/streaming/event_spec.rb +20 -22
- data/spec/twitter/streaming/friend_list_spec.rb +11 -0
- data/spec/twitter/streaming/message_parser_spec.rb +54 -0
- data/spec/twitter/suggestion_spec.rb +11 -11
- data/spec/twitter/target_user_spec.rb +6 -6
- data/spec/twitter/token_spec.rb +4 -4
- data/spec/twitter/trend_results_spec.rb +30 -30
- data/spec/twitter/trend_spec.rb +20 -20
- data/spec/twitter/tweet_spec.rb +170 -173
- data/spec/twitter/user_spec.rb +179 -179
- data/twitter.gemspec +2 -2
- metadata +21 -4
- metadata.gz.sig +2 -1
@@ -3,191 +3,187 @@ require 'helper'
|
|
3
3
|
describe Twitter::REST::Client do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@client = Twitter::REST::Client.new(:consumer_key =>
|
6
|
+
@client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
10
|
-
context
|
11
|
-
it
|
12
|
-
expect {
|
13
|
-
Twitter::REST::Client.new(:consumer_key => [12345, 54321])
|
14
|
-
}.to raise_exception(Twitter::Error::ConfigurationError)
|
9
|
+
describe '.new' do
|
10
|
+
context 'when invalid credentials are provided' do
|
11
|
+
it 'raises a ConfigurationError exception' do
|
12
|
+
expect { Twitter::REST::Client.new(:consumer_key => [12_345, 54_321]) }.to raise_exception(Twitter::Error::ConfigurationError)
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
context
|
19
|
-
it
|
20
|
-
expect {
|
21
|
-
Twitter::REST::Client.new
|
22
|
-
}.not_to raise_error
|
16
|
+
context 'when no credentials are provided' do
|
17
|
+
it 'does not raise an exception' do
|
18
|
+
expect { Twitter::REST::Client.new }.not_to raise_error
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
|
-
describe
|
28
|
-
it
|
29
|
-
client = Twitter::REST::Client.new(:bearer_token =>
|
23
|
+
describe '.credentials?' do
|
24
|
+
it 'returns true if only bearer_token is supplied' do
|
25
|
+
client = Twitter::REST::Client.new(:bearer_token => 'BT')
|
30
26
|
expect(client.credentials?).to be true
|
31
27
|
end
|
32
|
-
it
|
33
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
28
|
+
it 'returns true if all OAuth credentials are present' do
|
29
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
|
34
30
|
expect(client.credentials?).to be true
|
35
31
|
end
|
36
|
-
it
|
37
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
32
|
+
it 'returns false if any credentials are missing' do
|
33
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT')
|
38
34
|
expect(client.credentials?).to be false
|
39
35
|
end
|
40
36
|
end
|
41
37
|
|
42
|
-
it
|
43
|
-
stub_get(
|
44
|
-
user1 = Twitter::REST::Client.new(:consumer_key =>
|
45
|
-
stub_get(
|
46
|
-
user2 = Twitter::REST::Client.new(:consumer_key =>
|
38
|
+
it 'does not cache the screen name across clients' do
|
39
|
+
stub_get('/1.1/account/verify_credentials.json').to_return(:body => fixture('sferik.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
40
|
+
user1 = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS').current_user
|
41
|
+
stub_get('/1.1/account/verify_credentials.json').to_return(:body => fixture('pengwynn.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
42
|
+
user2 = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS').current_user
|
47
43
|
expect(user1).not_to eq(user2)
|
48
44
|
end
|
49
45
|
|
50
|
-
describe
|
46
|
+
describe '#delete' do
|
51
47
|
before do
|
52
|
-
stub_delete(
|
48
|
+
stub_delete('/custom/delete').with(:query => {:deleted => 'object'})
|
53
49
|
end
|
54
|
-
it
|
55
|
-
@client.delete(
|
56
|
-
expect(a_delete(
|
50
|
+
it 'allows custom delete requests' do
|
51
|
+
@client.delete('/custom/delete', :deleted => 'object')
|
52
|
+
expect(a_delete('/custom/delete').with(:query => {:deleted => 'object'})).to have_been_made
|
57
53
|
end
|
58
54
|
end
|
59
55
|
|
60
|
-
describe
|
56
|
+
describe '#put' do
|
61
57
|
before do
|
62
|
-
stub_put(
|
58
|
+
stub_put('/custom/put').with(:body => {:updated => 'object'})
|
63
59
|
end
|
64
|
-
it
|
65
|
-
@client.put(
|
66
|
-
expect(a_put(
|
60
|
+
it 'allows custom put requests' do
|
61
|
+
@client.put('/custom/put', :updated => 'object')
|
62
|
+
expect(a_put('/custom/put').with(:body => {:updated => 'object'})).to have_been_made
|
67
63
|
end
|
68
64
|
end
|
69
65
|
|
70
|
-
describe
|
71
|
-
it
|
72
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
66
|
+
describe '#user_token?' do
|
67
|
+
it 'returns true if the user token/secret are present' do
|
68
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
|
73
69
|
expect(client.user_token?).to be true
|
74
70
|
end
|
75
|
-
it
|
76
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
71
|
+
it 'returns false if the user token/secret are not completely present' do
|
72
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT')
|
77
73
|
expect(client.user_token?).to be false
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
81
|
-
describe
|
82
|
-
it
|
83
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
77
|
+
describe '#bearer_token?' do
|
78
|
+
it 'returns true if the app token is present' do
|
79
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :bearer_token => 'BT')
|
84
80
|
expect(client.bearer_token?).to be true
|
85
81
|
end
|
86
|
-
it
|
87
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
82
|
+
it 'returns false if the bearer_token is not present' do
|
83
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
|
88
84
|
expect(client.bearer_token?).to be false
|
89
85
|
end
|
90
86
|
end
|
91
87
|
|
92
|
-
describe
|
93
|
-
it
|
94
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
88
|
+
describe '#credentials?' do
|
89
|
+
it 'returns true if all credentials are present' do
|
90
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
|
95
91
|
expect(client.credentials?).to be true
|
96
92
|
end
|
97
|
-
it
|
98
|
-
client = Twitter::REST::Client.new(:consumer_key =>
|
93
|
+
it 'returns false if any credentials are missing' do
|
94
|
+
client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT')
|
99
95
|
expect(client.credentials?).to be false
|
100
96
|
end
|
101
97
|
end
|
102
98
|
|
103
|
-
describe
|
104
|
-
it
|
99
|
+
describe '#connection' do
|
100
|
+
it 'looks like Faraday connection' do
|
105
101
|
expect(@client.send(:connection)).to respond_to(:run_request)
|
106
102
|
end
|
107
|
-
it
|
103
|
+
it 'memoizes the connection' do
|
108
104
|
c1, c2 = @client.send(:connection), @client.send(:connection)
|
109
105
|
expect(c1.object_id).to eq(c2.object_id)
|
110
106
|
end
|
111
107
|
end
|
112
108
|
|
113
|
-
describe
|
114
|
-
it
|
115
|
-
stub_post(
|
116
|
-
@client.update(
|
117
|
-
expect(a_post(
|
109
|
+
describe '#request' do
|
110
|
+
it 'encodes the entire body when no uploaded media is present' do
|
111
|
+
stub_post('/1.1/statuses/update.json').with(:body => {:status => 'Update'}).to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
112
|
+
@client.update('Update')
|
113
|
+
expect(a_post('/1.1/statuses/update.json').with(:body => {:status => 'Update'})).to have_been_made
|
118
114
|
end
|
119
|
-
it
|
120
|
-
stub_post(
|
121
|
-
@client.update_with_media(
|
122
|
-
expect(a_post(
|
115
|
+
it 'encodes none of the body when uploaded media is present' do
|
116
|
+
stub_post('/1.1/statuses/update_with_media.json').to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
117
|
+
@client.update_with_media('Update', fixture('pbjt.gif'))
|
118
|
+
expect(a_post('/1.1/statuses/update_with_media.json')).to have_been_made
|
123
119
|
end
|
124
|
-
it
|
125
|
-
allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new(
|
126
|
-
expect{@client.send(:request, :get,
|
120
|
+
it 'catches Faraday errors' do
|
121
|
+
allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new('Oops'))
|
122
|
+
expect { @client.send(:request, :get, '/path') }.to raise_error Twitter::Error
|
127
123
|
end
|
128
|
-
it
|
129
|
-
allow(@client).to receive(:connection).and_raise(JSON::ParserError.new(
|
130
|
-
expect{@client.send(:request, :get,
|
124
|
+
it 'catches JSON::ParserError errors' do
|
125
|
+
allow(@client).to receive(:connection).and_raise(JSON::ParserError.new('unexpected token'))
|
126
|
+
expect { @client.send(:request, :get, '/path') }.to raise_error Twitter::Error
|
131
127
|
end
|
132
128
|
end
|
133
129
|
|
134
|
-
describe
|
135
|
-
it
|
136
|
-
uri = Twitter::REST::Client::ENDPOINT +
|
130
|
+
describe '#oauth_auth_header' do
|
131
|
+
it 'creates the correct auth headers' do
|
132
|
+
uri = Twitter::REST::Client::ENDPOINT + '/1.1/direct_messages.json'
|
137
133
|
authorization = @client.send(:oauth_auth_header, :get, uri)
|
138
|
-
expect(authorization.options[:signature_method]).to eq(
|
139
|
-
expect(authorization.options[:version]).to eq(
|
140
|
-
expect(authorization.options[:consumer_key]).to eq(
|
141
|
-
expect(authorization.options[:consumer_secret]).to eq(
|
142
|
-
expect(authorization.options[:token]).to eq(
|
143
|
-
expect(authorization.options[:token_secret]).to eq(
|
144
|
-
end
|
145
|
-
it
|
134
|
+
expect(authorization.options[:signature_method]).to eq('HMAC-SHA1')
|
135
|
+
expect(authorization.options[:version]).to eq('1.0')
|
136
|
+
expect(authorization.options[:consumer_key]).to eq('CK')
|
137
|
+
expect(authorization.options[:consumer_secret]).to eq('CS')
|
138
|
+
expect(authorization.options[:token]).to eq('AT')
|
139
|
+
expect(authorization.options[:token_secret]).to eq('AS')
|
140
|
+
end
|
141
|
+
it 'submits the correct auth header when no media is present' do
|
146
142
|
# We use static values for nounce and timestamp to get a stable signature
|
147
|
-
secret = {:consumer_key =>
|
148
|
-
:token =>
|
149
|
-
:nonce =>
|
150
|
-
header = {
|
143
|
+
secret = {:consumer_key => 'CK', :consumer_secret => 'CS',
|
144
|
+
:token => 'OT', :token_secret => 'OS',
|
145
|
+
:nonce => 'b6ebe4c2a11af493f8a2290fe1296965', :timestamp => '1370968658'}
|
146
|
+
header = {'Authorization' => /oauth_signature="FbthwmgGq02iQw%2FuXGEWaL6V6eM%3D"/}
|
151
147
|
|
152
148
|
allow(@client).to receive(:credentials).and_return(secret)
|
153
|
-
stub_post(
|
154
|
-
@client.update(
|
155
|
-
expect(a_post(
|
149
|
+
stub_post('/1.1/statuses/update.json').with(:body => {:status => 'Just a test'}).to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
150
|
+
@client.update('Just a test')
|
151
|
+
expect(a_post('/1.1/statuses/update.json').
|
156
152
|
with(:headers => header)).to have_been_made
|
157
153
|
end
|
158
|
-
it
|
154
|
+
it 'submits the correct auth header when media is present' do
|
159
155
|
# We use static values for nounce and timestamp to get a stable signature
|
160
|
-
secret = {:consumer_key =>
|
161
|
-
:token =>
|
162
|
-
:nonce =>
|
163
|
-
header = {
|
156
|
+
secret = {:consumer_key => 'CK', :consumer_secret => 'CS',
|
157
|
+
:token => 'OT', :token_secret => 'OS',
|
158
|
+
:nonce => 'e08201ad0dab4897c99445056feefd95', :timestamp => '1370967652'}
|
159
|
+
header = {'Authorization' => /oauth_signature="9ziouUPwZT9IWWRbJL8r0BerKYA%3D"/}
|
164
160
|
|
165
161
|
allow(@client).to receive(:credentials).and_return(secret)
|
166
|
-
stub_post(
|
167
|
-
@client.update_with_media(
|
168
|
-
expect(a_post(
|
162
|
+
stub_post('/1.1/statuses/update_with_media.json').to_return(:body => fixture('status.json'), :headers => header)
|
163
|
+
@client.update_with_media('Just a test', fixture('pbjt.gif'))
|
164
|
+
expect(a_post('/1.1/statuses/update_with_media.json').
|
169
165
|
with(:headers => header)).to have_been_made
|
170
166
|
end
|
171
167
|
end
|
172
168
|
|
173
|
-
describe
|
174
|
-
it
|
175
|
-
client = Twitter::REST::Client.new(:bearer_token =>
|
169
|
+
describe '#bearer_auth_header' do
|
170
|
+
it 'creates the correct auth headers with supplied bearer_token' do
|
171
|
+
client = Twitter::REST::Client.new(:bearer_token => 'BT')
|
176
172
|
authorization = client.send(:bearer_auth_header)
|
177
|
-
expect(authorization).to eq(
|
173
|
+
expect(authorization).to eq('Bearer BT')
|
178
174
|
end
|
179
|
-
it
|
180
|
-
token = Twitter::Token.new(:token_type =>
|
175
|
+
it 'creates the correct auth headers with supplied bearer token' do
|
176
|
+
token = Twitter::Token.new(:token_type => 'bearer', :access_token => 'BT')
|
181
177
|
client = Twitter::REST::Client.new(:bearer_token => token)
|
182
178
|
authorization = client.send(:bearer_auth_header)
|
183
|
-
expect(authorization).to eq(
|
179
|
+
expect(authorization).to eq('Bearer BT')
|
184
180
|
end
|
185
181
|
end
|
186
182
|
|
187
|
-
describe
|
188
|
-
it
|
183
|
+
describe '#bearer_token_credentials_auth_header' do
|
184
|
+
it 'creates the correct auth header with supplied consumer_key and consumer_secret' do
|
189
185
|
authorization = @client.send(:bearer_token_credentials_auth_header)
|
190
|
-
expect(authorization).to eq(
|
186
|
+
expect(authorization).to eq('Basic Q0s6Q1M=')
|
191
187
|
end
|
192
188
|
end
|
193
189
|
end
|
@@ -2,42 +2,42 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe Twitter::SavedSearch do
|
4
4
|
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
saved_search = Twitter::SavedSearch.new(:id => 1, :name =>
|
8
|
-
other = Twitter::SavedSearch.new(:id => 1, :name =>
|
5
|
+
describe '#==' do
|
6
|
+
it 'returns true when objects IDs are the same' do
|
7
|
+
saved_search = Twitter::SavedSearch.new(:id => 1, :name => 'foo')
|
8
|
+
other = Twitter::SavedSearch.new(:id => 1, :name => 'bar')
|
9
9
|
expect(saved_search == other).to be true
|
10
10
|
end
|
11
|
-
it
|
11
|
+
it 'returns false when objects IDs are different' do
|
12
12
|
saved_search = Twitter::SavedSearch.new(:id => 1)
|
13
13
|
other = Twitter::SavedSearch.new(:id => 2)
|
14
14
|
expect(saved_search == other).to be false
|
15
15
|
end
|
16
|
-
it
|
16
|
+
it 'returns false when classes are different' do
|
17
17
|
saved_search = Twitter::SavedSearch.new(:id => 1)
|
18
18
|
other = Twitter::Identity.new(:id => 1)
|
19
19
|
expect(saved_search == other).to be false
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
it
|
25
|
-
saved_search = Twitter::SavedSearch.new(:id =>
|
23
|
+
describe '#created_at' do
|
24
|
+
it 'returns a Time when created_at is set' do
|
25
|
+
saved_search = Twitter::SavedSearch.new(:id => 16_129_012, :created_at => 'Mon Jul 16 12:59:01 +0000 2007')
|
26
26
|
expect(saved_search.created_at).to be_a Time
|
27
27
|
end
|
28
|
-
it
|
29
|
-
saved_search = Twitter::SavedSearch.new(:id =>
|
28
|
+
it 'returns nil when created_at is not set' do
|
29
|
+
saved_search = Twitter::SavedSearch.new(:id => 16_129_012)
|
30
30
|
expect(saved_search.created_at).to be_nil
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
it
|
36
|
-
saved_search = Twitter::SavedSearch.new(:id =>
|
34
|
+
describe '#created?' do
|
35
|
+
it 'returns true when created_at is set' do
|
36
|
+
saved_search = Twitter::SavedSearch.new(:id => 16_129_012, :created_at => 'Mon Jul 16 12:59:01 +0000 2007')
|
37
37
|
expect(saved_search.created?).to be true
|
38
38
|
end
|
39
|
-
it
|
40
|
-
saved_search = Twitter::SavedSearch.new(:id =>
|
39
|
+
it 'returns false when created_at is not set' do
|
40
|
+
saved_search = Twitter::SavedSearch.new(:id => 16_129_012)
|
41
41
|
expect(saved_search.created?).to be false
|
42
42
|
end
|
43
43
|
end
|
@@ -2,124 +2,124 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe Twitter::SearchResults do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe '#each' do
|
6
6
|
before do
|
7
7
|
@search_results = Twitter::SearchResults.new(:statuses => [{:id => 1}, {:id => 2}, {:id => 3}, {:id => 4}, {:id => 5}, {:id => 6}])
|
8
8
|
end
|
9
|
-
it
|
9
|
+
it 'iterates' do
|
10
10
|
count = 0
|
11
|
-
@search_results.each{count += 1}
|
11
|
+
@search_results.each { count += 1 }
|
12
12
|
expect(count).to eq(6)
|
13
13
|
end
|
14
|
-
context
|
15
|
-
it
|
14
|
+
context 'with start' do
|
15
|
+
it 'iterates' do
|
16
16
|
count = 0
|
17
|
-
@search_results.each(5){count += 1}
|
17
|
+
@search_results.each(5) { count += 1 }
|
18
18
|
expect(count).to eq(1)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
it
|
23
|
+
describe '#completed_in' do
|
24
|
+
it 'returns a number of seconds' do
|
25
25
|
completed_in = Twitter::SearchResults.new(:search_metadata => {:completed_in => 0.029}).completed_in
|
26
26
|
expect(completed_in).to be_a Float
|
27
27
|
expect(completed_in).to eq(0.029)
|
28
28
|
end
|
29
|
-
it
|
29
|
+
it 'is nil when not set' do
|
30
30
|
completed_in = Twitter::SearchResults.new.completed_in
|
31
31
|
expect(completed_in).to be_nil
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
36
|
-
it
|
37
|
-
max_id = Twitter::SearchResults.new(:search_metadata => {:max_id =>
|
35
|
+
describe '#max_id' do
|
36
|
+
it 'returns an ID' do
|
37
|
+
max_id = Twitter::SearchResults.new(:search_metadata => {:max_id => 250_126_199_840_518_145}).max_id
|
38
38
|
expect(max_id).to be_an Integer
|
39
|
-
expect(max_id).to eq(
|
39
|
+
expect(max_id).to eq(250_126_199_840_518_145)
|
40
40
|
end
|
41
|
-
it
|
41
|
+
it 'is nil when not set' do
|
42
42
|
max_id = Twitter::SearchResults.new.max_id
|
43
43
|
expect(max_id).to be_nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe
|
48
|
-
it
|
47
|
+
describe '#page' do
|
48
|
+
it 'returns page number' do
|
49
49
|
page = Twitter::SearchResults.new(:search_metadata => {:page => 1}).page
|
50
50
|
expect(page).to be_an Integer
|
51
51
|
expect(page).to eq(1)
|
52
52
|
end
|
53
|
-
it
|
53
|
+
it 'is nil when not set' do
|
54
54
|
page = Twitter::SearchResults.new.page
|
55
55
|
expect(page).to be_nil
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
60
|
-
it
|
61
|
-
query = Twitter::SearchResults.new(:search_metadata => {:query =>
|
59
|
+
describe '#query' do
|
60
|
+
it 'returns the query' do
|
61
|
+
query = Twitter::SearchResults.new(:search_metadata => {:query => '%23freebandnames'}).query
|
62
62
|
expect(query).to be_a String
|
63
|
-
expect(query).to eq(
|
63
|
+
expect(query).to eq('%23freebandnames')
|
64
64
|
end
|
65
|
-
it
|
65
|
+
it 'is nil when not set' do
|
66
66
|
query = Twitter::SearchResults.new.query
|
67
67
|
expect(query).to be_nil
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
72
|
-
it
|
71
|
+
describe '#results_per_page' do
|
72
|
+
it 'returns the number of results per page' do
|
73
73
|
results_per_page = Twitter::SearchResults.new(:search_metadata => {:count => 4}).results_per_page
|
74
74
|
expect(results_per_page).to be_an Integer
|
75
75
|
expect(results_per_page).to eq(4)
|
76
76
|
end
|
77
|
-
it
|
77
|
+
it 'is nil when not set' do
|
78
78
|
results_per_page = Twitter::SearchResults.new.results_per_page
|
79
79
|
expect(results_per_page).to be_nil
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
describe
|
84
|
-
it
|
85
|
-
since_id = Twitter::SearchResults.new(:search_metadata => {:since_id =>
|
83
|
+
describe '#since_id' do
|
84
|
+
it 'returns an ID' do
|
85
|
+
since_id = Twitter::SearchResults.new(:search_metadata => {:since_id => 250_126_199_840_518_145}).since_id
|
86
86
|
expect(since_id).to be_an Integer
|
87
|
-
expect(since_id).to eq(
|
87
|
+
expect(since_id).to eq(250_126_199_840_518_145)
|
88
88
|
end
|
89
|
-
it
|
89
|
+
it 'is nil when not set' do
|
90
90
|
since_id = Twitter::SearchResults.new.since_id
|
91
91
|
expect(since_id).to be_nil
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
describe
|
96
|
-
it
|
97
|
-
next_results = Twitter::SearchResults.new(:search_metadata => {:next_results =>
|
95
|
+
describe '#next_results?' do
|
96
|
+
it 'returns true when next_results is set' do
|
97
|
+
next_results = Twitter::SearchResults.new(:search_metadata => {:next_results => '?'}).next_results?
|
98
98
|
expect(next_results).to be true
|
99
99
|
end
|
100
|
-
it
|
100
|
+
it 'returns false when next_results is not set' do
|
101
101
|
next_results = Twitter::SearchResults.new(:search_metadata => {}).next_results?
|
102
102
|
expect(next_results).to be false
|
103
103
|
end
|
104
|
-
it
|
105
|
-
next_results = Twitter::SearchResults.new
|
104
|
+
it 'returns false is search_metadata is not set' do
|
105
|
+
next_results = Twitter::SearchResults.new.next_results?
|
106
106
|
expect(next_results).to be false
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
describe
|
111
|
-
it
|
112
|
-
search_results = Twitter::SearchResults.new(:search_metadata => {:next_results =>
|
110
|
+
describe '#next_results' do
|
111
|
+
it 'returns a hash of query parameters' do
|
112
|
+
search_results = Twitter::SearchResults.new(:search_metadata => {:next_results => '?max_id=249279667666817023&q=%23freebandnames&count=4&include_entities=1&result_type=mixed'})
|
113
113
|
expect(search_results.next_results).to be_a Hash
|
114
|
-
expect(search_results.next_results[:max_id]).to eq(
|
114
|
+
expect(search_results.next_results[:max_id]).to eq('249279667666817023')
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
describe
|
119
|
-
it
|
120
|
-
search_results = Twitter::SearchResults.new(:search_metadata => {:refresh_url =>
|
118
|
+
describe '#refresh_results' do
|
119
|
+
it 'returns a hash of query parameters' do
|
120
|
+
search_results = Twitter::SearchResults.new(:search_metadata => {:refresh_url => '?since_id=249279667666817023&q=%23freebandnames&count=4&include_entities=1&result_type=recent'})
|
121
121
|
expect(search_results.refresh_results).to be_a Hash
|
122
|
-
expect(search_results.refresh_results[:since_id]).to eq(
|
122
|
+
expect(search_results.refresh_results[:since_id]).to eq('249279667666817023')
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|