Commit 51aca02

mo <mo@mokhan.ca>
2018-12-15 18:01:24
accept password confirmation during registration
1 parent 53cad95
Changed files (2)
app/controllers/registrations_controller.rb
@@ -18,6 +18,6 @@ class RegistrationsController < ApplicationController
   private
 
   def user_params
-    params.require(:user).permit(:email, :password)
+    params.require(:user).permit(:email, :password, :password_confirmation)
   end
 end
spec/requests/registrations_spec.rb
@@ -13,8 +13,9 @@ RSpec.describe '/registrations' do
   describe "POST /registrations" do
     context "when the new registration data is valid" do
       let(:email) { FFaker::Internet.email }
+      let(:new_password) { FFaker::Internet.password }
 
-      before { post "/registrations", params: { user: { email: email, password: "password" } } }
+      before { post "/registrations", params: { user: { email: email, password: new_password, password_confirmation: new_password } } }
 
       specify { expect(response).to redirect_to(new_session_url) }
       specify { expect(User.count).to be(1) }
@@ -29,5 +30,15 @@ RSpec.describe '/registrations' do
       specify { expect(response).to redirect_to(new_registration_path) }
       specify { expect(flash[:error]).to be_present }
     end
+
+    context "when the password confirmation does not match" do
+      let(:email) { FFaker::Internet.email }
+      let(:new_password) { FFaker::Internet.password }
+
+      before { post "/registrations", params: { user: { email: email, password: new_password, password_confirmation: 'other' } } }
+
+      specify { expect(response).to redirect_to(new_registration_path) }
+      specify { expect(flash[:error]).to be_present }
+    end
   end
 end