Browse Source

test: ajout test méthode update

Lou 2 years ago
parent
commit
3575af41d3

+ 1
- 1
Gemfile View File

@@ -33,7 +33,7 @@ group :development, :test do
33 33
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console
34 34
   # gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
35 35
   gem 'pry'
36
-  gem 'pry-rails'
36
+  # gem 'pry-rails'
37 37
 end
38 38
 
39 39
 group :development do

+ 0
- 3
Gemfile.lock View File

@@ -108,8 +108,6 @@ GEM
108 108
     pry (0.14.1)
109 109
       coderay (~> 1.1)
110 110
       method_source (~> 1.0)
111
-    pry-rails (0.3.9)
112
-      pry (>= 0.10.4)
113 111
     puma (5.2.2)
114 112
       nio4r (~> 2.0)
115 113
     racc (1.5.2)
@@ -188,7 +186,6 @@ DEPENDENCIES
188 186
   listen (~> 3.3)
189 187
   pg
190 188
   pry
191
-  pry-rails
192 189
   puma (~> 5.0)
193 190
   rack-cors
194 191
   rails (~> 6.1.3, >= 6.1.3.1)

+ 8
- 4
app/controllers/api/v1/memberships_controller.rb View File

@@ -24,13 +24,17 @@ class Api::V1::MembershipsController < ApplicationController
24 24
   end
25 25
 
26 26
   def update
27
-    if @membership.update(memberships_params)
28
-      render json: MembershipSerializer.new(@membership).serializable_hash.to_json, status: :ok
27
+    if params[:membership][:can_edit] 
28
+      if @membership.update(memberships_params)
29
+        render json: MembershipSerializer.new(@membership).serializable_hash.to_json, status: :ok
30
+      else
31
+        render json: @membership.errors, status: :unprocessable_entity
32
+      end
29 33
     else
30
-      render json: @membership.errors, status: :unprocessable_entity
34
+      head 422
31 35
     end
32 36
   end
33
-
37
+  
34 38
   def destroy
35 39
     @membership.destroy
36 40
     head 204

+ 7
- 15
test/controllers/api/v1/memberships_controller_test.rb View File

@@ -73,21 +73,13 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
73 73
     assert_response :forbidden
74 74
   end
75 75
 
76
-  # test "should forbid update read_only attributes - team_id" do
77
-  #   patch api_v1_membership_url(@membership),
78
-  #   headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
79
-  #   params: { membership: { team_id: @team2.id } },
80
-  #   as: :json
81
-  #   assert_response :unprocessable_entity
82
-  # end
83
-
84
-  # test "should forbid update read_only attributes - member_id" do
85
-  #   patch api_v1_membership_url(@membership),
86
-  #   headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
87
-  #   params: { membership: { member_id: @user2.id } },
88
-  #   as: :json
89
-  #   assert_response :unprocessable_entity
90
-  # end  
76
+  test "should forbid update read_only attributes - team_id" do
77
+    patch api_v1_membership_url(@membership),
78
+    headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
79
+    params: { membership: { team_id: @team2.id, member_id: @user2.id } },
80
+    as: :json
81
+    assert_response :unprocessable_entity
82
+  end
91 83
 
92 84
   # DESTROY
93 85
   test "should destroy membership" do

+ 0
- 4
test/models/membership_test.rb View File

@@ -29,8 +29,4 @@ class MembershipTest < ActiveSupport::TestCase
29 29
     membership = Membership.new(member_id: @user.id, team_id: @team.id, can_edit: true)
30 30
     assert_not membership.valid?
31 31
   end
32
-
33
-  test "membership team & member id should not be updated" do
34
-    # How to perfom this test ?
35
-  end
36 32
 end

Loading…
Cancel
Save