Refactor code related to authentication:
* User model * SessionsController
This commit is contained in:
@@ -8,31 +8,39 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
context 'when the user submit invalid credentials' do
|
||||
it 'renders the new template' do
|
||||
User.stub(:authenticate).and_return(false)
|
||||
post :create,
|
||||
:session => Factory.attributes_for(:user)
|
||||
response.should render_template('new')
|
||||
end
|
||||
let(:user) { Factory.create(:user) }
|
||||
|
||||
def do_create
|
||||
post :create, :session => {
|
||||
:email => user.email,
|
||||
:password => user.password
|
||||
}
|
||||
end
|
||||
|
||||
context 'when the user submit valid credentials' do
|
||||
let(:user) { Factory.create(:user) }
|
||||
before do
|
||||
User.stub(:authenticate).and_return(user)
|
||||
end
|
||||
|
||||
context 'with valid credentials' do
|
||||
it 'signs the user in' do
|
||||
post :create, :session => Factory.attributes_for(:user)
|
||||
do_create
|
||||
controller.current_user.should == user
|
||||
end
|
||||
|
||||
it 'redirects to the home page' do
|
||||
post :create, :session => Factory.attributes_for(:user)
|
||||
do_create
|
||||
response.should redirect_to(:root)
|
||||
end
|
||||
end
|
||||
|
||||
[:email, :password].each do |attr|
|
||||
context "with invalid credentials (#{attr})" do
|
||||
before do
|
||||
user.stub(attr => user.send(attr) + '_INVALID')
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
do_create
|
||||
response.should render_template('new')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
|
Reference in New Issue
Block a user