Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. # spec/controllers/api/v1/sessions_controller_spec.rb
  2. require 'rails_helper'
  3.  
  4. RSpec.describe Api::V1::SessionsController, type: :controller do
  5.  
  6. describe "POST #create" do
  7.  
  8. before(:each) do
  9. @user = FactoryGirl.create(:user)
  10. end
  11.  
  12. context "when the credentials are correct" do
  13. before(:each) do
  14. credentials = { email: @user.email, password: "12345678" }
  15. post :create, params: { session: credentials } # modified line
  16. end
  17.  
  18. it "returns the user record corresponding to the given credentials" do
  19. @user.reload
  20. expect(json_response[:auth_token]).to eql @user.auth_token
  21. end
  22.  
  23. it { should respond_with 200 }
  24. end
  25.  
  26. context "when the credentials are incorrect" do
  27. before(:each) do
  28. credentials = { email: @user.email, password: 'badpassword' }
  29. post :create, params: { session: credentials } # modified line
  30. end
  31.  
  32. it "returns a json with an error" do
  33. p "json response errors"
  34. p json_response[:errors]
  35. expect(json_response[:errors]).to eql "Invalid email or password"
  36. end
  37.  
  38. it { should respond_with 422}
  39. end
  40.  
  41. end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement