Skip to content

Commit

Permalink
Create users_controller_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Sep 20, 2024
1 parent f386dc3 commit 1c04d5c
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rails_helper'

RSpec.describe Api::V1::UsersController, type: :controller do
describe 'GET #show' do
it 'returns the current user' do
user = FactoryBot.create(:user)
sign_in user
get :show, format: :json
expect(response).to be_success
expect(JSON.parse(response.body)).to eq(user.as_json)
end
end

describe 'PUT #update' do
it 'updates the current user' do
user = FactoryBot.create(:user)
sign_in user
put :update, params: { user: { email: '[email protected]' } }, format: :json
expect(response).to be_success
expect(user.reload.email).to eq('[email protected]')
end
end

describe 'DELETE #destroy' do
it 'destroys the current user' do
user = FactoryBot.create(:user)
sign_in user
delete :destroy, format: :json
expect(response).to be_success
expect(User.find_by(id: user.id)).to be_nil
end
end
end

0 comments on commit 1c04d5c

Please sign in to comment.