Last active
July 28, 2016 03:57
-
-
Save GiancarlosIO/0b9b00136e37054bc90fd24728b591b4 to your computer and use it in GitHub Desktop.
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
describe UsersController do | |
describe 'GET index' do | |
before do | |
@user = FactoryGirl.create(:user) | |
end | |
it 'ok' do | |
get :index | |
expect(response).to have_http_status(:ok) | |
expect(response).to render_template('index') | |
expect(assigns(:users)).to eq([@user]) | |
end | |
end | |
describe 'GET show' do | |
it 'ok' do | |
get :show, id: @user.id | |
expect(response).to have_http_status(:ok) | |
expect(response).to render_template('show') | |
expect(assigns(:user)).to eq(@user) | |
end | |
it 'when user doesn\'t exist' do | |
get :show, id: 69_696 | |
expect(response).to have_http_status(:redirect) | |
end | |
end | |
describe 'GET new' do | |
it 'ok' do | |
get :new | |
expect(assigns(:user)).to be_a_new(User) | |
end | |
end | |
describe 'GET edit' do | |
it 'ok' do | |
get :edit, id: @user.id | |
expect(assigns(:user)).to eq(@user) | |
end | |
end | |
describe 'POST create' do | |
before do | |
@attributes = { name: 'Giancarlos', last_name: 'Isasi', email: '[email protected]' } | |
end | |
context 'with valid params' do | |
it 'creates a new user' do | |
User.new | |
expect { post :create, user: @attributes }.to change(User, :count).by(1) | |
end | |
it 'assigns a newly created user as @user' do | |
post :create, user: @attributes | |
expect(assigns(:user)).to be_a(User) | |
end | |
it 'redirects to the created user' do | |
post :create, user: @attributes | |
expect(response).to redirect_to(user_path(User.last)) | |
end | |
end | |
end | |
describe 'PUT update' do | |
before do | |
@attributes = { name: 'update Giancarlos' } | |
end | |
context 'with valid params' do | |
it 'assigns the user as @user' do | |
put :update, id: @user.id, user: @attributes | |
expect(assigns(:user).name).to eq @attributes[:name] | |
end | |
it 'redirects' do | |
put :update, id: @user.id, user: @attributes | |
expect(response).to redirect_to(user_path(@user)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment