Skip to content

Commit

Permalink
Test note/tag output created at ActiveRecord level
Browse files Browse the repository at this point in the history
Added testing of note XML, JSON, GPX, RSS and feed outputs (with tags)
when note (and tags) are created on FactoryBot / ActiveRecord level.
  • Loading branch information
nenad-vujicic committed Dec 9, 2024
1 parent faa483b commit e8a149e
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions test/controllers/api/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e8a149e

Please sign in to comment.