Skip to content

Instantly share code, notes, and snippets.

@mazikwyry
Created June 13, 2017 11:01
Show Gist options
  • Save mazikwyry/92f13d278c459cef6e1cf49d883f1d81 to your computer and use it in GitHub Desktop.
Save mazikwyry/92f13d278c459cef6e1cf49d883f1d81 to your computer and use it in GitHub Desktop.
require 'rails_helper'
RSpec.describe 'POST /signup', type: :request do
let(:url) { '/signup' }
let(:params) do
{
user: {
email: 'user@example.com',
password: 'password'
}
}
end
context 'when user is unauthenticated' do
before { post url, params: params }
it 'returns 200' do
expect(response.status).to eq 200
end
it 'returns a new user' do
expect(response.body).to match_schema('user')
end
end
context 'when user already exists' do
before do
Fabricate :user, email: params[:user][:email]
post url, params: params
end
it 'returns bad request status' do
expect(response.status).to eq 400
end
it 'returns validation errors' do
expect(json['errors'].first['title']).to eq('Bad Request')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment