4   class FeedsControllerTest < ActionDispatch::IntegrationTest
 
   6     # test all routes which lead to this controller
 
   9         { :path => "/traces/rss", :method => :get },
 
  10         { :controller => "traces/feeds", :action => "show", :format => :rss }
 
  13         { :path => "/traces/tag/tagname/rss", :method => :get },
 
  14         { :controller => "traces/feeds", :action => "show", :tag => "tagname", :format => :rss }
 
  17         { :path => "/user/username/traces/rss", :method => :get },
 
  18         { :controller => "traces/feeds", :action => "show", :display_name => "username", :format => :rss }
 
  21         { :path => "/user/username/traces/tag/tagname/rss", :method => :get },
 
  22         { :controller => "traces/feeds", :action => "show", :display_name => "username", :tag => "tagname", :format => :rss }
 
  28       # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
 
  29       trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
 
  30         create(:tracetag, :trace => trace, :tag => "London")
 
  32       trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
 
  33         create(:tracetag, :trace => trace, :tag => "Birmingham")
 
  35       create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
 
  36         create(:tracetag, :trace => trace, :tag => "London")
 
  38       create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
 
  39         create(:tracetag, :trace => trace, :tag => "Birmingham")
 
  42       # First with the public feed
 
  44       check_trace_feed [trace_b, trace_a]
 
  46       # Restrict traces to those with a given tag
 
  47       get traces_feed_path(:tag => "London")
 
  48       check_trace_feed [trace_a]
 
  53       second_user = create(:user)
 
  56       trace_b = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago, :user => user)
 
  57       trace_c = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago, :user => user) do |trace|
 
  58         create(:tracetag, :trace => trace, :tag => "London")
 
  60       create(:trace, :visibility => "private")
 
  62       # Test a user with no traces
 
  63       get traces_feed_path(:display_name => second_user)
 
  66       # Test the user with the traces - should see only public ones
 
  67       get traces_feed_path(:display_name => user)
 
  68       check_trace_feed [trace_c, trace_b]
 
  70       # Should only see traces with the correct tag when a tag is specified
 
  71       get traces_feed_path(:display_name => user, :tag => "London")
 
  72       check_trace_feed [trace_c]
 
  74       # Should no traces if the user does not exist
 
  75       get traces_feed_path(:display_name => "UnknownUser")
 
  81     def check_trace_feed(traces)
 
  82       assert_response :success
 
  83       assert_template "traces/feeds/show"
 
  84       assert_equal "application/rss+xml", @response.media_type
 
  85       assert_select "rss", :count => 1 do
 
  86         assert_select "channel", :count => 1 do
 
  88           assert_select "description"
 
  91           assert_select "item", :count => traces.length do |items|
 
  92             traces.zip(items).each do |trace, item|
 
  93               assert_select item, "title", trace.name
 
  94               assert_select item, "link", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
 
  95               assert_select item, "guid", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
 
  96               assert_select item, "description" do
 
  98                   assert_select "img[src='#{trace_icon_url trace.user, trace}']"
 
 101               # assert_select item, "dc:creator", trace.user.display_name
 
 102               assert_select item, "pubDate", trace.timestamp.rfc822