diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 044b1bfb289..95cb21b6412 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -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 @@ -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 diff --git a/features/works/work_edit.feature b/features/works/work_edit.feature index fc7a84b4bd1..f51d49ccdf9 100644 --- a/features/works/work_edit.feature +++ b/features/works/work_edit.feature @@ -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" diff --git a/features/works/work_edit_tags.feature b/features/works/work_edit_tags.feature index a84cf8fd3fc..725487a1467 100644 --- a/features/works/work_edit_tags.feature +++ b/features/works/work_edit_tags.feature @@ -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"