Skip to content

Commit

Permalink
AO3-4808 Display an error if fandom is removed when editing tags (otw…
Browse files Browse the repository at this point in the history
  • Loading branch information
ariana-paris authored and sarken committed Mar 23, 2017
1 parent ea32dcb commit 00866d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
52 changes: 28 additions & 24 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def create
render :new && return
elsif params[:cancel_button]
flash[:notice] = ts('New work posting canceled.')
redirect_to current_user && return
redirect_to current_user and return
else
# now also treating the cancel_coauthor_button case, bc it should function like a preview, really
set_work_tag_error_messages
Expand Down Expand Up @@ -455,33 +455,37 @@ def update
end

def update_tags
render(:edit_tags) && return unless @work.errors.empty?

if params[:preview_button]
preview_mode(:edit_tags) do
render :preview_tags
end
# If Edit or Cancel is pressed, bail out and display relevant form
if params[:edit_button]
render :edit_tags
elsif params[:cancel_button]
cancel_posting_and_redirect
elsif params[:edit_button]
render :edit_tags
elsif params[:save_button]
Work.expire_work_tag_groups_id(@work.id)
flash[:notice] = ts('Tags were successfully updated.')
redirect_to(@work)
else
saved = true

if @work.has_required_tags? && @work.invalid_tags.blank?
@work.posted = true
@work.minor_version = @work.minor_version + 1
saved = @work.save
# @work.update_minor_version
end
# Otherwise, check that the work is valid, contains no errors etc
set_work_tag_error_messages

preview_mode(:edit_tags, saved) do
flash[:notice] = ts('Work was successfully updated.')
redirect_to(@work)
if @work.errors.empty?
if params[:preview_button]
preview_mode(:edit_tags) do
render :preview_tags
end
elsif params[:save_button]
Work.expire_work_tag_groups_id(@work.id)
flash[:notice] = ts('Tags were successfully updated.')
redirect_to(@work)
else
if @work.has_required_tags? && @work.invalid_tags.blank?
@work.posted = true
@work.minor_version = @work.minor_version + 1
@work.save
flash[:notice] = ts('Work was successfully updated.')
redirect_to(@work) and return
else
render :edit_tags
end
end
else
render :edit_tags
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions features/works/work_edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,12 @@ Feature: Edit Works
And I fill in "Fandoms" with ""
And I press "Post Without Preview"
Then I should see "Sorry! We couldn't save this work because:Please add all required tags. Fandom is missing."

Scenario: User can cancel editing a work
Given I am logged in as a random user
And I post the work "Work 1" with fandom "testing"
And I edit the work "Work 1"
And I fill in "Fandoms" with ""
And I press "Cancel"
When I view the work "Work 1"
Then I should see "Fandom: testing"
19 changes: 19 additions & 0 deletions features/works/work_edit_tags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ Feature: Edit tags on a work
When I view the work "Some Work"
And I follow "Edit Tags"
Then I should not see "Choose a language"

Scenario: A work's tags cannot be edited to remove its fandom
Given I am logged in as a random user
And I post the work "Work 1" with fandom "testing"
And I view the work "Work 1"
And I follow "Edit Tags"
When I fill in "Fandoms" with ""
And I press "Post Without Preview"
Then I should see "Sorry! We couldn't save this work because:Please add all required tags. Fandom is missing."

Scenario: User can cancel editing a work's tags
Given I am logged in as a random user
And I post the work "Work 1" with fandom "testing"
And I view the work "Work 1"
And I follow "Edit Tags"
And I fill in "Fandoms" with ""
And I press "Cancel"
When I view the work "Work 1"
Then I should see "Fandom: testing"

0 comments on commit 00866d6

Please sign in to comment.