-
Notifications
You must be signed in to change notification settings - Fork 1
User controller rspec #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: integration
Are you sure you want to change the base?
Changes from all commits
f517f0d
932e674
1173d2d
0739708
9cdd758
ab30018
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe UsersController, type: :controller do | ||
| describe '#index' do | ||
| it 'redirects to home page' do | ||
| get :index | ||
| expect(response).to redirect_to(root_path) | ||
| end | ||
| end | ||
|
|
||
| let(:user){ create(:user) } | ||
| describe '#create' do | ||
| context 'with valid params' do | ||
| def valid_user | ||
| post :create, params: { user: attributes_for(:user)} | ||
| end | ||
|
|
||
| it 'saves a record to the database' do | ||
| count_before = User.count | ||
| valid_user | ||
|
|
||
| count_after = User.count | ||
| expect(count_after).to eq(count_before + 1) | ||
| end | ||
|
|
||
| it 'saves session id of current user' do | ||
| # u = create(:user) | ||
| # expect(session[:user_id]).to eq(u.id) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment and space below it. Probably better to set session[:user_id] to nil first and then do the comparison. I like the way you did in the comment though. |
||
| valid_user | ||
| expect(session[:user_id]).not_to eq(nil) | ||
| end | ||
| end | ||
|
|
||
| context 'with invalid params' do | ||
| def invalid_user | ||
| post :create, params: { user: attributes_for(:user, email: nil)} | ||
| end | ||
|
|
||
| it 'does not save a record to the database' do | ||
| count_before = User.count | ||
| invalid_user | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this space too >. < |
||
| count_after = User.count | ||
| expect(count_after).to eq(count_before) | ||
| end | ||
|
|
||
| it 'renders the new template' do | ||
| invalid_user | ||
| expect(response).to render_template(:new) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '#show' do | ||
| it 'renders the show template' do | ||
| user = create(:user) | ||
| get :show, params: { id: user.id } | ||
| expect(response).to render_template(:show) | ||
| end | ||
|
|
||
| it 'user id is passed' do | ||
| user = create(:user) | ||
| get :show, params: { id: user.id } | ||
| expect(assigns(:user)).to eq(user) | ||
| end | ||
| end | ||
|
|
||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space, lesson learned from Steve