This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe User do | |
describe 'POST /api/users' do | |
let(:access_token) { FactoryGirl.create(:access_token) } | |
let(:headers) do | |
{ | |
'Authorization' => "#{access_token.token_type} #{access_token.token}" | |
} | |
end | |
let(:params) do | |
{ | |
'user[name]' => Faker::Name.name, | |
'user[screen_name]' => Faker::Internet.user_name(nil, %w(_)).first(15), | |
'user[password]' => "password", | |
'user[password_confirmation]' => "password", | |
} | |
end | |
context 'with correct parameter' do | |
it do | |
is_expected.to eq 201 | |
expect(response.body).to match_schema :user | |
end | |
end | |
context 'with blank name' do | |
before { params['user[name]'] = '' } | |
it do | |
is_expected.to eq 422 | |
json = JSON.parse(response.body) | |
expect(json).to have_key 'name' | |
end | |
end | |
describe 'user[screen_name]' do | |
context 'with blank' do | |
before { params['user[screen_name]'] = '' } | |
it do | |
is_expected.to eq 422 | |
json = JSON.parse(response.body) | |
expect(json).to have_key 'screen_name' | |
end | |
end | |
context 'with 15 characters' do | |
before { params['user[screen_name]'] = 'a' * 15 } | |
it do | |
is_expected.to eq 201 | |
expect(response.body).to match_schema :user | |
end | |
end | |
context 'with 16 characters' do | |
before { params['user[screen_name]'] = 'a' * 16 } | |
it do | |
is_expected.to eq 422 | |
json = JSON.parse(response.body) | |
expect(json).to have_key 'screen_name' | |
end | |
end | |
end | |
context 'with blank password' do | |
before do | |
params['user[password]'] = '' | |
params['user[password_confirmation]'] = '' | |
end | |
it do | |
is_expected.to eq 422 | |
json = JSON.parse(response.body) | |
expect(json).to have_key 'password' | |
expect(json).to have_key 'password_confirmation' | |
end | |
end | |
context 'with wrong password_confirmation' do | |
before { params['user[password]'] = 'wrong password' } | |
it do | |
is_expected.to eq 422 | |
json = JSON.parse(response.body) | |
expect(json).to have_key 'password_confirmation' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment