From 0dd5447e63b88eed8a99d6e1bbb80877c5a9287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Mon, 7 Sep 2015 13:31:45 +0200 Subject: [PATCH] Fix tumblr service deletion spec to actually test deletion --- spec/models/services/tumblr_spec.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/spec/models/services/tumblr_spec.rb b/spec/models/services/tumblr_spec.rb index c10d62cf3..ea0c7e756 100644 --- a/spec/models/services/tumblr_spec.rb +++ b/spec/models/services/tumblr_spec.rb @@ -4,9 +4,9 @@ describe Services::Tumblr, type: :model do let(:user) { alice } let(:post) { user.post(:status_message, text: "hello", to: user.aspects.first.id) } let(:service) { Services::Tumblr.new(access_token: "yeah", access_secret: "foobar") } + let(:post_id) { "bla" } describe "#post" do - let(:post_id) { "bla" } let(:post_request) { {body: service.build_tumblr_post(post, "")} } let(:post_response) { {status: 201, body: {response: {id: post_id}}.to_json} } @@ -24,12 +24,14 @@ describe Services::Tumblr, type: :model do } it "posts a status message to the primary blog and stores the id" do - stub_request(:post, "http://api.tumblr.com/v2/blog/bar.tumblr.com/post") + stub = stub_request(:post, "http://api.tumblr.com/v2/blog/bar.tumblr.com/post") .with(post_request).to_return(post_response) expect(post).to receive(:tumblr_ids=).with({"bar.tumblr.com" => post_id}.to_json) service.post(post) + + expect(stub).to have_been_requested end end @@ -37,20 +39,25 @@ describe Services::Tumblr, type: :model do let(:user_info) { {response: {user: {blogs: [{url: "http://foo.tumblr.com"}]}}}.to_json } it "posts a status message to the returned blog" do - stub_request(:post, "http://api.tumblr.com/v2/blog/foo.tumblr.com/post") + stub = stub_request(:post, "http://api.tumblr.com/v2/blog/foo.tumblr.com/post") .with(post_request).to_return(post_response) service.post(post) + + expect(stub).to have_been_requested end end end describe "#delete_post" do it "removes posts from tumblr" do - stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete") - .to_return(status: 200) + post.tumblr_ids = {"foodbar.tumblr.com" => post_id}.to_json + stub = stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete") + .with(body: {"id" => post_id}).to_return(status: 200) service.delete_post(post) + + expect(stub).to have_been_requested end end end