Skip to content

Commit

Permalink
test: system tests for accounts controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Mar 29, 2024
1 parent 36824cd commit c91d8b2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def edit

def update
if @account.update(account_params)
redirect_to edit_account_path, notice: "Account was successfully updated."
redirect_to edit_account_path, notice: I18n.t("accounts.update.success")
else
render :edit, status: :unprocessable_entity
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/kiqr.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ en:
accounts:
edit:
title: "Edit your account profile"
update:
success: "Your account profile has been updated successfully."
form:
name:
personal: "Your full name"
Expand Down
37 changes: 37 additions & 0 deletions test/system/accounts/edit_acounts_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "application_system_test_case"

class EditAccountsTest < ApplicationSystemTestCase
setup do
@user = create(:user)
@team_account = create(:account, name: "Team account")
@team_account.account_users << AccountUser.create(user: @user, role: "owner")
end

test "can edit personal account" do
sign_in(@user)
visit edit_account_path

# Fill the personal account setup form
fill_in "account[name]", with: "New name"

click_on "commit"
assert_text I18n.t("accounts.update.success")

@user.personal_account.reload
assert_equal "New name", @user.personal_account.name
end

test "can edit team account" do
sign_in(@user)
visit edit_account_path(account_id: @team_account)

# Fill the personal account setup form
fill_in "account[name]", with: "New team name"

click_on "commit"
assert_text I18n.t("accounts.update.success")

@team_account.reload
assert_equal "New team name", @team_account.name
end
end

0 comments on commit c91d8b2

Please sign in to comment.