From e8a149e49beae5919a830467bd93b78ff5727ce4 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Tue, 12 Nov 2024 18:44:12 +0100 Subject: [PATCH] Test note/tag output created at ActiveRecord level Added testing of note XML, JSON, GPX, RSS and feed outputs (with tags) when note (and tags) are created on FactoryBot / ActiveRecord level. --- test/controllers/api/notes_controller_test.rb | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/controllers/api/notes_controller_test.rb b/test/controllers/api/notes_controller_test.rb index 5f69e6a2ac..3972da6cf6 100644 --- a/test/controllers/api/notes_controller_test.rb +++ b/test/controllers/api/notes_controller_test.rb @@ -594,6 +594,8 @@ def test_reopen_fail def test_show_success open_note = create(:note_with_comments) + create(:note_tag, :note => open_note, :k => "created_by", :v => "OSM_TEST") + create(:note_tag, :note => open_note, :k => "삭ÒX~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|傥4ր", :v => "Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|؇Őϋ") get api_note_path(open_note, :format => "xml") assert_response :success @@ -610,6 +612,8 @@ def test_show_success assert_select "comment", :count => 1 end end + assert_select "tag[k='created_by'][v='OSM_TEST']", :count => 1 + assert_select "tag[k='삭ÒX~`!@#$%^&*()-=_+,<.>/?;:\\'\"[{}]\\\\|傥4ր'][v='Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:\\'\"[{}]\\\\|؇Őϋ']", :count => 1 end get api_note_path(open_note, :format => "rss") @@ -624,6 +628,10 @@ def test_show_success assert_select "geo|lat", open_note.lat.to_s assert_select "geo|long", open_note.lon.to_s assert_select "georss|point", "#{open_note.lon} #{open_note.lon}" + assert_select "dc|subject", :count => 2 do |values| + assert_equal "created_by=OSM_TEST", values[0].text + assert_equal '삭ÒX~`!@#$%^&*()-=_+,<.>/?;:\'"[{}]\\|傥4ր=Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:\'"[{}]\\|؇Őϋ', values[1].text + end end end end @@ -643,6 +651,8 @@ def test_show_success assert_equal close_api_note_url(open_note, :format => "json"), js["properties"]["close_url"] assert_equal open_note.created_at.to_s, js["properties"]["date_created"] assert_equal open_note.status, js["properties"]["status"] + assert_equal "OSM_TEST", js["properties"]["tags"]["created_by"] + assert_equal "Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|؇Őϋ", js["properties"]["tags"]["삭ÒX~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|傥4ր"] get api_note_path(open_note, :format => "gpx") assert_response :success @@ -658,6 +668,8 @@ def test_show_success assert_select "url", api_note_url(open_note, :format => "gpx") assert_select "comment_url", comment_api_note_url(open_note, :format => "gpx") assert_select "close_url", close_api_note_url(open_note, :format => "gpx") + assert_select "tag[k='created_by'][v='OSM_TEST']", :count => 1 + assert_select "tag[k='삭ÒX~`!@#$%^&*()-=_+,<.>/?;:\\'\"[{}]\\\\|傥4ր'][v='Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:\\'\"[{}]\\\\|؇Őϋ']", :count => 1 end end end @@ -1171,18 +1183,30 @@ def test_search_bad_params def test_feed_success position = (1.1 * GeoRecord::SCALE).to_i - create(:note_with_comments, :latitude => position, :longitude => position) - create(:note_with_comments, :latitude => position, :longitude => position) + a_note = create(:note_with_comments, :latitude => position, :longitude => position) + create(:note_tag, :note => a_note, :k => "created_by", :v => "OSM_TEST") + create(:note_tag, :note => a_note, :k => "삭ÒX~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|傥4ր", :v => "Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|؇Őϋ") + b_note = create(:note_with_comments, :latitude => position, :longitude => position) + create(:note_tag, :note => b_note, :k => "created_by", :v => "OSM_TEST") + create(:note_tag, :note => b_note, :k => "삭ÒX~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|傥4ր", :v => "Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|؇Őϋ") position = (1.5 * GeoRecord::SCALE).to_i - create(:note_with_comments, :latitude => position, :longitude => position) - create(:note_with_comments, :latitude => position, :longitude => position) + c_note = create(:note_with_comments, :latitude => position, :longitude => position) + create(:note_tag, :note => c_note, :k => "created_by", :v => "OSM_TEST") + create(:note_tag, :note => c_note, :k => "삭ÒX~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|傥4ր", :v => "Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|؇Őϋ") + d_note = create(:note_with_comments, :latitude => position, :longitude => position) + create(:note_tag, :note => d_note, :k => "created_by", :v => "OSM_TEST") + create(:note_tag, :note => d_note, :k => "삭ÒX~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|傥4ր", :v => "Ƭ߯ĸá~`!@#$%^&*()-=_+,<.>/?;:'\"[{}]\\|؇Őϋ") get feed_api_notes_path(:format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do assert_select "channel", :count => 1 do - assert_select "item", :count => 4 + assert_select "item", :count => 4 do |items| + items.each do |item| + assert_select item, "dc|subject", :count => 2 + end + end end end