From c91d8b22df311856d5a61c9447a3d7d3cc1a930e Mon Sep 17 00:00:00 2001 From: Rasmus Kjellberg <2277443+kjellberg@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:22:25 +0100 Subject: [PATCH] test: system tests for accounts controller --- app/controllers/accounts_controller.rb | 2 +- config/locales/kiqr.en.yml | 2 ++ test/system/accounts/edit_acounts_test.rb | 37 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/system/accounts/edit_acounts_test.rb diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 7db873f..3773aa6 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -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 diff --git a/config/locales/kiqr.en.yml b/config/locales/kiqr.en.yml index e0c4a69..890825a 100644 --- a/config/locales/kiqr.en.yml +++ b/config/locales/kiqr.en.yml @@ -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" diff --git a/test/system/accounts/edit_acounts_test.rb b/test/system/accounts/edit_acounts_test.rb new file mode 100644 index 0000000..6b2fe90 --- /dev/null +++ b/test/system/accounts/edit_acounts_test.rb @@ -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