Skip to content

Commit

Permalink
chore: share accounts/form with onboarding path
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Apr 2, 2024
1 parent 1b88bde commit 79b8db5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
12 changes: 11 additions & 1 deletion app/controllers/users/onboarding_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Users::OnboardingController < ApplicationController
end

def new
@account = current_user.build_personal_account
@account = current_user.build_personal_account(personal: true)
end

def create
Expand All @@ -38,4 +38,14 @@ def create
def after_onboarding_path
dashboard_path
end

def form_submit_path
onboarding_path
end
helper_method :form_submit_path

def form_method
:post
end
helper_method :form_method
end
1 change: 1 addition & 0 deletions app/views/accounts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= simple_form_for(account, url: form_submit_path, method: form_method) do |f| %>
<%= f.input :name, placeholder: (account.personal? ? t(".name.personal") : t(".name.team")), required: true, autofocus: true %>
<%#= f.input :custom_field %>
<div class="mt-4 flex justify-between items-center">
<%= f.button :submit, account.persisted? ? t(".button.save") : t(".button.create") %>
</div>
Expand Down
8 changes: 1 addition & 7 deletions app/views/users/onboarding/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
description: "Finish the registration by setting up your user profile."
) do %>
<main class="flex flex-col gap-4 w-full max-w-2xl">
<%= simple_form_for(@account, url: onboarding_path) do |f| %>
<%= f.input :name, placeholder: "Enter your full name", required: true, autofocus: true %>

<div class="mt-4 flex justify-between items-center">
<%= f.button :submit, "Complete the setup" %>
</div>
<% end %>
<%= render "accounts/form", account: @account %>
</main>
<% end %>
<% end %>
7 changes: 4 additions & 3 deletions test/system/users/onboarding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class OnboardingTest < ApplicationSystemTestCase
assert_text I18n.t("devise.registrations.signed_up_but_unconfirmed")

# This is a hack to confirm the email for the user
User.find_by(email: "[email protected]").update(confirmed_at: Time.now)
user = User.find_by(email: "[email protected]")
user.update(confirmed_at: Time.now)

# Login in with the newly created user
visit new_user_session_path
Expand All @@ -26,12 +27,12 @@ class OnboardingTest < ApplicationSystemTestCase
assert_current_path onboarding_path

# Fill the personal account setup form
fill_in "account[name]", with: "John Doe"
# fill_in "account[my_custom_field]", with: "My custom value"
fill_in_account_fields

click_on "commit"

# Should be redirected to dashboard after successfully signing up.
assert_current_path dashboard_path
assert_equal "New name", user.reload.personal_account.name
end
end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
# Load migrations
ActiveRecord::Schema.verbose = false

# Shared helper for filling in account fields.
# This helper is used in onboarding and accounts tests.
# You can add more fields as needed.
def fill_in_account_fields
fill_in "account[name]", with: "New name"
# fill_in "account[custom_field]", with: "Custom data"
end

module ActiveSupport
Expand Down

0 comments on commit 79b8db5

Please sign in to comment.