From: Tom Hughes Date: Fri, 10 May 2013 20:41:19 +0000 (+0100) Subject: Improve tests for trace RSS feeds X-Git-Tag: live~5023 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/b3e540a6b6d9b9833ae57d9067774deb592c5164 Improve tests for trace RSS feeds --- diff --git a/app/models/trace.rb b/app/models/trace.rb index bc47aa8e0..5e609786d 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -8,6 +8,7 @@ class Trace < ActiveRecord::Base scope :visible, where(:visible => true) scope :visible_to, lambda { |u| visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) } scope :public, where(:visibility => ["public", "identifiable"]) + scope :tagged, lambda { |t| joins(:tags).where(:gpx_file_tags => { :tag => t }) } validates_presence_of :user_id, :name, :timestamp validates_presence_of :description, :on => :create diff --git a/test/fixtures/gpx_file_tags.yml b/test/fixtures/gpx_file_tags.yml index d914bfb84..1dac0f26d 100644 --- a/test/fixtures/gpx_file_tags.yml +++ b/test/fixtures/gpx_file_tags.yml @@ -2,3 +2,18 @@ first_trace_1: gpx_id: 1 tag: London id: 1 + +second_trace_1: + gpx_id: 2 + tag: London + id: 2 + +second_trace_2: + gpx_id: 2 + tag: Birmingham + id: 3 + +third_trace_1: + gpx_id: 4 + tag: Birmingham + id: 4 diff --git a/test/functional/trace_controller_test.rb b/test/functional/trace_controller_test.rb index d0afcc587..06095c603 100644 --- a/test/functional/trace_controller_test.rb +++ b/test/functional/trace_controller_test.rb @@ -211,16 +211,16 @@ class TraceControllerTest < ActionController::TestCase # Check that the rss loads def test_rss get :georss - assert_rss_success + check_trace_feed Trace.public - get :georss, :display_name => users(:normal_user).display_name - assert_rss_success - end + get :georss, :tag => "London" + check_trace_feed Trace.tagged("London").public - def assert_rss_success - assert_response :success - assert_template nil - assert_equal "application/rss+xml", @response.content_type + get :georss, :display_name => users(:public_user).display_name + check_trace_feed users(:public_user).traces.public + + get :georss, :display_name => users(:public_user).display_name, :tag => "Birmingham" + check_trace_feed users(:public_user).traces.tagged("Birmingham").public end # Check getting a specific trace through the api @@ -348,6 +348,30 @@ class TraceControllerTest < ActionController::TestCase private + def check_trace_feed(traces) + assert_response :success + assert_template nil + assert_equal "application/rss+xml", @response.content_type + assert_select "rss", :count => 1 do + assert_select "channel", :count => 1 do + assert_select "title" + assert_select "description" + assert_select "link" + assert_select "image" + assert_select "item", :count => traces.visible.count do |items| + traces.visible.order("timestamp DESC").zip(items).each do |trace,item| + assert_select item, "title", trace.name + assert_select item, "link", "http://test.host/user/#{trace.user.display_name}/traces/#{trace.id}" + assert_select item, "guid", "http://test.host/user/#{trace.user.display_name}/traces/#{trace.id}" + assert_select item, "description" + assert_select item, "author", trace.user.display_name + assert_select item, "pubDate", trace.timestamp.rfc822 + end + end + end + end + end + def check_trace_list(traces) traces = traces.visible.order("timestamp DESC") diff --git a/test/unit/tracetag_test.rb b/test/unit/tracetag_test.rb index 2112e5891..0a22919b5 100644 --- a/test/unit/tracetag_test.rb +++ b/test/unit/tracetag_test.rb @@ -4,7 +4,7 @@ class TracetagTest < ActiveSupport::TestCase api_fixtures def test_tracetag_count - assert_equal 1, Tracetag.count + assert_equal 4, Tracetag.count end def test_validations