Skip to content

Commit

Permalink
Change the Feed#url argument to be clearer; use that method instead o…
Browse files Browse the repository at this point in the history
…f reimplementing
  • Loading branch information
carols10cents committed Sep 25, 2012
1 parent d167a0d commit 7b26acd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ def populate_entries(os_entries)
# Pings hub
# needs absolute url for feed to give to hub for callback
def ping_hubs
feed_url = "#{url}.atom"
feed_url = url(:format => :atom)
OPub::Publisher.new(feed_url, hubs).ping_hubs
end

def local?
remote_url.nil?
end

def url(atom_format = false)
def url(params = {})
atom_format = params.fetch(:format, false) == :atom

if local? && author
protocol = author.use_ssl ? "https" : "http"
url = "#{protocol}://#{author.domain}/feeds/#{id}"
Expand Down
2 changes: 1 addition & 1 deletion app/views/xml/webfinger/xrd.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%Alias= "#{@user.feed.url}"
%Alias= "#{@base_url}users/#{@user.username}"
%Link{:rel => "http://webfinger.net/rel/profile-page", :type => "text/html", :href => "#{@base_url}users/#{@user.username}"}
%Link{:rel => "http://schemas.google.com/g/2010#updates-from", :href => @user.feed.url(true)}
%Link{:rel => "http://schemas.google.com/g/2010#updates-from", :href => @user.feed.url(:format => :atom)}
%Link{:rel => "salmon", :href => "#{@user.feed.url}/salmon"}
%Link{:rel => "http://salmon-protocol.org/ns/salmon-replies", :href => "#{@user.feed.url}/salmon"}
%Link{:rel => "http://salmon-protocol.org/ns/salmon-mention", :href => "#{@user.feed.url}/salmon"}
Expand Down
12 changes: 12 additions & 0 deletions test/models/feed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,16 @@
f.last_update.must_equal(later)
end
end

describe "#url" do
it "does not end in .atom by default" do
f = Fabricate(:feed)
f.url.wont_match(/\.atom$/)
end

it "does end in .atom if we ask it to" do
f = Fabricate(:feed)
f.url(:format => :atom).must_match(/\.atom$/)
end
end
end
2 changes: 1 addition & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include TestHelper

def stub_superfeedr_request_for_user(user)
user_feed_url = CGI.escape(user.feed.url(true))
user_feed_url = CGI.escape(user.feed.url(:format => :atom))

# Downcase the escaped user_feed_url for ruby 1.9.2
stub_request(:post, "http://rstatus.superfeedr.com/").
Expand Down

0 comments on commit 7b26acd

Please sign in to comment.