Skip to content

Commit

Permalink
Add changeset comment search api json format
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Feb 28, 2024
1 parent 2de59cd commit e83658c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
json.id changeset_comment.id
json.visible changeset_comment.visible
json.date changeset_comment.created_at.xmlschema
if changeset_comment.author.data_public?
json.uid changeset_comment.author.id
json.user changeset_comment.author.display_name
end
json.text changeset_comment.body
5 changes: 5 additions & 0 deletions app/views/api/changeset_comments/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
json.partial! "api/root_attributes"

json.comments(@comments) do |comment|
json.partial! comment
end
9 changes: 1 addition & 8 deletions app/views/api/changesets/_changeset.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ json.tags changeset.tags unless changeset.tags.empty?

if @comments
json.comments(@comments) do |comment|
json.id comment.id
json.visible comment.visible
json.date comment.created_at.xmlschema
if comment.author.data_public?
json.uid comment.author.id
json.user comment.author.display_name
end
json.text comment.body
json.partial! comment
end
end
12 changes: 12 additions & 0 deletions test/controllers/api/changeset_comments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def test_routes
{ :path => "/api/0.6/changeset_comments", :method => :get },
{ :controller => "api/changeset_comments", :action => "index" }
)
assert_routing(
{ :path => "/api/0.6/changeset_comments.json", :method => :get },
{ :controller => "api/changeset_comments", :action => "index", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/changeset/1/comment", :method => :post },
{ :controller => "api/changeset_comments", :action => "create", :id => "1" }
Expand Down Expand Up @@ -67,6 +71,14 @@ def test_index
get api_changeset_comments_path(:user => user1.id)
assert_response :success
assert_comments_in_order [comment22, comment21, comment11]

get api_changeset_comments_path(:from => "2023-03-15T00:00:00Z", :format => "json")
assert_response :success
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
assert_equal 2, js["comments"].count
assert_equal comment23.id, js["comments"][0]["id"]
assert_equal comment22.id, js["comments"][1]["id"]
end

##
Expand Down

0 comments on commit e83658c

Please sign in to comment.