Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Do not create session with incorrect params
Browse files Browse the repository at this point in the history
  • Loading branch information
chischaschos committed Feb 23, 2014
1 parent 0acfe07 commit d71f124
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/todo/services/session_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def valid?
if user
create_session
else
@h_errors.merge!({ default: 'email or password invalid' })
@h_errors[:errors].merge!({ default: 'email or password invalid' })
end

@h_errors[:errors].empty?
Expand Down
15 changes: 13 additions & 2 deletions spec/services/session_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

let(:params) { { email: 'test@test.com', password: '123test123' } }

context 'when a session does not exists yet' do
before { Todo::Models::User.create params }
let(:wrong_params) { { email: 'test@test.com', password: '123' } }

before { Todo::Models::User.create params }

context 'when the requested user does not exists' do
it 'should not create a session' do
session_creator = Todo::Services::SessionCreator.new wrong_params
expect(session_creator).not_to be_valid
expect(session_creator.access_token).to be_nil
expect(session_creator.h_errors[:errors]).not_to be_empty
end
end

context 'when a session does not exists yet' do
it 'should create a session' do
session_creator = Todo::Services::SessionCreator.new params
expect(session_creator).to be_valid
Expand Down

0 comments on commit d71f124

Please sign in to comment.