diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e70c5cc1..c38c5cbf 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6735fcfd..88340a9d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index c873c248..9e991278 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,3 +1,7 @@ +<% @user.errors.full_messages.each do |msg| %> +<%= msg %> +<% end %> + <%= form_for @user, url: register_path do |f| %>

<%= f.label :name %>

diff --git a/spec/features/users/login_spec.rb b/spec/features/users/login_spec.rb index f1a259bf..603e3b53 100644 --- a/spec/features/users/login_spec.rb +++ b/spec/features/users/login_spec.rb @@ -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: "reg_@gmail.com" + fill_in 'Password', with: "password" + + click_button('Login') + + save_and_open_page + + 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 diff --git a/spec/features/users/new_spec.rb b/spec/features/users/new_spec.rb index f72a2d65..13f45672 100644 --- a/spec/features/users/new_spec.rb +++ b/spec/features/users/new_spec.rb @@ -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: 'user_1@gmail.com' + 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