Skip to content

Commit

Permalink
Fix spec for sending pings on Article save
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Sep 16, 2014
1 parent 0653659 commit c59d8e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
29 changes: 23 additions & 6 deletions spec/models/article_spec.rb
Expand Up @@ -156,12 +156,29 @@
end
end

### XXX: Should we have a test here?
it "test_send_pings" do
end

### XXX: Should we have a test here?
it "test_send_multiple_pings" do
describe "saving an Article" do
context "with a blog that sends outbound pings" do
let(:referenced_url) { 'http://anotherblog.org/a-post' }
let!(:blog) { create(:blog, send_outbound_pings: 1) }

it 'sends a pingback to urls linked in the body' do
ActiveRecord::Base.observers.should include(:email_notifier)
ActiveRecord::Base.observers.should include(:web_notifier)
a = Article.new :body => %{<a href="#{referenced_url}">}, :title => 'Test the pinging', :published => true
mock_ping = double('ping')
a.pings.stub(:build) { double 'other ping' }
a.pings.stub(:build).with("url" => referenced_url).and_return mock_ping
mock_ping.should_receive(:send_pingback_or_trackback).with(%r{http://myblog.net/\d{4}/\d{2}/\d{2}/test-the-pinging})

expect(a.html_urls.size).to eq(1)
a.save!
a.should be_just_published
a = Article.find(a.id)
a.should_not be_just_published
# Saving again will not resend the pings
a.save
end
end
end

describe "Testing redirects" do
Expand Down
29 changes: 2 additions & 27 deletions spec/models/ping_spec.rb
Expand Up @@ -21,38 +21,13 @@

it 'Pingback sent to url found in referenced body' do
mock_response.should_receive(:[]).with('X-Pingback').at_least(:once).and_return(nil)
mock_response.should_receive(:body).at_least(:once)\
.and_return(%{<link rel="pingback" href="http://anotherblog.org/xml-rpc" />})
mock_response.should_receive(:body).at_least(:once).
and_return(%{<link rel="pingback" href="#{pingback_target}" />})
mock_xmlrpc_response.should_receive(:call).with('pingback.ping', referrer_url, referenced_url)
make_and_send_ping
end
end

context "with a send outbound pings blog" do
let!(:blog) { create(:blog, send_outbound_pings: 1) }

it 'Pingback sent when new article is saved' do
ActiveRecord::Base.observers.should include(:email_notifier)
ActiveRecord::Base.observers.should include(:web_notifier)
a = Article.new :body => '<a href="http://anotherblog.org/a-post">', :title => 'Test the pinging', :published => true

Net::HTTP.should_receive(:get_response).and_return(mock_response)
XMLRPC::Client.should_receive(:new2).with(pingback_target).and_return(mock_xmlrpc_response)

mock_response.should_receive(:[]).with('X-Pingback').at_least(:once).and_return(pingback_target)
mock_xmlrpc_response.should_receive(:call).with('pingback.ping', %r{http://myblog.net/\d{4}/\d{2}/\d{2}/test-the-pinging}, referenced_url)

expect(a.html_urls.size).to eq(1)
a.save!
a.should be_just_published
a = Article.find(a.id)
a.should_not be_just_published
# Saving again will not resend the pings
a.save
end

end

def make_and_send_ping
Net::HTTP.should_receive(:get_response).and_return(mock_response)
XMLRPC::Client.should_receive(:new2).with(pingback_target).and_return(mock_xmlrpc_response)
Expand Down

0 comments on commit c59d8e3

Please sign in to comment.