Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def index

if @owner.present?
@search = BookmarkSearchForm.new(options.merge(faceted: true, parent: @owner))

if @user.blank?
# When it's not a particular user's bookmarks, we want
# to list *bookmarkable* items to avoid duplication
Expand All @@ -112,7 +111,6 @@ def index
flash_search_warnings(@bookmarks)
@facets = @bookmarks.facets
end

if @search.options[:excluded_tag_ids].present? || @search.options[:excluded_bookmark_tag_ids].present?
# Excluded tags do not appear in search results, so we need to generate empty facets
# to keep them as checkboxes on the filters.
Expand Down Expand Up @@ -288,6 +286,13 @@ def confirm_delete
def destroy
@bookmark.destroy
flash[:notice] = ts("Bookmark was successfully deleted.")
# We check that the URL from where the bookmark was deleted is a list of bookmarks. If it is not, we cannot redirect the user back since it would cause a 404 error
if %r{(/bookmarks\z)|(bookmarks/search\z)}.match?(URI.parse(request.referer).path)
redirect_back_or_to user_bookmarks_path(current_user)
else
redirect_to user_bookmarks_path(current_user)
end
rescue URI::InvalidURIError
redirect_to user_bookmarks_path(current_user)
end

Expand Down
83 changes: 73 additions & 10 deletions features/bookmarks/bookmark_javascript.feature
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@bookmarks
Feature: Create and edit bookmarks with javascript enabled
@bookmarks @javascript
Feature: Create, edit and delete bookmarks with javascript enabled
In order to have a good user experience
As a humble user
I want to be able to create and edit bookmarks with javascript enabled
I want to be able to create, edit and delete bookmarks with javascript enabled

Background:
Given I am logged in as "recengine"
And I bookmark the work "Bookmark: The Beginnings"
And I bookmark the work "Bookmark: The Sequel"
And I bookmark the work "RedirectCorrectly"

@javascript
Scenario: The Bookmark button on a work's bookmark page correctly opens, closes, and reopens the form
When I am logged out
And I am logged in
Expand All @@ -28,7 +28,6 @@ Feature: Create and edit bookmarks with javascript enabled
Then I should see "save a bookmark!"
And I should not see "Bookmark" within "#main .navigation"

@javascript
Scenario: The Edit Bookmark button on a work's bookmark page correctly opens, closes, and reopens the edit form
When I am on the bookmarks page for the work "Bookmark: The Beginnings"
# Open
Expand All @@ -45,7 +44,6 @@ Feature: Create and edit bookmarks with javascript enabled
When I follow "Edit"
Then I should see "save a bookmark!"

@javascript
Scenario: The Edit button correctly opens, closes, and reopens edit forms when there are multiple bookmarks on a page
When I am on the bookmarks page
# Open
Expand All @@ -62,7 +60,6 @@ Feature: Create and edit bookmarks with javascript enabled
When I follow "Edit" in the blurb for recengine's bookmark of "Bookmark: The Beginnings"
Then the edit bookmark form should be open in the blurb for recengine's bookmark of "Bookmark: The Beginnings"

@javascript
Scenario: The Saved button correctly opens, closes, and reopens edit forms when there are multiple bookmark blurbs on a page
Given "bookmarker" has a bookmark of a work titled "Bookmark: The Beginnings"
And "bookmarker" has a bookmark of a work titled "Bookmark: The Sequel"
Expand All @@ -83,7 +80,6 @@ Feature: Create and edit bookmarks with javascript enabled
When I follow "Saved" in the blurb for recengine's bookmark of "Bookmark: The Beginnings"
Then the edit bookmark form should be open in the blurb for bookmarker's bookmark of "Bookmark: The Beginnings"

@javascript
Scenario: The Save button correctly opens, closes, and reopens edit forms when there are multiple bookmark blurbs on a page
When I am logged out
And I am logged in as "bookmarker"
Expand All @@ -102,7 +98,6 @@ Feature: Create and edit bookmarks with javascript enabled
When I follow "Save" in the blurb for recengine's bookmark of "Bookmark: The Beginnings"
Then the new bookmark form should be open in the blurb for recengine's bookmark of "Bookmark: The Beginnings"

