From: Anton Khorev Date: Sun, 10 Sep 2023 14:10:31 +0000 (+0300) Subject: Add comment ids to changeset discussion api responses X-Git-Tag: live~1135^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/4b9298855569baf858034fea610f77299fda38e5 Add comment ids to changeset discussion api responses --- diff --git a/app/views/api/changesets/_changeset.json.jbuilder b/app/views/api/changesets/_changeset.json.jbuilder index 25b366011..0d76ed90c 100644 --- a/app/views/api/changesets/_changeset.json.jbuilder +++ b/app/views/api/changesets/_changeset.json.jbuilder @@ -23,6 +23,7 @@ json.tags changeset.tags unless changeset.tags.empty? if @include_discussion json.comments(changeset.comments) do |comment| + json.id comment.id json.date comment.created_at.xmlschema if comment.author.data_public? json.uid comment.author.id diff --git a/app/views/api/changesets/_changeset.xml.builder b/app/views/api/changesets/_changeset.xml.builder index e0188a10e..bc4365eb6 100644 --- a/app/views/api/changesets/_changeset.xml.builder +++ b/app/views/api/changesets/_changeset.xml.builder @@ -28,6 +28,7 @@ xml.changeset(attrs) do |changeset_xml_node| changeset_xml_node.discussion do |discussion_xml_node| changeset.comments.includes(:author).each do |comment| cattrs = { + "id" => comment.id, "date" => comment.created_at.xmlschema } if comment.author.data_public? diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index d4656a5ea..433984414 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -170,7 +170,7 @@ module Api assert_select "osm>changeset>discussion>comment", 0 changeset = create(:changeset, :closed) - create_list(:changeset_comment, 3, :changeset_id => changeset.id) + comment1, comment2, comment3 = create_list(:changeset_comment, 3, :changeset_id => changeset.id) get changeset_show_path(changeset), :params => { :include_discussion => true } assert_response :success, "cannot get closed changeset with comments" @@ -182,6 +182,9 @@ module Api assert_select "osm>changeset>@closed_at", changeset.closed_at.xmlschema assert_select "osm>changeset>discussion", 1 assert_select "osm>changeset>discussion>comment", 3 + assert_select "osm>changeset>discussion>comment:nth-child(1)>@id", comment1.id.to_s + assert_select "osm>changeset>discussion>comment:nth-child(2)>@id", comment2.id.to_s + assert_select "osm>changeset>discussion>comment:nth-child(3)>@id", comment3.id.to_s end def test_show_json @@ -221,6 +224,25 @@ module Api assert_nil js["changeset"]["max_lat"] assert_nil js["changeset"]["max_lon"] assert_equal 0, js["changeset"]["comments"].count + + changeset = create(:changeset, :closed) + comment0, comment1, comment2 = create_list(:changeset_comment, 3, :changeset_id => changeset.id) + + get changeset_show_path(changeset), :params => { :format => "json", :include_discussion => true } + assert_response :success, "cannot get closed changeset with comments" + + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal Settings.api_version, js["version"] + assert_equal Settings.generator, js["generator"] + assert_equal changeset.id, js["changeset"]["id"] + assert_not js["changeset"]["open"] + assert_equal changeset.created_at.xmlschema, js["changeset"]["created_at"] + assert_equal changeset.closed_at.xmlschema, js["changeset"]["closed_at"] + assert_equal 3, js["changeset"]["comments"].count + assert_equal comment0.id, js["changeset"]["comments"][0]["id"] + assert_equal comment1.id, js["changeset"]["comments"][1]["id"] + assert_equal comment2.id, js["changeset"]["comments"][2]["id"] end def test_show_tag_and_discussion_json