Bläddra i källkod

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

Lou 3 år sedan
förälder
incheckning
796571af50

+ 5
- 0
app/controllers/api/v1/users_controller.rb Visa fil

7
   end
7
   end
8
 
8
 
9
   def show
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
     render json: UserSerializer.new(@user).serializable_hash.to_json
14
     render json: UserSerializer.new(@user).serializable_hash.to_json
15
+    end
11
   end
16
   end
12
 
17
 
13
   def create
18
   def create

+ 3
- 3
test/controllers/api/v1/users_controller_test.rb Visa fil

11
     assert_response :success
11
     assert_response :success
12
     # Test to ensure response contains the correct email
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
   end
17
   end
18
 
18
 
19
   #CREATE
19
   #CREATE

Loading…
Avbryt
Spara