]> git.openstreetmap.org Git - rails.git/commitdiff
API User details: format tweaks
authormmd-osm <mmd.osm@gmail.com>
Fri, 18 Sep 2020 19:04:38 +0000 (21:04 +0200)
committermmd-osm <mmd.osm@gmail.com>
Fri, 18 Sep 2020 19:50:38 +0000 (21:50 +0200)
- _show_ to return single user only
- remove nesting for languages

app/views/api/users/_user.json.jbuilder
app/views/api/users/show.json.jbuilder
test/controllers/api/users_controller_test.rb

index 9629e8fa50276a53770f1123023a2b46e1253c02..d89b42befcf8a8725e6332945d060cb5e6001034 100644 (file)
@@ -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
index 8ef92752f2dd5ae2be32756d15aff06e71fcfcff..51a85380ca97cf641280c3e515bcba0eca46e23d 100644 (file)
@@ -1,3 +1 @@
-json.users([@user]) do |user|
-  json.partial! user
-end
+json.partial! @user
index 2824c40b28a626a6c9cf264d00b7fad7a00aeb3e..5ce30d6a614f4e7f3d84cd5c2af2aaf675f56ac8 100644 (file)
@@ -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