From 37a7996d949b47f76e5a38cc227f5bbb3e4c19fe Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Fri, 18 Sep 2020 21:04:38 +0200 Subject: [PATCH] API User details: format tweaks - _show_ to return single user only - remove nesting for languages --- app/views/api/users/_user.json.jbuilder | 6 +----- app/views/api/users/show.json.jbuilder | 4 +--- test/controllers/api/users_controller_test.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/views/api/users/_user.json.jbuilder b/app/views/api/users/_user.json.jbuilder index 9629e8fa5..d89b42bef 100644 --- a/app/views/api/users/_user.json.jbuilder +++ b/app/views/api/users/_user.json.jbuilder @@ -54,11 +54,7 @@ json.user do end end - if user.languages - json.languages do - json.array! user.languages.split(",") - end - end + json.languages user.languages if user.languages? json.messages do json.received do diff --git a/app/views/api/users/show.json.jbuilder b/app/views/api/users/show.json.jbuilder index 8ef92752f..51a85380c 100644 --- a/app/views/api/users/show.json.jbuilder +++ b/app/views/api/users/show.json.jbuilder @@ -1,3 +1 @@ -json.users([@user]) do |user| - json.partial! user -end +json.partial! @user diff --git a/test/controllers/api/users_controller_test.rb b/test/controllers/api/users_controller_test.rb index 2824c40b2..5ce30d6a6 100644 --- a/test/controllers/api/users_controller_test.rb +++ b/test/controllers/api/users_controller_test.rb @@ -81,6 +81,15 @@ module Api # check that a non-existent user is not returned get api_user_path(:id => 0) assert_response :not_found + + # check that a visible user is returned properly in json + get api_user_path(:id => user.id, :format => "json") + assert_response :success + assert_equal "application/json", response.media_type + + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal user.id, js["user"]["id"] end def test_details -- 2.39.5