1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
require 'helper'
describe Twitter::REST::Favorites do
before do
@client = Twitter::REST::Client.new(consumer_key: 'CK', consumer_secret: 'CS', access_token: 'AT', access_token_secret: 'AS')
end
describe '#favorites' do
context 'with a screen name passed' do
before do
stub_get('/1.1/favorites/list.json').with(query: {screen_name: 'sferik'}).to_return(body: fixture('user_timeline.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.favorites('sferik')
expect(a_get('/1.1/favorites/list.json').with(query: {screen_name: 'sferik'})).to have_been_made
end
it 'returns the 20 most recent favorite Tweets for the authenticating user or user specified by the ID parameter' do
favorites = @client.favorites('sferik')
expect(favorites).to be_an Array
expect(favorites.first).to be_a Twitter::Tweet
expect(favorites.first.user.id).to eq(7_505_382)
end
context 'with a URI object passed' do
it 'requests the correct resource' do
user = URI.parse('https://twitter.com/sferik')
@client.favorites(user)
expect(a_get('/1.1/favorites/list.json').with(query: {screen_name: 'sferik'})).to have_been_made
end
end
end
context 'without arguments passed' do
before do
stub_get('/1.1/favorites/list.json').to_return(body: fixture('user_timeline.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.favorites
expect(a_get('/1.1/favorites/list.json')).to have_been_made
end
it 'returns the 20 most recent favorite Tweets for the authenticating user or user specified by the ID parameter' do
favorites = @client.favorites
expect(favorites).to be_an Array
expect(favorites.first).to be_a Twitter::Tweet
expect(favorites.first.user.id).to eq(7_505_382)
end
end
end
describe '#unfavorite' do
before do
stub_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'}).to_return(body: fixture('status.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.unfavorite(540_897_316_908_331_009)
expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'})).to have_been_made
end
it 'returns an array of un-favorited Tweets' do
tweets = @client.unfavorite(540_897_316_908_331_009)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
expect(tweets.first.text).to eq('Powerful cartoon by @BillBramhall: http://t.co/IOEbc5QoES')
end
context 'not found' do
before do
stub_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'}).to_return(status: 404, body: fixture('not_found.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'does not raise an error' do
expect { @client.unfavorite(540_897_316_908_331_009) }.not_to raise_error
end
end
context 'with a URI object passed' do
it 'requests the correct resource' do
tweet = URI.parse('https://twitter.com/sferik/status/540897316908331009')
@client.unfavorite(tweet)
expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
context 'with a Tweet passed' do
it 'requests the correct resource' do
tweet = Twitter::Tweet.new(id: 540_897_316_908_331_009)
@client.unfavorite(tweet)
expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
end
describe '#unfavorite!' do
before do
stub_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'}).to_return(body: fixture('status.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.unfavorite!(540_897_316_908_331_009)
expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'})).to have_been_made
end
it 'returns an array of un-favorited Tweets' do
tweets = @client.unfavorite!(540_897_316_908_331_009)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
expect(tweets.first.text).to eq('Powerful cartoon by @BillBramhall: http://t.co/IOEbc5QoES')
end
context 'does not exist' do
before do
stub_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'}).to_return(status: 404, body: fixture('not_found.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'raises a NotFound error' do
expect { @client.unfavorite!(540_897_316_908_331_009) }.to raise_error(Twitter::Error::NotFound)
end
end
context 'with a URI object passed' do
it 'requests the correct resource' do
tweet = URI.parse('https://twitter.com/sferik/status/540897316908331009')
@client.unfavorite!(tweet)
expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
context 'with a Tweet passed' do
it 'requests the correct resource' do
tweet = Twitter::Tweet.new(id: 540_897_316_908_331_009)
@client.unfavorite!(tweet)
expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
end
describe '#favorite' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(body: fixture('status.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.favorite(540_897_316_908_331_009)
expect(a_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'})).to have_been_made
end
it 'returns an array of favorited Tweets' do
tweets = @client.favorite(540_897_316_908_331_009)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
expect(tweets.first.text).to eq('Powerful cartoon by @BillBramhall: http://t.co/IOEbc5QoES')
end
context 'already favorited' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(status: 403, body: fixture('already_favorited.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'does not raise an error' do
expect { @client.favorite(540_897_316_908_331_009) }.not_to raise_error
end
end
context 'not found' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(status: 404, body: fixture('not_found.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'does not raise an error' do
expect { @client.favorite(540_897_316_908_331_009) }.not_to raise_error
end
end
context 'with a URI object passed' do
it 'requests the correct resource' do
tweet = URI.parse('https://twitter.com/sferik/status/540897316908331009')
@client.favorite(tweet)
expect(a_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
context 'with a Tweet passed' do
it 'requests the correct resource' do
tweet = Twitter::Tweet.new(id: 540_897_316_908_331_009)
@client.favorite(tweet)
expect(a_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
end
describe '#favorite!' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(body: fixture('status.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.favorite!(540_897_316_908_331_009)
expect(a_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'})).to have_been_made
end
it 'returns an array of favorited Tweets' do
tweets = @client.favorite!(540_897_316_908_331_009)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
expect(tweets.first.text).to eq('Powerful cartoon by @BillBramhall: http://t.co/IOEbc5QoES')
end
context 'forbidden' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(status: 403, body: '{}', headers: {content_type: 'application/json; charset=utf-8'})
end
it 'raises a Forbidden error' do
expect { @client.favorite!(540_897_316_908_331_009) }.to raise_error(Twitter::Error::Forbidden)
end
end
context 'already favorited' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(status: 403, body: fixture('already_favorited.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'raises an AlreadyFavorited error' do
expect { @client.favorite!(540_897_316_908_331_009) }.to raise_error(Twitter::Error::AlreadyFavorited)
end
end
context 'does not exist' do
before do
stub_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'}).to_return(status: 404, body: fixture('not_found.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'raises a NotFound error' do
expect { @client.favorite!(540_897_316_908_331_009) }.to raise_error(Twitter::Error::NotFound)
end
end
context 'with a URI object passed' do
it 'requests the correct resource' do
tweet = URI.parse('https://twitter.com/sferik/status/540897316908331009')
@client.favorite!(tweet)
expect(a_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
context 'with a Tweet passed' do
it 'requests the correct resource' do
tweet = Twitter::Tweet.new(id: 540_897_316_908_331_009)
@client.favorite!(tweet)
expect(a_post('/1.1/favorites/create.json').with(body: {id: '540897316908331009'})).to have_been_made
end
end
end
end
|