Add authentication and User model
* Add User model * Add SessionsController * Add password authentication on User * Request authentication for all actions except sign in * Add some helpers for ApplicationController * Update features to work with mandatory authentication
This commit is contained in:
44
spec/models/user_spec.rb
Normal file
44
spec/models/user_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
subject { user }
|
||||
let(:user) { Factory.build(:user) }
|
||||
|
||||
context 'with valid attributes' do
|
||||
it { should be_valid }
|
||||
end
|
||||
|
||||
context 'when email empty' do
|
||||
before do
|
||||
user.email = ''
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'when password empty' do
|
||||
before do
|
||||
user.password = ''
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe '.authenticate' do
|
||||
let (:user) { Factory.create(:user) }
|
||||
|
||||
it 'returns the user with valid credentials' do
|
||||
User.authenticate(
|
||||
user.email,
|
||||
user.password
|
||||
).should == user
|
||||
end
|
||||
|
||||
it 'returns false with invalid credentials' do
|
||||
User.authenticate(
|
||||
user.email,
|
||||
'WRONG'
|
||||
).should be_false
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user