Skip to content

Commit

Permalink
WIP Add change password on Me::Show page
Browse files Browse the repository at this point in the history
This doesn't pass consistently. I think the problem is that the form
some how isn't loading and selenium is not able to wait for one of the
form fields. The result is it fills out the password_confirmation, but
not the password field.
  • Loading branch information
edwardloveall committed Jun 25, 2019
1 parent 177b891 commit b71f879
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
15 changes: 15 additions & 0 deletions spec/flows/user_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@ describe "Visit a user to follow them" do

flow.should_have_flash("Your invite has been sent for approval!")
end

it "can update password on account page" do
old_pass = Authentic.generate_encrypted_password("password")
user = UserBox.create(&.encrypted_password(old_pass))
flow = UserFlow.new(user)

flow.sign_in
flow.visit_my_account
sleep(0.01)
flow.update_password("my great password")
flow.sign_out
flow.sign_in(email: user.email, password: "my great password")

flow.should_be_signed_in
end
end
5 changes: 4 additions & 1 deletion spec/support/flows/authenticated_base_flow.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ abstract class AuthenticatedBaseFlow < BaseFlow
end

def sign_out
visit_my_page
sign_out_button.click
end

Expand All @@ -34,6 +33,10 @@ abstract class AuthenticatedBaseFlow < BaseFlow
click "@main-follow-nav"
end

def visit_my_account
click "@nav-account"
end

def should_be_signed_in
sign_out_button.should be_on_page
end
Expand Down
7 changes: 7 additions & 0 deletions spec/support/flows/user_flow.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ class UserFlow < AuthenticatedBaseFlow
def request_follow
click "@request-user-follow"
end

def update_password(password : String)
fill_form PasswordResetForm,
password: password,
password_confirmation: password
click "@update-password-button"
end
end
2 changes: 1 addition & 1 deletion src/actions/me/show.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Me::Show < BrowserAction
get "/me" do
render ShowPage, bits: BitQuery.from(current_user)
render ShowPage, form: PasswordResetForm.new
end
end
16 changes: 16 additions & 0 deletions src/actions/users/update_password.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Users::UpdatePassword < BrowserAction
include Auth::PasswordResets::FindUser

post "/users/:user_id/password_update" do
PasswordResetForm.update(user, params) do |form, user|
if form.saved?
flash.success = "Your password has been updated"
redirect to: Me::Show
else
puts params.to_h
puts form.errors
render Me::ShowPage, form: form
end
end
end
end
1 change: 1 addition & 0 deletions src/pages/main_layout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class MainLayout
li { link "My Bits", to: Users::Show.with(@current_user) }
li { link "New Bit", to: Bits::New, flow_id: "new-bit-link" }
li { link "Follow", to: Follows::Index, flow_id: "main-follow-nav" }
li { link "Account", to: Me::Show, flow_id: "nav-account" }
li { link "Sign Out", to: SignIns::Delete, flow_id: "sign-out-button" }
end
end
Expand Down
12 changes: 12 additions & 0 deletions src/pages/me/show_page.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
class Me::ShowPage < MainLayout
needs form : PasswordResetForm

def content
h3 "#{@current_user.username}"

render_password_reset_form(@form)
end

private def render_password_reset_form(form)
form_for Users::UpdatePassword.with(@current_user.id) do
field(form.password) { |i| password_input i, autofocus: "true" }
field(form.password_confirmation) { |i| password_input i }

submit "Update Password", flow_id: "update-password-button"
end
end
end

0 comments on commit b71f879

Please sign in to comment.