diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index b70cdcb3c89..901479ef37c 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -601,11 +601,6 @@ def post_draft @user = current_user @work = Work.find(params[:id]) - unless @user.is_author_of?(@work) - flash[:error] = ts('You can only post your own works.') - redirect_to(current_user) && return - end - if @work.posted flash[:error] = ts('That work is already posted. Do you want to edit it instead?') redirect_to(edit_user_work_path(@user, @work)) && return diff --git a/features/admins/admin_works.feature b/features/admins/admin_works.feature index 4b97a160970..cd3d88c1ed3 100644 --- a/features/admins/admin_works.feature +++ b/features/admins/admin_works.feature @@ -400,6 +400,20 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks Then I should see "Deutsch" And I should not see "English" + Scenario: Admin can edit language on drafts + Given basic languages + And I am logged in + And the draft "Wrong Language" + When I am logged in as a "policy_and_abuse" admin + And I view the work "Wrong Language" + And I follow "Edit Work" + When I select "Deutsch" from "Choose a language" + And I press "Save Draft" + Then I should see "Tags were successfully updated." + And I should see "This work is a draft" + And I should see "Deutsch" + But I should not see "English" + Scenario: When admin edits tags and language on works at the same time, both Activities entries are added Given basic languages And the work "Wrong Tags and Language" diff --git a/features/step_definitions/work_steps.rb b/features/step_definitions/work_steps.rb index ca2dea38284..e98e7724420 100644 --- a/features/step_definitions/work_steps.rb +++ b/features/step_definitions/work_steps.rb @@ -392,14 +392,6 @@ step "the periodic tag count task is run" end -Then /^I should see the default work content$/ do - page.should have_content(DEFAULT_CONTENT) -end - -Then /^I should not see the default work content$/ do - page.should_not have_content(DEFAULT_CONTENT) -end - When /^I fill in basic work tags$/ do select(DEFAULT_RATING, from: "Rating") fill_in("Fandoms", with: DEFAULT_FANDOM) diff --git a/features/works/work_edit_multiple.feature b/features/works/work_edit_multiple.feature index 1c6f75f83e0..b054b97fb53 100644 --- a/features/works/work_edit_multiple.feature +++ b/features/works/work_edit_multiple.feature @@ -46,7 +46,7 @@ Feature: Edit Multiple Works And I should see "Glorious" And I should see "Excellent" When I set the fandom to "Random" - And I press "Update All Works" + And I press "Update All Works" Then I should see "Your edits were put through" And I should see "Random" And I should not see "SGA" diff --git a/features/works/work_edit_tags.feature b/features/works/work_edit_tags.feature index 3d0bfc1c468..b4ba998782f 100644 --- a/features/works/work_edit_tags.feature +++ b/features/works/work_edit_tags.feature @@ -95,7 +95,7 @@ Feature: Edit tags on a work Then I should see the page title "Work 1 -" And I should see "Fandom: testing" - Scenario: Preview edit tags + Scenario: Preview edit tags and return to edit them Given I am logged in as "regularuser" And I post the work "Some Work" And I follow "Edit Tags" @@ -103,3 +103,7 @@ Feature: Edit tags on a work And I press "Preview" Then I should see the page title "Preview Work Tags" And I should see "Fandom: exclusive fandom" + And I should see "Preview Tags" + When I press "Edit" + Then I should see "Edit Work Tags" + And the "Fandoms" field should contain "exclusive fandom" diff --git a/spec/controllers/works/default_rails_actions_spec.rb b/spec/controllers/works/default_rails_actions_spec.rb index 894093c86a9..fe69e8e2149 100644 --- a/spec/controllers/works/default_rails_actions_spec.rb +++ b/spec/controllers/works/default_rails_actions_spec.rb @@ -257,15 +257,14 @@ def call_with_params(params) before { fake_login_known_user(user) } it "doesn't allow a user to create a work in a series that they don't own" do - @series = create(:series) + series = create(:series) work_attributes = attributes_for(:work).except(:posted) - work_attributes[:series_attributes] = { id: @series.id } - expect { + work_attributes[:series_attributes] = { id: series.id } + expect do post :create, params: { work: work_attributes } - }.not_to change { @series.works.all.count } + end.not_to change { series.works.all.count } expect(response).to render_template :new - expect(assigns[:work].errors.full_messages).to \ - include("You can't add a work to that series.") + expect(assigns[:work].errors.full_messages).to include("You can't add a work to that series.") end it "doesn't allow a user to submit only a pseud that is not theirs" do @@ -388,6 +387,20 @@ def call_with_params(params) end.to raise_error ActiveRecord::RecordNotFound end end + + context "when collection is given but the work is not in the collection" do + let(:unrelated_collection) { create(:collection) } + + before do + work.update!(collections: [create(:collection)]) + end + + it "redirects to the work" do + get :show, params: { id: work.id, collection_id: unrelated_collection.name } + + it_redirects_to work_path(work) + end + end end describe "share" do @@ -409,20 +422,18 @@ def call_with_params(params) end describe "index" do - before do - @fandom = create(:canonical_fandom) - @work = create(:work, fandom_string: @fandom.name) - end + let(:fandom) { create(:canonical_fandom) } + let!(:work) { create(:work, fandom_string: fandom.name) } it "returns the work" do get :index - expect(assigns(:works)).to include(@work) + expect(assigns(:works)).to include(work) end it "sets the fandom when given a fandom id" do - params = { fandom_id: @fandom.id } + params = { fandom_id: fandom.id } get :index, params: params - expect(assigns(:fandom)).to eq(@fandom) + expect(assigns(:fandom)).to eq(fandom) end describe "when the fandom id is invalid" do @@ -437,25 +448,25 @@ def call_with_params(params) it "returns the work" do params = { fandom_id: nil } get :index, params: params - expect(assigns(:works)).to include(@work) + expect(assigns(:works)).to include(work) end end - describe "without caching" do + context "without caching" do before do AdminSetting.first.update_attribute(:enable_test_caching, false) end it "returns the result with different works the second time" do get :index - expect(assigns(:works)).to include(@work) + expect(assigns(:works)).to include(work) work2 = create(:work) get :index expect(assigns(:works)).to include(work2) end end - describe "with caching" do + context "with caching" do before do AdminSetting.first.update_attribute(:enable_test_caching, true) end @@ -463,7 +474,7 @@ def call_with_params(params) context "with NO owner tag" do it "returns the same result the second time when a new work is created within the expiration time" do get :index - expect(assigns(:works)).to include(@work) + expect(assigns(:works)).to include(work) work2 = create(:work) run_all_indexing_jobs get :index @@ -472,44 +483,45 @@ def call_with_params(params) end context "with a valid owner tag" do + let!(:fandom2) { create(:canonical_fandom) } + let!(:work2) { create(:work, fandom_string: fandom2.name) } + before do - @fandom2 = create(:canonical_fandom) - @work2 = create(:work, fandom_string: @fandom2.name) run_all_indexing_jobs end it "only gets works under that tag" do - get :index, params: { tag_id: @fandom.name } - expect(assigns(:works).items).to include(@work) - expect(assigns(:works).items).not_to include(@work2) + get :index, params: { tag_id: fandom.name } + expect(assigns(:works).items).to include(work) + expect(assigns(:works).items).not_to include(work2) end it "shows different results on second page" do - get :index, params: { tag_id: @fandom.name, page: 2 } - expect(assigns(:works).items).not_to include(@work) + get :index, params: { tag_id: fandom.name, page: 2 } + expect(assigns(:works).items).not_to include(work) end context "with restricted works" do + let!(:work2) { create(:work, fandom_string: fandom.name, restricted: true) } + before do - @work2 = create(:work, fandom_string: @fandom.name, restricted: true) run_all_indexing_jobs end - it "shows restricted works to guests" do - get :index, params: { tag_id: @fandom.name } - expect(assigns(:works).items).to include(@work) - expect(assigns(:works).items).not_to include(@work2) + it "hides them from guests, showing only unrestricted works" do + get :index, params: { tag_id: fandom.name } + expect(assigns(:works).items).to include(work) + expect(assigns(:works).items).not_to include(work2) end - end context "when tag is a synonym" do - let(:fandom_synonym) { create(:fandom, merger: @fandom) } + let(:fandom_synonym) { create(:fandom, merger: fandom) } it "redirects to the merger's work index" do params = { tag_id: fandom_synonym.name } get :index, params: params - it_redirects_to tag_works_path(@fandom) + it_redirects_to tag_works_path(fandom) end context "when collection is specified" do @@ -518,7 +530,7 @@ def call_with_params(params) it "redirects to the merger's collection works index" do params = { tag_id: fandom_synonym.name, collection_id: collection.name } get :index, params: params - it_redirects_to collection_tag_works_path(collection, @fandom) + it_redirects_to collection_tag_works_path(collection, fandom) end end end @@ -565,7 +577,7 @@ def call_with_params(params) params = { user_id: user.login } get :index, params: params expect(assigns(:works).items).to include(user_work, pseud_work) - expect(assigns(:works).items).not_to include(@work) + expect(assigns(:works).items).not_to include(work) end context "with a valid pseud" do @@ -573,7 +585,7 @@ def call_with_params(params) params = { user_id: user.login, pseud_id: pseud.name } get :index, params: params expect(assigns(:works).items).to include(pseud_work) - expect(assigns(:works).items).not_to include(user_work, @work) + expect(assigns(:works).items).not_to include(user_work, work) end end @@ -582,7 +594,7 @@ def call_with_params(params) params = { user_id: user.login, pseud_id: "nonexistent_pseud" } get :index, params: params expect(assigns(:works).items).to include(user_work, pseud_work) - expect(assigns(:works).items).not_to include(@work) + expect(assigns(:works).items).not_to include(work) end end end @@ -620,11 +632,11 @@ def call_with_params(params) describe "update" do let(:update_user) { create(:user) } - let(:update_work) { + let(:update_work) do work = create(:work, authors: [update_user.default_pseud]) create(:chapter, work: work) work - } + end context "when logged in as admin", work_search: false do let(:work) { create(:work) } @@ -650,14 +662,13 @@ def call_with_params(params) end it "doesn't allow the user to add a series that they don't own" do - @series = create(:series) - attrs = { series_attributes: { id: @series.id } } - expect { + series = create(:series) + attrs = { series_attributes: { id: series.id } } + expect do put :update, params: { id: update_work.id, work: attrs } - }.not_to change { @series.works.all.count } + end.not_to change { series.works.all.count } expect(response).to render_template :edit - expect(assigns[:work].errors.full_messages).to \ - include("You can't add a work to that series.") + expect(assigns(:work).errors.full_messages).to include("You can't add a work to that series.") end it "redirects to the edit page if the work could not be saved" do @@ -1057,5 +1068,18 @@ def call_with_params(params) .to raise_exception(ActiveRecord::RecordNotFound) end end + + context "when the work deletion errors out" do + before do + allow_any_instance_of(Work).to receive(:destroy) { raise ActiveRecord::RecordNotDestroyed } + + fake_login_known_user(work.users.first) + end + + it "sets flash message" do + delete :destroy, params: { id: work } + expect(flash[:error]).to eq("We couldn't delete that right now, sorry! Please try again later.") + end + end end end diff --git a/spec/controllers/works/drafts_spec.rb b/spec/controllers/works/drafts_spec.rb index 81a9a514735..9a91279ffea 100644 --- a/spec/controllers/works/drafts_spec.rb +++ b/spec/controllers/works/drafts_spec.rb @@ -86,8 +86,6 @@ it "should display an error if the current user is not the owner of the specified work" do random_work = create(:draft) put :post_draft, params: { id: random_work.id } - # There is code to return a different message in the action, but it is unreachable using a web request - # as the application_controller redirects the user first it_redirects_to_with_error(work_path(random_work), "Sorry, you don't have permission to access the page you were trying to reach.") end diff --git a/spec/controllers/works/importing_spec.rb b/spec/controllers/works/importing_spec.rb index e6bb82db344..36c9e80dc73 100644 --- a/spec/controllers/works/importing_spec.rb +++ b/spec/controllers/works/importing_spec.rb @@ -18,6 +18,20 @@ expect(flash[:error]).to eq "Did you want to enter a URL?" end + context "when the work doesn't save" do + before do + WebMock.stub_request(:get, /import-site-without-tags/) + .to_return(status: 200, + body: "stubbed response", + headers: {}) + end + + it "shows an error message" do + get :import, params: { urls: "http://import-site-without-tags.net", language_id: "en", work: { fandom_string: "Testing" } } + expect(flash[:error]).to eq "We were only partially able to import this work and couldn't save it. Please review below!" + end + end + it "there is an external author name but importing_for_others is NOT turned on" do params = { urls: "url1, url2", diff --git a/spec/controllers/works/updating_tags_spec.rb b/spec/controllers/works/tags_spec.rb similarity index 76% rename from spec/controllers/works/updating_tags_spec.rb rename to spec/controllers/works/tags_spec.rb index 16a2f631dc6..6530042c373 100644 --- a/spec/controllers/works/updating_tags_spec.rb +++ b/spec/controllers/works/tags_spec.rb @@ -25,4 +25,15 @@ it_behaves_like "can update work tags and language" end end + + describe "GET #preview_tags" do + let(:work) { create(:work) } + + it "renders preview tags" do + fake_login_known_user(work.users.first) + + get :preview_tags, params: { id: work } + expect(response).to render_template "preview_tags" + end + end end