Browse Source

Adds a query string to include users' created activities in def show

Lou 3 years ago
parent
commit
796571af50

+ 5
- 0
app/controllers/api/v1/users_controller.rb View File

@@ -7,7 +7,12 @@ class Api::V1::UsersController < ApplicationController
7 7
   end
8 8
 
9 9
   def show
10
+    if params[:included] === "true"
11
+    options = { include: [:activities] }
12
+    render json: UserSerializer.new(@user, options).serializable_hash.to_json
13
+    else
10 14
     render json: UserSerializer.new(@user).serializable_hash.to_json
15
+    end
11 16
   end
12 17
 
13 18
   def create

+ 3
- 3
test/controllers/api/v1/users_controller_test.rb View File

@@ -11,9 +11,9 @@ class Api::V1::UsersControllerTest < ActionDispatch::IntegrationTest
11 11
     assert_response :success
12 12
     # Test to ensure response contains the correct email
13 13
 
14
-    json_response = JSON.parse(self.response.body)
15
-    assert_equal @user.email, json_response['data']['attributes']['email']
16
-    assert_equal @user.username, json_response['data']['attributes']['username']
14
+    json_response = JSON.parse(self.response.body, symbolize_names: true)
15
+    assert_equal @user.email, json_response.dig(:data, :attributes, :email)
16
+    assert_equal @user.username, json_response.dig(:data, :attributes, :username)
17 17
   end
18 18
 
19 19
   #CREATE

Loading…
Cancel
Save