Skip to content

Commit 5a3eaa0

Browse files
committed
Enable setting password for subscribers
1 parent f4f3e7b commit 5a3eaa0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

app/controllers/users/registrations_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ def update
3737

3838
user = current_user
3939

40-
if !user.authenticate(params[:user][:password_challenge])
40+
if user.password_digest_was.present? && !user.authenticate(params[:user][:password_challenge])
4141
flash.now[:error] = "Incorrect password"
4242
return render Users::Registrations::EditView.new(user: user), status: :unprocessable_entity
4343
end
4444

4545
if !user.update(update_user_params)
46+
flash.now[:error] = user.errors.full_messages.to_sentence
4647
return render Users::Registrations::EditView.new(user: user), status: :unprocessable_entity
4748
end
4849

spec/requests/users/registrations_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,27 @@
173173
expect(flash.now[:error]).to eq("Incorrect password")
174174
expect(response).to have_http_status(:unprocessable_entity)
175175
end
176+
177+
it "allows for subscriber setting password first time" do
178+
user = FactoryBot.create(:user, :confirmed, :subscriber)
179+
login_user(user)
180+
181+
put users_registration_path,
182+
params: {user: {password: "password", password_confirmation: "password"}}
183+
184+
expect(response).to redirect_to(users_dashboard_path)
185+
expect(flash[:notice]).to eq("Account updated")
186+
end
187+
188+
it "disallows for subscriber setting password first time without password confirmation" do
189+
user = FactoryBot.create(:user, :confirmed, :subscriber)
190+
login_user(user)
191+
192+
put users_registration_path,
193+
params: {user: {password: "password", password_confirmation: "wrongpassword"}}
194+
195+
expect(flash.now[:error]).to eq("Password confirmation doesn't match Password")
196+
expect(response).to have_http_status(:unprocessable_entity)
197+
end
176198
end
177199
end

0 commit comments

Comments
 (0)