@javascript
Scenario: The Saved button correctly opens, closes, and reopens edit forms when there are multiple bookmarkable blurbs on a page
When the tag "Testing" is canonized
And I go to the bookmarks tagged "Testing"
Expand All @@ -120,7 +115,6 @@ Feature: Create and edit bookmarks with javascript enabled
When I follow "Saved" in the bookmarkable blurb for "Bookmark: The Beginnings"
Then the edit bookmark form should be open in the bookmarkable blurb for "Bookmark: The Beginnings"

@javascript
Scenario: The Save button correctly opens, closes, and reopens edit forms when there are multiple bookmarkable blurbs on a page
When the tag "Testing" is canonized
And I am logged out
Expand All @@ -139,3 +133,72 @@ Feature: Create and edit bookmarks with javascript enabled
# Reopen
When I follow "Save" in the bookmarkable blurb for "Bookmark: The Beginnings"
Then the new bookmark form should be open in the bookmarkable blurb for "Bookmark: The Beginnings"


# Deleting redirects (AO3-4989)
Scenario: Deleting bookmarks from your bookmarks page does not reset the filtering
Given I am logged in as "PharloomEditor"
And I post the work "Shakra"
And I post the work "Hornet"
And I post the work "Sherma"
And I bookmark the work "Shakra" with the note "Silksong"
And I bookmark the work "Hornet"
And I bookmark the work "Sherma" with the note "Silksong"
When I go to PharloomEditor's bookmarks page
And I fill in "Search bookmarker's tags and notes" with "Silksong"
And I press "Sort and Filter"
And all indexing jobs have been run
And I follow "Delete" in the bookmarkable blurb for "Shakra"
And I confirm the bookmark's deletion
Then I should not see "Shakra"
And I should not see "Hornet"
And I should see "Sherma"

Scenario: Deleting bookmarks from your bookmarks page redirects you back
When I go to recengine's bookmarks page
And I follow "Delete" in the bookmarkable blurb for "RedirectCorrectly"
And I confirm the bookmark's deletion
Then I should be on recengine's bookmarks page

Scenario: Deleting bookmarks from the bookmarks page redirects you back
When I go to the bookmarks page
And I follow "Delete" in the bookmarkable blurb for "RedirectCorrectly"
And I confirm the bookmark's deletion
Then I should be on the bookmarks page

Scenario: Deleting bookmarks from a canonical tag's bookmarks page redirects you back
Given I post the work "Hello" with freeform "Redirect"
And the tag "Redirect" is canonized
And I bookmark the work "Hello"
And all indexing jobs have been run
And I go to the bookmarks tagged "Redirect"
And I follow "Delete" in the bookmarkable blurb for "Hello"
And I confirm the bookmark's deletion
Then I should be on the bookmarks tagged "Redirect"

Scenario: Deleting bookmarks from a user pseud's bookmarks page redirects you back
Given "recengine" has the pseud "alt"
And I bookmark the work "Alternate" as "alt"
And I go to the bookmarks page of "recengine" as pseud "alt"
And I follow "Delete" in the bookmarkable blurb for "Alternate"
And I confirm the bookmark's deletion
Then I should be on the bookmarks page of "recengine" as pseud "alt"

Scenario: Deleting bookmarks from a work's bookmarks page redirects you back
Given I go to the bookmarks page for the work "RedirectCorrectly"
And I follow "Delete"
And I confirm the bookmark's deletion
Then I should be on the bookmarks page for the work "RedirectCorrectly"

Scenario: Deleting bookmarks from the bookmark's page redirects you to your user bookmarks page
Given I bookmark the work "VeryShortLived"
And I follow "Delete"
And I confirm the bookmark's deletion
Then I should be on recengine's bookmarks page

Scenario: Deleting bookmarks from a non-canonical tag's page redirects you to your user bookmarks page
Given I bookmark the work "Ruby" with the tags "Sapphire"
And I go to the "Sapphire" tag page
And I follow "Delete" in the bookmarkable blurb for "Ruby"
And I confirm the bookmark's deletion
Then I should be on recengine's bookmarks page
4 changes: 4 additions & 0 deletions features/step_definitions/bookmark_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ def submit_bookmark_form(pseud, note, tags, collection)
find("#bookmark_#{bookmark_id}").click_link(link)
end

When "I confirm the bookmark's deletion" do
expect(page.accept_alert).to eq("Are you sure you want to delete this bookmark?") if @javascript
end

Then "the {word} bookmark form should be open in the bookmarkable blurb for {string}" do |action, title|
work_id = Work.find_by(title: title).id
within("#bookmark_#{work_id}") do
Expand Down
Loading