Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popular links delete #2276

Merged
merged 7 commits into from
Aug 14, 2024
Merged

Popular links delete #2276

merged 7 commits into from
Aug 14, 2024

Conversation

ellohez
Copy link
Contributor

@ellohez ellohez commented Aug 7, 2024

Create delete mechanism for 'edit' page

  • Added a 'Delete draft' link to the sidebar.
  • Added a confirmation page for deleting the draft.
  • Added Delete button and Cancel link on the confirmation page.
  • Ensured that a Published edition cannot be deleted, either from the GUI or from entering the URL.
  • Delete from database hooked up to the final Delete button.

Trello

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

@ellohez
Copy link
Contributor Author

ellohez commented Aug 7, 2024

My first PR! Happy for any feedback at this point.

@alphagov alphagov deleted a comment from SyedAliTw Aug 7, 2024
Copy link
Contributor

@mtaylorgds mtaylorgds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Just a few minor comments.

app/controllers/homepage_controller.rb Show resolved Hide resolved
link_to("Preview (opens in new tab)", preview_homepage_path(@latest_popular_links), rel:"noreferrer noopener", target:"_blank", class: "govuk-link")
]
link_to("Preview (opens in new tab)", preview_homepage_path(@latest_popular_links), rel:"noreferrer noopener", target:"_blank", class: "govuk-link"),
link_to("Delete draft", confirm_destroy_popular_links_path( @latest_popular_links), class: "govuk-link gem-link--destructive")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space before @latest_popular_links.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can still fix this one, right?

app/views/homepage/popular_links/confirm_destroy.html.erb Outdated Show resolved Hide resolved
test/functional/homepage_controller_test.rb Outdated Show resolved Hide resolved
test/functional/homepage_controller_test.rb Outdated Show resolved Hide resolved
test/functional/homepage_controller_test.rb Outdated Show resolved Hide resolved
test/integration/homepage_popular_links_test.rb Outdated Show resolved Hide resolved
test/integration/homepage_popular_links_test.rb Outdated Show resolved Hide resolved
Add delete functionality and confirm destroy method
Functional and integration tests added for delete mechanism
Routes for 'confirm delete' page and actual destroy action
Destroy and confirm destroy functionality
PopularLinksEdition.can_delete? method to test if edition can be deleted
Tests for confirmation page and cancel delete
Tests for:
 Show previously published edition
 Successful and unsuccessful delete from DB

Application error message was being used twice, so extracted out to own method.
Added an extra check to ensure that there is no way to delete a published edition.
To prevent issues with multiple users accessing the same edition.
Link renamed to 'Delete draft'
Application error message makes it clear that it was a draft that failed to be deleted not an edition
'Can't delete published edition' message updated to be more helpful
Confirmation and success messages reworded to be clear it is a draft that will be/has been deleted
…e of error message method

Fixed incorrect test title
Fixup! Add missing test and extracted error message method
Rename of error message method
Removed content block that doesn't exist in mainstream
Copy link
Contributor

@mtaylorgds mtaylorgds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of very minor comments.

link_to("Preview (opens in new tab)", preview_homepage_path(@latest_popular_links), rel:"noreferrer noopener", target:"_blank", class: "govuk-link")
]
link_to("Preview (opens in new tab)", preview_homepage_path(@latest_popular_links), rel:"noreferrer noopener", target:"_blank", class: "govuk-link"),
link_to("Delete draft", confirm_destroy_popular_links_path( @latest_popular_links), class: "govuk-link gem-link--destructive")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can still fix this one, right?

test/functional/homepage_controller_test.rb Show resolved Hide resolved
Improved test - more descriptive name and added assert for the error message
Test improvements - more accurate names and extra assert
Renamed tests to more explanatory names
Added test to check alert and redirect if delete from DB fails with an exception
Divided tests into 3 contexts - 'draft', 'published' and 'database errors'
Moved context blocks 'destroy' and 'confirm destroy' to after 'publish'
Moved the test for deletion failure to #destroy #draft context block
Added redirect assert to test for can't delete published edition
Copy link
Contributor

@mtaylorgds mtaylorgds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM—good work!

@ellohez ellohez merged commit 4515e05 into main Aug 14, 2024
12 checks passed
@ellohez ellohez deleted the popular-links-delete branch August 14, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants