Implement sessions/create in JSON API

This commit is contained in:
Thibault Jouan
2012-02-26 11:16:52 +00:00
parent 499b06c9e5
commit 5dfafdcc46
6 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
require 'spec_helper'
feature 'API sign in' do
let(:user) { Factory.create(:user) }
def do_create
post api_v0_sessions_path, :format => :json, :session => {
:email => user.email,
:password => user.password
}
end
scenario 'signs the user in with valid credentials' do
do_create
response.should be_success
(JSON response.body).should include 'id'
end
[:email, :password].each do |attr|
scenario "rejects authentication with invalid credentials (#{attr})" do
user.stub(attr => user.send(attr) + '_INVALID')
do_create
response.should be_not_found
response.body.should be_empty
end
end
end