Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User story8 and User story11 #110

Merged
merged 4 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def create
flash[:notice] = "You are now logged in."
redirects
else
flash[:notice] = "Those are the wrong credentials."
render :new
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create
elsif email_confirmation == true
flash.now[:notice] = "That email address is already taken."
render :new
elsif @user.save!
elsif @user.save
session[:user_id] = @user.id
flash[:notice] = "You are now registered and logged in."
redirect_to profile_path
Expand Down
4 changes: 4 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% @user.errors.full_messages.each do |msg| %>
<%= msg %>
<% end %>
Copy link
Owner

Choose a reason for hiding this comment

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

High Level: Rails pipes missing/incorrect fields as errors into the User , which can then be printed on the View.


<%= form_for @user, url: register_path do |f| %>

<p><%= f.label :name %></p>
Expand Down
28 changes: 20 additions & 8 deletions spec/features/users/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@
expect(current_path).to eq(root_path)
expect(page).to have_content('You are now logged in.')
end

it 'shows error message if credentials are bad' do
visit login_path

fill_in 'Email', with: "[email protected]"
fill_in 'Password', with: "password"

click_button('Login')

save_and_open_page
Copy link
Owner

Choose a reason for hiding this comment

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

Just make sure to remove this on the next PR @zachlp2016


expect(current_path).to eq(login_path)
expect(page).to have_content('Those are the wrong credentials.')
end
end
end
#

#
# As a visitor
# When I visit the login path
# I see a field to enter my email address and password
# When I submit valid information
# If I am a regular user, I am redirected to my profile page
# If I am a merchant user, I am redirected to my merchant dashboard page
# If I am an admin user, I am redirected to the home page of the site
# And I see a flash message that I am logged in
# When I visit the login page ("/login")
# And I submit valid information
# Then I am redirected to the login page
# And I see a flash message that tells me that my credentials were incorrect
# I am NOT told whether it was my email or password that was incorrect
30 changes: 30 additions & 0 deletions spec/features/users/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,35 @@
expect(new_user.name).to eq('User_1')
end
end

it 'Will not let me register if fields are missing' do
visit root_path

within '.navbar' do
click_link('Register')
end

fill_in 'Name', with: ''
fill_in 'Address', with: '1111 South One St.'
fill_in 'City', with: 'Denver'
fill_in 'State', with: ''
fill_in 'Zip', with: '80000'
fill_in 'Email', with: '[email protected]'
fill_in 'Password', with: ''
fill_in 'Confirm password', with: ''

click_button 'Create User'

expect(current_path).to eq(register_path)
expect(page).to have_content("Name can't be blank")
expect(page).to have_content("State can't be blank")
expect(page).to have_content("Password can't be blank")
end
end
end
#
# As a visitor
# When I visit the user registration page
# And I do not fill in this form completely,
# I am returned to the registration page
# And I see a flash message indicating that I am missing required fields