Skip to content
Browse files

Do not create session with incorrect params

  • Loading branch information...
1 parent 0acfe07 commit d71f1242dbc23691f6f22abf9a62e372e761daad @chischaschos committed Feb 22, 2014
Showing with 14 additions and 3 deletions.
  1. +1 −1 lib/todo/services/session_creator.rb
  2. +13 −2 spec/services/session_creator_spec.rb
View
2 lib/todo/services/session_creator.rb
@@ -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?
View
15 spec/services/session_creator_spec.rb
@@ -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

0 comments on commit d71f124

Please sign in to comment.
Something went wrong with that request. Please try again.