Skip to content

Commit

Permalink
fix password reset permission specs
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Oct 20, 2024
1 parent be14ad8 commit 3d339b5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions app/controllers/v0/password_resets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ def create
# 2/3 - The associated user object is returned, indicating a valid token
def show
@user = User.find_by!(password_reset_token: params[:id])
@current_user = @user
authorize @user, :update_password?
render 'users/show', status: :ok
end

# 3/3 - The password reset is submitted and committed to the database
def update
@user = User.find_by!(password_reset_token: params[:id])
@current_user = @user
authorize @user, :update_password?
if @user.update({ password: params.require(:password), password_reset_token: nil })
render 'users/show', status: :ok
Expand Down
4 changes: 2 additions & 2 deletions spec/policies/user_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it { is_expected.to_not permitz(:update) }
it { is_expected.to_not permitz(:destroy) }
it { is_expected.to permitz(:request_password_reset) }
it { is_expected.to_not permitz(:update_password) }
it { is_expected.to permitz(:update_password) }
end

context "for a user" do
Expand All @@ -22,7 +22,7 @@
it { is_expected.to permitz(:update) }
it { is_expected.to permitz(:destroy) }
it { is_expected.to_not permitz(:request_password_reset) }
it { is_expected.to permitz(:update_password) }
it { is_expected.to_not permitz(:update_password) }
end

end
1 change: 1 addition & 0 deletions spec/requests/v0/password_resets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
it "can reset password with valid token" do
expect(user.authenticate('newpass')).to be_falsey
j = api_put "password_resets/#{user.password_reset_token}", { password: 'newpass' }
p response
expect(j["username"]).to eq(user.username)
expect(response.status).to eq(200)

Expand Down

0 comments on commit 3d339b5

Please sign in to comment.