2015-07-08 15:17:37 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe UsersController, type: :controller do
|
2015-08-06 15:10:31 -04:00
|
|
|
describe '#show' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
before(:each) { get :show, id: user }
|
|
|
|
|
|
|
|
it 'should render :show' do
|
|
|
|
expect(response).to render_template(:show)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should assign user comments to @comments' do
|
|
|
|
comments = 5.times.collect { create(:comment, user: user) }
|
|
|
|
|
|
|
|
expect(assigns(:comments)).to eq(comments)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should assign requested User to @user' do
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-10 00:27:23 -04:00
|
|
|
describe '#new' do
|
|
|
|
it 'should render :new' do
|
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should assign new User to @user' do
|
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(assigns(:user)).to be_a_new(User)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-08 15:17:37 -04:00
|
|
|
describe '#create' do
|
|
|
|
let(:data) do
|
|
|
|
{
|
|
|
|
username: 'username',
|
|
|
|
password: 'password',
|
|
|
|
email: 'username@domain.com'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid data' do
|
|
|
|
it 'should create a user' do
|
|
|
|
expect { post :create, user: data }.to change(User, :count).by(1)
|
|
|
|
end
|
|
|
|
|
2015-07-10 00:19:01 -04:00
|
|
|
it 'should redirect to the login page' do
|
|
|
|
post :create, user: data
|
|
|
|
|
|
|
|
expect(response).to redirect_to signin_path
|
|
|
|
end
|
2015-07-10 15:20:46 -04:00
|
|
|
|
|
|
|
it 'should send a notice flash message' do
|
|
|
|
post :create, user: data
|
|
|
|
|
|
|
|
expect(flash[:notice]).to be_present
|
|
|
|
end
|
2015-07-08 15:17:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid data' do
|
|
|
|
it 'should not create a user with an invalid username' do
|
|
|
|
data['username'] = ''
|
|
|
|
|
|
|
|
expect { post :create, user: data }.to change(User, :count).by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create a user with an invalid password' do
|
|
|
|
data['password'] = ''
|
|
|
|
|
|
|
|
expect { post :create, user: data }.to change(User, :count).by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create a user with an invalid email' do
|
|
|
|
data['email'] = ''
|
|
|
|
|
|
|
|
expect { post :create, user: data }.to change(User, :count).by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should render :new' do
|
|
|
|
data['username'] = ''
|
|
|
|
|
|
|
|
post :create, user: data
|
|
|
|
|
|
|
|
expect(response).to render_template(:new)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|