-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
global_business/business/controllers/api/v1/accounts_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Api::V1::AccountsController, type: :controller do | ||
describe 'GET #index' do | ||
it 'returns the current user\'s accounts' do | ||
user = FactoryBot.create(:user) | ||
account = FactoryBot.create(:account, user: user) | ||
sign_in user | ||
get :index, format: :json | ||
expect(response).to be_success | ||
expect(JSON.parse(response.body)).to eq([account.as_json]) | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
it 'returns the specified account' do | ||
user = FactoryBot.create(:user) | ||
account = FactoryBot.create(:account, user: user) | ||
sign_in user | ||
get :show, params: { id: account.id }, format: : json | ||
expect(response).to be_success | ||
expect(JSON.parse(response.body)).to eq(account.as_json) | ||
end | ||
end | ||
|
||
describe 'POST #create' do | ||
it 'creates a new account' do | ||
user = FactoryBot.create(:user) | ||
sign_in user | ||
post :create, params: { account: { balance: 100.0 } }, format: :json | ||
expect(response).to be_success | ||
expect(Account.count).to eq(1) | ||
end | ||
end | ||
|
||
describe 'PUT #update' do | ||
it 'updates the specified account' do | ||
user = FactoryBot.create(:user) | ||
account = FactoryBot.create(:account, user: user) | ||
sign_in user | ||
put :update, params: { id: account.id, account: { balance: 200.0 } }, format: :json | ||
expect(response).to be_success | ||
expect(account.reload.balance).to eq(200.0) | ||
end | ||
end | ||
|
||
describe 'DELETE #destroy' do | ||
it 'destroys the specified account' do | ||
user = FactoryBot.create(:user) | ||
account = FactoryBot.create(:account, user: user) | ||
sign_in user | ||
delete :destroy, params: { id: account.id }, format: :json | ||
expect(response).to be_success | ||
expect(Account.find_by(id: account.id)).to be_nil | ||
end | ||
end | ||
end |