Skip to content

Commit

Permalink
Merge pull request #8568 from alphagov/fix-bug-with-view-historical-a…
Browse files Browse the repository at this point in the history
…ccount-link

Fix view link for historical accounts
  • Loading branch information
davidgisbey authored Nov 29, 2023
2 parents a8dbd56 + 06435ad commit 85ecde3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/views/admin/historical_accounts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
text: @historical_account.summary,
},
{
text: link_to(sanitize("View #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), Whitehall.public_host + @historical_account.public_path, class: "govuk-link") +
text: link_to(sanitize("View #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), @historical_account.public_url, class: "govuk-link") +
link_to(sanitize("Edit #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), edit_admin_person_historical_account_path(@person, @historical_account), class: "govuk-link govuk-!-margin-left-2") +
link_to(sanitize("Delete #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), confirm_destroy_admin_person_historical_account_path(@person, @historical_account), class: "govuk-link govuk-!-margin-left-2 gem-link--destructive"),
},
Expand Down
16 changes: 11 additions & 5 deletions test/functional/admin/historical_accounts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ class Admin::HistoricalAccountsControllerTest < ActionController::TestCase
end

test "GET on :index assigns the person, their historical accounts and renders the :index template" do
@historical_account = create(:historical_account, person: @person, role: @role)
historical_account = create(:historical_account, person: @person, role: @role)
get :index, params: { person_id: @person }

assert_response :success
assert_template :index
assert_equal @person, assigns(:person)
assert_equal @person.historical_account, assigns(:historical_account)
assert_equal historical_account, assigns(:historical_account)
end
view_test "GET on :index should not show Create historical accounts button when historical account is already created" do
@historical_account = create(:historical_account, person: @person, role: @role)

view_test "GET on :index should display a historical account's details and prevent creation of a second historical account" do
create(:historic_role_appointment, person: @person, role: @role)
historical_account = create(:historical_account, person: @person, role: @role)

get :index, params: { person_id: @person }

assert_select(".govuk-button", text: "Create historical account", count: 0)
assert_select ".govuk-table__cell a:nth-child(1)[href='#{historical_account.public_url}']", text: "View #{@role.name}"
assert_select ".govuk-table__cell a:nth-child(2)[href='#{edit_admin_person_historical_account_path(@person, historical_account)}']", text: "Edit #{@role.name}"
assert_select ".govuk-table__cell a:nth-child(3)[href='#{confirm_destroy_admin_person_historical_account_path(@person, historical_account)}']", text: "Delete #{@role.name}"
assert_select ".govuk-button", text: "Create historical account", count: 0
end

view_test "GET on :index should show Create historical accounts button when historical account is not created" do
Expand Down

0 comments on commit 85ecde3

Please sign in to comment.