From 5faf0bf8d14a5483b1a69e966c8f07dd69fb0b94 Mon Sep 17 00:00:00 2001 From: Kevin Dew Date: Mon, 15 Apr 2019 09:45:15 +0100 Subject: [PATCH] Remove interactor tests for now These aren't currently adding any further value than the feature tests we already have. --- .../images/create_interactor_spec.rb | 46 ------ .../images/destroy_interactor_spec.rb | 58 ------- .../images/update_crop_interactor_spec.rb | 91 ----------- .../images/update_interactor_spec.rb | 141 ------------------ 4 files changed, 336 deletions(-) delete mode 100644 spec/interactors/images/create_interactor_spec.rb delete mode 100644 spec/interactors/images/destroy_interactor_spec.rb delete mode 100644 spec/interactors/images/update_crop_interactor_spec.rb delete mode 100644 spec/interactors/images/update_interactor_spec.rb diff --git a/spec/interactors/images/create_interactor_spec.rb b/spec/interactors/images/create_interactor_spec.rb deleted file mode 100644 index 68332e7abe..0000000000 --- a/spec/interactors/images/create_interactor_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Images::CreateInteractor do - def strong_params(**params) - ActionController::Parameters.new(params) - end - - describe ".call" do - let(:edition) { create(:edition) } - let(:user) { create(:user) } - - context "when an image upload has issues" do - it "fails with issues" do - result = Images::CreateInteractor.call( - params: strong_params( - document: edition.document.to_param, - image: nil, - ), - user: user, - ) - expect(result).to be_failure - expect(result.issues.any?).to be(true) - end - end - - context "when an image upload doesn't have issues" do - let(:params) do - strong_params( - document: edition.document.to_param, - image: fixture_file_upload("files/960x640.jpg", "image/jpeg"), - ) - end - - it "uploads an image" do - expect { Images::CreateInteractor.call(params: params, user: user) } - .to change { Image.count } - .by(1) - end - - it "updates the edition revision" do - expect { Images::CreateInteractor.call(params: params, user: user) } - .to(change { edition.reload.revision }) - end - end - end -end diff --git a/spec/interactors/images/destroy_interactor_spec.rb b/spec/interactors/images/destroy_interactor_spec.rb deleted file mode 100644 index bdd4f3ed98..0000000000 --- a/spec/interactors/images/destroy_interactor_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Images::DestroyInteractor do - def strong_params(**params) - ActionController::Parameters.new(params) - end - - describe ".call" do - let(:user) { create(:user) } - let(:image_revision) { create(:image_revision, :on_asset_manager) } - let(:edition) { create(:edition, image_revisions: [image_revision]) } - let(:params) do - strong_params( - document: edition.document.to_param, - image_id: image_revision.image_id, - ) - end - - let(:preview_service) { double(try_create_preview: nil) } - - before do - allow(PreviewService) - .to receive(:new).with(edition).and_return(preview_service) - end - - it "creates a revision without the image revision" do - Images::DestroyInteractor.call(params: params, user: user) - revision = edition.reload.revision - expect(revision.image_revisions).not_to include(image_revision) - end - - it "creates a timeline entry" do - expect(TimelineEntry) - .to receive(:create_for_revision) - .with(entry_type: :image_deleted, edition: edition) - Images::DestroyInteractor.call(params: params, user: user) - end - - it "creates a preview" do - expect(preview_service).to receive(:try_create_preview) - Images::DestroyInteractor.call(params: params, user: user) - end - - context "when the image does not exist" do - let(:edition) { create(:edition) } - - it "raises an ActiveRecord::RecordNotFound error" do - params = strong_params( - document: edition.document.to_param, - image_id: Image.maximum(:id).to_i + 1, - ) - - expect { Images::DestroyInteractor.call(params: params, user: user) } - .to raise_error(ActiveRecord::RecordNotFound) - end - end - end -end diff --git a/spec/interactors/images/update_crop_interactor_spec.rb b/spec/interactors/images/update_crop_interactor_spec.rb deleted file mode 100644 index 7a41ce8ac9..0000000000 --- a/spec/interactors/images/update_crop_interactor_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Images::UpdateCropInteractor do - def strong_params(**params) - ActionController::Parameters.new(params) - end - - describe ".call" do - let(:user) { create(:user) } - let(:preview_service) { double(try_create_preview: nil) } - let(:image_revision) { create(:image_revision) } - let(:edition) { create(:edition, image_revisions: [image_revision]) } - - before do - allow(PreviewService) - .to receive(:new).with(edition).and_return(preview_service) - end - - context "when the crop has changed" do - let(:params) do - strong_params( - document: edition.document.to_param, - image_id: image_revision.image_id, - image_revision: { - crop_x: image_revision.crop_x + 10, - crop_y: image_revision.crop_y + 10, - crop_width: image_revision.crop_width, - }, - ) - end - - it "creates a new revision" do - expect { Images::UpdateCropInteractor.call(params: params, user: user) } - .to(change { edition.reload.revision }) - end - - it "creates a timeline entry" do - expect(TimelineEntry) - .to receive(:create_for_revision) - .with(entry_type: :image_updated, edition: edition) - Images::UpdateCropInteractor.call(params: params, user: user) - end - - it "creates a preview" do - expect(preview_service).to receive(:try_create_preview) - Images::UpdateCropInteractor.call(params: params, user: user) - end - end - - context "when the crop hasn't changed" do - let(:params) do - strong_params( - document: edition.document.to_param, - image_id: image_revision.image_id, - image_revision: { - crop_x: image_revision.crop_x, - crop_y: image_revision.crop_y, - crop_width: image_revision.crop_width, - }, - ) - end - - it "doesn't create a new revision" do - expect { Images::UpdateCropInteractor.call(params: params, user: user) } - .not_to(change { edition.reload.revision }) - end - - it "doesn't create a timeline entry" do - expect { Images::UpdateCropInteractor.call(params: params, user: user) } - .not_to change(TimelineEntry, :count) - end - - it "creates a preview" do - expect(preview_service).not_to receive(:try_create_preview) - Images::UpdateCropInteractor.call(params: params, user: user) - end - end - - context "when the image does not exist" do - it "raises an ActiveRecord::RecordNotFound error" do - params = strong_params( - document: edition.document.to_param, - image_id: Image.maximum(:id).to_i + 1, - ) - - expect { Images::UpdateCropInteractor.call(params: params, user: user) } - .to raise_error(ActiveRecord::RecordNotFound) - end - end - end -end diff --git a/spec/interactors/images/update_interactor_spec.rb b/spec/interactors/images/update_interactor_spec.rb deleted file mode 100644 index ff55b36c09..0000000000 --- a/spec/interactors/images/update_interactor_spec.rb +++ /dev/null @@ -1,141 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Images::UpdateInteractor do - def strong_params(**params) - ActionController::Parameters.new(params) - end - - describe ".call" do - let(:user) { create(:user) } - let(:image_revision) { create(:image_revision) } - let(:edition) { create(:edition, image_revisions: [image_revision]) } - let(:preview_service) { double(try_create_preview: nil) } - let(:success_params) do - { - document: edition.document.to_param, - image_id: image_revision.image_id, - image_revision: { alt_text: "alt text" }, - } - end - - before do - allow(PreviewService) - .to receive(:new).with(edition).and_return(preview_service) - end - - context "when an image is updated" do - it "creates a new revision" do - expect { Images::UpdateInteractor.call(params: strong_params(success_params), user: user) } - .to(change { edition.reload.revision }) - image_revision = edition.image_revisions.first - alt_text = success_params[:image_revision][:alt_text] - expect(image_revision.alt_text).to eq(alt_text) - end - - it "creates a preview" do - expect(preview_service).to receive(:try_create_preview) - Images::UpdateInteractor.call(params: strong_params(success_params), user: user) - end - end - - context "when an image is updated without changing lead image" do - it "creates a image_updated timeline entry" do - expect(TimelineEntry) - .to receive(:create_for_revision) - .with(entry_type: :image_updated, edition: edition) - Images::UpdateInteractor.call(params: strong_params(success_params), user: user) - end - end - - context "when a new lead image is selected" do - let(:params) do - strong_params(success_params.merge(lead_image: "on")) - end - - it "sets the edition lead image" do - expect { Images::UpdateInteractor.call(params: params, user: user) } - .to change { edition.reload.lead_image_revision } - .from(nil) - end - - it "creates a lead image selected timeline entry" do - expect(TimelineEntry) - .to receive(:create_for_revision) - .with(entry_type: :lead_image_selected, edition: edition) - Images::UpdateInteractor.call(params: params, user: user) - end - end - - context "when a lead image is removed" do - let(:edition) { create(:edition, lead_image_revision: image_revision) } - let(:params) do - strong_params(success_params.merge(lead_image: nil)) - end - - it "removes the edition lead image" do - expect { Images::UpdateInteractor.call(params: params, user: user) } - .to change { edition.reload.lead_image_revision } - .to(nil) - end - - it "creates a lead image removed timeline entry" do - expect(TimelineEntry) - .to receive(:create_for_revision) - .with(entry_type: :lead_image_removed, edition: edition) - Images::UpdateInteractor.call(params: params, user: user) - end - end - - context "when the image isn't changed" do - let(:image_revision) { create(:image_revision, alt_text: "existing") } - let(:params) do - strong_params(success_params.merge(image_revision: { alt_text: "existing" })) - end - - it "doesn't create a timeline entry" do - expect { Images::UpdateInteractor.call(params: params, user: user) } - .not_to change(TimelineEntry, :count) - end - - it "doesn't update the editions revision" do - expect { Images::UpdateInteractor.call(params: params, user: user) } - .not_to(change { edition.reload.revision }) - end - - it "doesn't preview" do - expect(preview_service).not_to receive(:try_create_preview) - Images::UpdateInteractor.call(params: params, user: user) - end - end - - context "when there are issues" do - it "fails with issues" do - result = Images::UpdateInteractor.call( - params: strong_params( - document: edition.document.to_param, - image_id: image_revision.image_id, - image_revision: { alt_text: "" }, - ), - user: user, - ) - expect(result).to be_failure - expect(result.issues.any?).to be(true) - end - end - - context "when the image does not exist" do - let(:edition) { create(:edition) } - - it "raises an ActiveRecord::RecordNotFound error" do - params = strong_params( - document: edition.document.to_param, - image_id: Image.maximum(:id).to_i + 1, - image_revision: { caption: "Caption" }, - ) - - expect { Images::UpdateInteractor.call(params: params, user: user) } - .to raise_error(ActiveRecord::RecordNotFound) - end - end - end -end