ajout des def update et destroy - les tests ne sont pas complets
This commit is contained in:
parent
1ab12d986c
commit
a06caa1a88
5 changed files with 80 additions and 10 deletions
|
|
@ -4,7 +4,9 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
|||
setup do
|
||||
@membership = memberships(:one)
|
||||
@user = users(:one)
|
||||
@user2 = users(:two)
|
||||
@team = teams(:one)
|
||||
@team2 = teams(:two)
|
||||
end
|
||||
|
||||
# INDEX
|
||||
|
|
@ -45,7 +47,6 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# end
|
||||
# assert_response :created
|
||||
# end
|
||||
|
||||
|
||||
test "should forbid create membership" do
|
||||
assert_no_difference("Membership.count") do
|
||||
|
|
@ -55,4 +56,53 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
# UPDATE
|
||||
test "should update membership" do
|
||||
patch api_v1_membership_url(@membership),
|
||||
headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
||||
params: { membership: { can_edit: true } },
|
||||
as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should forbid update membership" do
|
||||
patch api_v1_membership_url(@membership),
|
||||
params: { membership: { can_edit: true } },
|
||||
as: :json
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
# test "should forbid update read_only attributes - team_id" do
|
||||
# patch api_v1_membership_url(@membership),
|
||||
# headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
||||
# params: { membership: { team_id: @team2.id } },
|
||||
# as: :json
|
||||
# assert_response :unprocessable_entity
|
||||
# end
|
||||
|
||||
# test "should forbid update read_only attributes - member_id" do
|
||||
# patch api_v1_membership_url(@membership),
|
||||
# headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
||||
# params: { membership: { member_id: @user2.id } },
|
||||
# as: :json
|
||||
# assert_response :unprocessable_entity
|
||||
# end
|
||||
|
||||
# DESTROY
|
||||
test "should destroy membership" do
|
||||
assert_difference('Membership.count', -1) do
|
||||
delete api_v1_membership_url(@membership),
|
||||
headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
||||
as: :json
|
||||
end
|
||||
assert_response :no_content
|
||||
end
|
||||
|
||||
test "should forbid destroy membership" do
|
||||
assert_no_difference('Membership.count') do
|
||||
delete api_v1_membership_url(@membership), as: :json
|
||||
end
|
||||
assert_response :forbidden
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue