Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions spec/system/signup/index.spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
require 'rails_helper'

RSpec.describe 'Signup feature' do
it 'should create new user successfully' do
visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
Comment on lines +5 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are repeating in every test iteration. Can we use before(:each) here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Will do that.

fill_in('user_email', with: 'johndoe@example.com')
fill_in('user_phone', with: '9988776677')
fill_in('user_password', with: 'JohnDoe')
Comment on lines +10 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fill these info using Faker for generating names, emails etc. Its like chance.js and we can avoid these hardcoded data.
Faker creates different names, emails etc i think. everytime it runs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Will use that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinandanarya06 We also need to store the names and password as well as we need the same for Login as well

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think we have create user command in factorybot. We can use it in Login testing.

Or we can use rspec fixtures if we need to store and reuse in different tests.


click_button('Sign Up', exact: true)
expect(current_path).to eql('/')

expect(page).to have_content('Your account is not verified!')
end

Comment on lines +17 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems too much.
Does prettier support ruby file 🤔
Otherwise we have to install rufo extension 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peeyush14goyal What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier now supports Ruby formatting as well. Is your prettier working @divyagar ?

it 'should not create user due to no email' do
visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
fill_in('user_phone', with: '9988776677')
fill_in('user_password', with: 'JohnDoe')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/users')

expect(page).to have_content("Attention needed")
expect(page).to have_content("Email can't be blank")
end

it 'should not create user due to no password' do
visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
fill_in('user_email', with: 'johndoe@example.com')
fill_in('user_phone', with: '9988776677')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/users')

expect(page).to have_content("Attention needed")
expect(page).to have_content("Password can't be blank")
end

it 'should not create user due to short password' do
visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
fill_in('user_email', with: 'johndoe@example.com')
fill_in('user_phone', with: '9988776677')
fill_in('user_password', with: 'John')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/users')

expect(page).to have_content("Attention needed")
expect(page).to have_content("Password is too short (minimum is 6 characters)")
end

it 'should not create user due to duplicate email' do
visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
fill_in('user_email', with: 'johndoe@example.com')
fill_in('user_phone', with: '9988776677')
fill_in('user_password', with: 'JohnDoe')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/')

visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
fill_in('user_email', with: 'johndoe@example.com')
fill_in('user_phone', with: '99887766')
fill_in('user_password', with: 'JohnDoe')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/users')

expect(page).to have_content("Attention needed")
expect(page).to have_content("Email has already been taken")
end

it 'should not create user due to duplicate phone numbers' do
visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe')
select "ASHA", :from => "user_role"
fill_in('user_email', with: 'johndoe@example.com')
fill_in('user_phone', with: '9988776677')
fill_in('user_password', with: 'JohnDoe')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/')

visit new_user_registration_path
expect(page).to have_content('Sign up new account')

fill_in('user_full_name', with: 'John Doe2')
select "ASHA", :from => "user_role"
fill_in('user_email', with: 'johndoe2@example.com')
fill_in('user_phone', with: '9988776677')
fill_in('user_password', with: 'JohnDoe2')

click_button('Sign Up', exact: true)
expect(current_path).to eql('/users')

expect(page).to have_content("Attention needed")
expect(page).to have_content("Phone has already been taken")
end

end