]> git.openstreetmap.org Git - rails.git/commitdiff
Add comment ids to changeset discussion api responses
authorAnton Khorev <tony29@yandex.ru>
Sun, 10 Sep 2023 14:10:31 +0000 (17:10 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 10 Sep 2023 14:30:06 +0000 (17:30 +0300)
app/views/api/changesets/_changeset.json.jbuilder
app/views/api/changesets/_changeset.xml.builder
test/controllers/api/changesets_controller_test.rb

index 25b366011ce77db5ec66f36bc9ffc9bc0e8620b8..0d76ed90c61eaccaf257b6d0bf0ac306dc314b9d 100644 (file)
@@ -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
index e0188a10e0914b5e9dd66fbd756c8a426df38e2f..bc4365eb6c7f049f2060d737995d2bf782ecb94a 100644 (file)
@@ -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?
index d4656a5ea24a1295a509924313dfd1c55388d6be..4339844140e2df80bcc856a7cfff56137dacb031 100644 (file)
@@ -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