|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "spec_helper" |
| 4 | + |
| 5 | +# OP-19674: after an administrator changes a user's attributes out-of-band, the |
| 6 | +# account page must not be served stale. This example covers navigating away and |
| 7 | +# back to it through in-app menu links (a forward Turbo visit, not history). |
| 8 | +RSpec.describe "My account is fresh after navigating back to it", :js do |
| 9 | + shared_let(:admin) { create(:admin) } |
| 10 | + shared_let(:section) { create(:user_custom_field_section, name: "Professional info") } |
| 11 | + shared_let(:job_title) { create(:user_custom_field, :string, name: "Job title", user_custom_field_section: section) } |
| 12 | + shared_let(:alpha) { create(:department, name: "Alpha department", members: [admin]) } |
| 13 | + shared_let(:beta) { create(:department, name: "Beta department") } |
| 14 | + |
| 15 | + before do |
| 16 | + section.update!(attribute_order: ["department", job_title.column_name]) |
| 17 | + admin.update!(custom_field_values: { job_title.id => "Old title" }) |
| 18 | + login_as admin |
| 19 | + |
| 20 | + visit my_account_path |
| 21 | + expect(page).to have_select("user[department_id]", disabled: true, selected: "Alpha department") |
| 22 | + expect(page).to have_field("Job title", with: "Old title") |
| 23 | + |
| 24 | + # An administrator moves the user and changes the job title out-of-band. |
| 25 | + Departments::AddUserService.new(beta, user: admin) |
| 26 | + .call(user_id: admin.id, remove_from_previous_department: true) |
| 27 | + admin.update!(custom_field_values: { job_title.id => "New title" }) |
| 28 | + end |
| 29 | + |
| 30 | + it "shows the updated Department and Job title after navigating back via the menu" do |
| 31 | + click_on "Notification and email" |
| 32 | + expect(page).to have_current_path(my_notifications_path, wait: 10, ignore_query: true) |
| 33 | + |
| 34 | + click_on "Account" |
| 35 | + expect(page).to have_current_path(my_account_path, wait: 10, ignore_query: true) |
| 36 | + |
| 37 | + expect(page).to have_select("user[department_id]", disabled: true, selected: "Beta department") |
| 38 | + expect(page).to have_field("Job title", with: "New title") |
| 39 | + end |
| 40 | +end |
0 commit comments