Skip to content

Commit 83dfedc

Browse files
committed
added test for failure state of the :set_preference aciton of the users controller
1 parent baf0d08 commit 83dfedc

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def set_preference
200200
render json: { status: 'failed',
201201
message: 'Failed to save the preference',
202202
errors: ['Both name and value parameters are required'] },
203-
status: 400
203+
status: :bad_request
204204
end
205205
end
206206

test/controllers/users_controller_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,21 @@ class UsersControllerTest < ActionController::TestCase
529529
end
530530
end
531531

532+
test 'set_preference should correctly handle invalid preferences' do
533+
sign_in users(:standard_user)
534+
535+
[nil, communities(:sample)].each do |community|
536+
post :set_preference, params: { community: community, format: :json }
537+
538+
assert_response(:bad_request)
539+
assert_valid_json_response
540+
541+
parsed_body = JSON.parse(response.body)
542+
assert_equal 'failed', parsed_body['status']
543+
assert_not_nil parsed_body['message']
544+
end
545+
end
546+
532547
private
533548

534549
def create_other_user

0 commit comments

Comments
 (0)