Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # spec/controllers/api/v1/sessions_controller_spec.rb
- require 'rails_helper'
- RSpec.describe Api::V1::SessionsController, type: :controller do
- describe "POST #create" do
- before(:each) do
- @user = FactoryGirl.create(:user)
- end
- context "when the credentials are correct" do
- before(:each) do
- credentials = { email: @user.email, password: "12345678" }
- post :create, params: { session: credentials } # modified line
- end
- it "returns the user record corresponding to the given credentials" do
- @user.reload
- expect(json_response[:auth_token]).to eql @user.auth_token
- end
- it { should respond_with 200 }
- end
- context "when the credentials are incorrect" do
- before(:each) do
- credentials = { email: @user.email, password: 'badpassword' }
- post :create, params: { session: credentials } # modified line
- end
- it "returns a json with an error" do
- p "json response errors"
- p json_response[:errors]
- expect(json_response[:errors]).to eql "Invalid email or password"
- end
- it { should respond_with 422}
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement