1 # frozen_string_literal: true
6 class FeedsControllerTest < ActionDispatch::IntegrationTest
8 # test all routes which lead to this controller
11 { :path => "/traces/rss", :method => :get },
12 { :controller => "traces/feeds", :action => "show", :format => :rss }
15 { :path => "/traces/tag/tagname/rss", :method => :get },
16 { :controller => "traces/feeds", :action => "show", :tag => "tagname", :format => :rss }
19 { :path => "/user/username/traces/rss", :method => :get },
20 { :controller => "traces/feeds", :action => "show", :display_name => "username", :format => :rss }
23 { :path => "/user/username/traces/tag/tagname/rss", :method => :get },
24 { :controller => "traces/feeds", :action => "show", :display_name => "username", :tag => "tagname", :format => :rss }
30 # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
31 trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
32 create(:tracetag, :trace => trace, :tag => "London")
34 trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
35 create(:tracetag, :trace => trace, :tag => "Birmingham")
37 create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
38 create(:tracetag, :trace => trace, :tag => "London")
40 create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
41 create(:tracetag, :trace => trace, :tag => "Birmingham")
44 # First with the public feed
46 check_trace_feed [trace_b, trace_a]
48 # Restrict traces to those with a given tag
49 get traces_feed_path(:tag => "London")
50 check_trace_feed [trace_a]
55 second_user = create(:user)
58 trace_b = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago, :user => user)
59 trace_c = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago, :user => user) do |trace|
60 create(:tracetag, :trace => trace, :tag => "London")
62 create(:trace, :visibility => "private")
64 # Test a user with no traces
65 get traces_feed_path(:display_name => second_user)
68 # Test the user with the traces - should see only public ones
69 get traces_feed_path(:display_name => user)
70 check_trace_feed [trace_c, trace_b]
72 # Should only see traces with the correct tag when a tag is specified
73 get traces_feed_path(:display_name => user, :tag => "London")
74 check_trace_feed [trace_c]
76 # Should no traces if the user does not exist
77 get traces_feed_path(:display_name => "UnknownUser")
83 def check_trace_feed(traces)
84 assert_response :success
85 assert_template "traces/feeds/show"
86 assert_equal "application/rss+xml", @response.media_type
87 assert_select "rss", :count => 1 do
88 assert_select "channel", :count => 1 do |channel|
90 assert_select "description"
93 assert_select "item", :count => traces.length
95 traces.zip(channel.css("item")).each do |trace, item|
96 assert_select item, "title", trace.name
97 assert_select item, "link", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
98 assert_select item, "guid", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
99 assert_select item, "description" do
100 assert_dom_encoded do
101 assert_select "img[src='#{trace_icon_url trace.user, trace}']"
104 # assert_select item, "dc:creator", trace.user.display_name
105 assert_select item, "pubDate", trace.timestamp.rfc822