From 79bda7a8edab5b3eb7e2feb13c31228c1ec2c219 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 30 Mar 2019 15:35:37 +0000 Subject: [PATCH] Format closed_at correctly in changeset API responses Fixes #2195 --- app/views/api/changesets/_changeset.builder | 2 +- .../api/changesets_controller_test.rb | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/views/api/changesets/_changeset.builder b/app/views/api/changesets/_changeset.builder index 47c494d9b..292184196 100644 --- a/app/views/api/changesets/_changeset.builder +++ b/app/views/api/changesets/_changeset.builder @@ -7,7 +7,7 @@ attrs = { "comments_count" => changeset.comments.length, "changes_count" => changeset.num_changes } -attrs["closed_at"] = changeset.closed_at unless changeset.is_open? +attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.is_open? changeset.bbox.to_unscaled.add_bounds_to(attrs, "_") if changeset.bbox.complete? # user attributes diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index e9132764c..f9643685f 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -132,31 +132,40 @@ module Api # check that the changeset can be shown and returns the correct # document structure. def test_show - changeset_id = create(:changeset).id + changeset = create(:changeset) - get :show, :params => { :id => changeset_id } + get :show, :params => { :id => changeset.id } assert_response :success, "cannot get first changeset" assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1 - assert_select "osm>changeset[id='#{changeset_id}']", 1 + assert_select "osm>changeset[id='#{changeset.id}']", 1 + assert_select "osm>changeset>@open", "true" + assert_select "osm>changeset>@created_at", changeset.created_at.xmlschema + assert_select "osm>changeset>@closed_at", 0 assert_select "osm>changeset>discussion", 0 - get :show, :params => { :id => changeset_id, :include_discussion => true } + get :show, :params => { :id => changeset.id, :include_discussion => true } assert_response :success, "cannot get first changeset with comments" assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1 - assert_select "osm>changeset[id='#{changeset_id}']", 1 + assert_select "osm>changeset[id='#{changeset.id}']", 1 + assert_select "osm>changeset>@open", "true" + assert_select "osm>changeset>@created_at", changeset.created_at.xmlschema + assert_select "osm>changeset>@closed_at", 0 assert_select "osm>changeset>discussion", 1 assert_select "osm>changeset>discussion>comment", 0 - changeset_id = create(:changeset, :closed).id - create_list(:changeset_comment, 3, :changeset_id => changeset_id) + changeset = create(:changeset, :closed) + create_list(:changeset_comment, 3, :changeset_id => changeset.id) - get :show, :params => { :id => changeset_id, :include_discussion => true } + get :show, :params => { :id => changeset.id, :include_discussion => true } assert_response :success, "cannot get closed changeset with comments" assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1 - assert_select "osm>changeset[id='#{changeset_id}']", 1 + assert_select "osm>changeset[id='#{changeset.id}']", 1 + assert_select "osm>changeset>@open", "false" + assert_select "osm>changeset>@created_at", changeset.created_at.xmlschema + assert_select "osm>changeset>@closed_at", changeset.closed_at.xmlschema assert_select "osm>changeset>discussion", 1 assert_select "osm>changeset>discussion>comment", 3 end -- 2.39.5