scube-server/spec/controllers/api/sessions_controller_spec.rb
2014-04-01 18:15:44 +00:00

50 lines
1.1 KiB
Ruby

require 'spec_helper'
describe API::SessionsController do
describe 'POST create' do
let(:user) { FactoryGirl.create(:user) }
def do_create
post :create, format: :json, session: {
email: user.email,
password: user.password
}
end
context 'with valid credentials' do
before do
do_create
end
it 'signs the user in' do
expect(controller.current_user).to eq user
end
it 'assigns the user' do
expect(assigns[:user]).to eq user
end
end
[:email, :password].each do |attr|
context "with invalid credentials (#{attr})" do
before do
allow(user).to receive(attr).and_return(user.send(attr) + '_INVALID')
do_create
end
it 'returns a not found response' do
expect(response).to be_not_found
end
it 'returns an empty body' do
expect(response.body).to be_empty
end
it 'assigns no user' do
expect(assigns[:user]).to be_nil
end
end
end
end
end