|
18 | 18 | let(:rash) { subject.user_info } |
19 | 19 |
|
20 | 20 | before(:each) do |
21 | | - stub_request(:get, 'https://api.bufferapp.com/1/user.json'). |
22 | | - with(query: { 'access_token' => 'some_token'}). |
23 | | - to_return(fixture('user_authenticated.txt')) |
| 21 | + url = "#{ base_path }/user.json" |
| 22 | + stub_with_to_return(:get, url, "user_authenticated.txt") |
24 | 23 | end |
25 | 24 |
|
26 | 25 | it "returns a Rash object" do |
|
36 | 35 | let(:rash) { Buff::Client.new("some_token").profiles } |
37 | 36 |
|
38 | 37 | before(:each) do |
39 | | - stub_request(:get, 'https://api.bufferapp.com/1/profiles.json'). |
40 | | - with(query: { 'access_token' => 'some_token'}). |
41 | | - to_return(fixture('profile_authenticated.txt')) |
| 38 | + url = "#{ base_path }/profiles.json" |
| 39 | + stub_with_to_return(:get, url, 'profile_authenticated.txt') |
42 | 40 | end |
43 | 41 |
|
44 | 42 | it "makes the correct url request" do |
|
57 | 55 | describe "#profile_by_id" do |
58 | 56 | let(:id) { "5160746d54f04a5e3a00000f" } |
59 | 57 | before(:each) do |
60 | | - stub_request(:get, "https://api.bufferapp.com/1/profiles/#{id}.json"). |
61 | | - with(query: { 'access_token' => 'some_token'}). |
62 | | - to_return(fixture('profiles_by_id.txt')) |
| 58 | + url = "#{base_path}/profiles/#{id}.json" |
| 59 | + fixture_name = "profiles_by_id.txt" |
| 60 | + stub_with_to_return(:get, url, fixture_name) |
63 | 61 | end |
64 | 62 |
|
65 | 63 | let(:rash) { Buff::Client.new("some_token").profile_by_id(id) } |
|
75 | 73 |
|
76 | 74 | describe "#profile_schedules_by_id" do |
77 | 75 | before(:each) do |
78 | | - stub_request(:get, "https://api.bufferapp.com/1/profiles/#{id}/schedules.json"). |
79 | | - with(query: { 'access_token' => 'some_token'}). |
80 | | - to_return(fixture('profile_schedules_by_id.txt')) |
| 76 | + url = "#{base_path}/profiles/#{id}/schedules.json" |
| 77 | + fixture_name = 'profile_schedules_by_id.txt' |
| 78 | + stub_with_to_return(:get, url, fixture_name) |
81 | 79 | end |
82 | 80 |
|
83 | 81 | let(:rash) { Buff::Client.new("some_token").profile_schedules_by_id(id) } |
|
107 | 105 |
|
108 | 106 | describe "#info" do |
109 | 107 | before do |
110 | | - stub_request(:get, "https://api.bufferapp.com/1/info/configuration.json?access_token=some_token"). |
| 108 | + stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token"). |
111 | 109 | to_return(fixture("info.txt")) |
112 | 110 | end |
113 | 111 |
|
|
182 | 180 |
|
183 | 181 | it "dumping a double schedule yields correct json" do |
184 | 182 | schedules = Buff::Schedules.new |
185 | | - schedules << @schedule |
186 | | - schedules << @schedule |
| 183 | + schedules << @schedule << @schedule |
187 | 184 | @sample_schedules = @sample_schedules.to_json |
188 | 185 |
|
189 | 186 | schedules.dump.should eq(@sample_schedules) |
|
195 | 192 | let(:client) { Buff::Client.new("some_token") } |
196 | 193 | describe "#get" do |
197 | 194 | it "delegates to #handle_response_code when code != 200" do |
198 | | - stub_request(:get, "https://api.bufferapp.com/1/info/configuration.json?access_token=some_token"). |
| 195 | + stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token"). |
199 | 196 | to_return(:status => 403, :body => "", :headers => {}) |
200 | 197 | client.should_receive(:handle_response_code).once |
201 | 198 | client.info |
202 | 199 | end |
203 | 200 |
|
204 | 201 |
|
205 | 202 | it "does not delegate to #handle_response_code when code = 200" do |
206 | | - stub_request(:get, "https://api.bufferapp.com/1/info/configuration.json?access_token=some_token"). |
| 203 | + stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token"). |
207 | 204 | to_return(fixture("link.txt")) |
208 | 205 | client.should_not_receive(:handle_response_code) |
209 | 206 | client.info |
|
214 | 211 |
|
215 | 212 | it "connects to the correct endpoint" do |
216 | 213 |
|
217 | | -#TODO improve test |
| 214 | + #TODO improve test |
218 | 215 | response = %Q[{"success": true, "message": "Schedule saved successfully"}] |
219 | 216 | id = "4eb854340acb04e870000010" |
220 | 217 | stub_request(:post, %r{https://api\.bufferapp\.com/1/profiles/4eb854340acb04e870000010/schedules/update\.json\?access_token=.*}). |
|
226 | 223 | end |
227 | 224 |
|
228 | 225 | xit "does not delegate to #handle_response_code when code = 200" do |
229 | | - stub_request(:get, "https://api.bufferapp.com/1/info/configuration.json?access_token=some_token"). |
230 | | - to_return(fixture("link.txt")) |
| 226 | + url = "#{base_path}/info/configuration.json" |
| 227 | + fixture_name = "link.txt" |
| 228 | + stub_with_to_return(:get, url, fixture_name) |
231 | 229 | client.should_not_receive(:handle_response_code) |
232 | 230 | client.info |
233 | 231 | end |
|
243 | 241 | context "fails gracefully with undocumented responses" do |
244 | 242 | it "responds to 401 unauthorized response" do |
245 | 243 | id = "4eb8565e0acb04bb82000004" |
246 | | - stub_request(:get, "https://api.bufferapp.com/1/updates/#{id}.json?access_token=some_token"). |
247 | | - to_return(fixture("update_by_id_non_auth.txt")) |
248 | | - |
| 244 | + url = "#{base_path}/updates/#{id}.json?access_token=some_token" |
| 245 | + stub_with_to_return(:get, url, "update_by_id_non_auth.txt") |
249 | 246 | lambda { client.update_by_id(id) }. |
250 | 247 | should raise_error(Buff::APIError) |
251 | 248 | end |
|
0 commit comments