From eb5e8f49bb34bd25a13a26b6eefb9d492ff6ac54 Mon Sep 17 00:00:00 2001 From: Laura Ghiorghisor Date: Mon, 1 Jul 2024 21:56:50 +0100 Subject: [PATCH] Fix tests for rubocop and assertions Ran some automations to fix rubocop. Fix some assertions which were testing the wrong objects due to variable declarations. --- db/schema.rb | 2 +- .../editing_content/govspeak_preview_spec.rb | 2 +- .../insert_contact_embed_spec.rb | 2 +- .../insert_inline_file_attachment_spec.rb | 4 +-- .../insert_inline_image_spec.rb | 2 +- .../insert_video_embed_spec.rb | 2 +- .../editing_content/url_preview_spec.rb | 2 +- .../reorder_attachments_spec.rb | 2 +- .../delete_file_attachment_spec.rb | 2 +- .../preview_file_attachment_spec.rb | 2 +- .../replace_file_attachment_file_spec.rb | 2 +- .../upload_file_attachment_spec.rb | 2 +- .../editing_images/choose_lead_image_spec.rb | 2 +- .../editing_images/delete_image_spec.rb | 2 +- .../editing_images/edit_image_spec.rb | 2 +- .../editing_images/remove_lead_image_spec.rb | 2 +- .../editing_images/upload_image_spec.rb | 2 +- .../editing_topics/edit_topics_search_spec.rb | 2 +- spec/features/workflow/publish_spec.rb | 2 +- .../workflow/publish_without_review_spec.rb | 2 +- spec/helpers/application_helper_spec.rb | 2 +- spec/jobs/populate_bulk_data_job_spec.rb | 2 +- spec/lib/edition_filter_spec.rb | 28 +++++++++---------- .../preview/content_checker_spec.rb | 8 +++--- .../publish/content_checker_spec.rb | 8 +++--- .../revision_updater/file_attachment_spec.rb | 6 ++-- .../versioning/revision_updater/image_spec.rb | 6 ++-- .../whitehall_importer/create_edition_spec.rb | 2 +- .../create_migration_spec.rb | 14 +++++----- spec/lib/whitehall_importer/import_spec.rb | 2 +- .../integrity_checker_spec.rb | 8 +++--- .../whitehall_migration/asset_import_spec.rb | 8 +++--- spec/services/preview_asset_service_spec.rb | 9 ++---- 33 files changed, 71 insertions(+), 74 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 59ef4f8e8a..b4806d713d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_09_16_182836) do +ActiveRecord::Schema[7.1].define(version: 2022_09_16_182836) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/features/editing_content/govspeak_preview_spec.rb b/spec/features/editing_content/govspeak_preview_spec.rb index aefb66eca3..ee5523a670 100644 --- a/spec/features/editing_content/govspeak_preview_spec.rb +++ b/spec/features/editing_content/govspeak_preview_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Shows a preview of Govspeak", js: true do +RSpec.feature "Shows a preview of Govspeak", :js do scenario do given_there_is_an_edition when_i_go_to_edit_the_edition diff --git a/spec/features/editing_content/insert_contact_embed_spec.rb b/spec/features/editing_content/insert_contact_embed_spec.rb index 0b77f4cd5e..f6f6fb8b12 100644 --- a/spec/features/editing_content/insert_contact_embed_spec.rb +++ b/spec/features/editing_content/insert_contact_embed_spec.rb @@ -1,7 +1,7 @@ RSpec.feature "Insert contact embed" do include AccessibleAutocompleteHelper - scenario "with javascript", js: true do + scenario "with javascript", :js do given_there_is_an_edition when_i_go_to_edit_the_edition and_i_click_to_insert_a_contact diff --git a/spec/features/editing_content/insert_inline_file_attachment_spec.rb b/spec/features/editing_content/insert_inline_file_attachment_spec.rb index 1ef07a16f6..5a88c7b012 100644 --- a/spec/features/editing_content/insert_inline_file_attachment_spec.rb +++ b/spec/features/editing_content/insert_inline_file_attachment_spec.rb @@ -1,5 +1,5 @@ RSpec.feature "Insert inline file attachment" do - scenario "block snippet", js: true do + scenario "block snippet", :js do given_there_is_an_edition_with_file_attachments when_i_go_to_edit_the_edition and_i_click_to_insert_a_file_attachment @@ -8,7 +8,7 @@ then_i_see_the_attachment_snippet_is_inserted end - scenario "link snippet", js: true do + scenario "link snippet", :js do given_there_is_an_edition_with_file_attachments when_i_go_to_edit_the_edition and_i_click_to_insert_a_file_attachment diff --git a/spec/features/editing_content/insert_inline_image_spec.rb b/spec/features/editing_content/insert_inline_image_spec.rb index 7c29e43198..143ba65484 100644 --- a/spec/features/editing_content/insert_inline_image_spec.rb +++ b/spec/features/editing_content/insert_inline_image_spec.rb @@ -1,5 +1,5 @@ RSpec.feature "Insert inline image" do - scenario "with javascript", js: true do + scenario "with javascript", :js do given_there_is_an_edition_with_images when_i_go_to_edit_the_edition and_i_click_to_insert_an_image diff --git a/spec/features/editing_content/insert_video_embed_spec.rb b/spec/features/editing_content/insert_video_embed_spec.rb index 58edbf2de4..cd639a557c 100644 --- a/spec/features/editing_content/insert_video_embed_spec.rb +++ b/spec/features/editing_content/insert_video_embed_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe "Insert video embed", js: true do +RSpec.describe "Insert video embed", :js do scenario do given_there_is_an_edition when_i_go_to_edit_the_edition diff --git a/spec/features/editing_content/url_preview_spec.rb b/spec/features/editing_content/url_preview_spec.rb index 3fa95f4560..9aa3f743f3 100644 --- a/spec/features/editing_content/url_preview_spec.rb +++ b/spec/features/editing_content/url_preview_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Shows a preview of the URL", js: true do +RSpec.feature "Shows a preview of the URL", :js do scenario do given_there_is_an_edition when_i_go_to_edit_the_edition diff --git a/spec/features/editing_featured_attachments/reorder_attachments_spec.rb b/spec/features/editing_featured_attachments/reorder_attachments_spec.rb index 54db32bba1..8b69fcec65 100644 --- a/spec/features/editing_featured_attachments/reorder_attachments_spec.rb +++ b/spec/features/editing_featured_attachments/reorder_attachments_spec.rb @@ -9,7 +9,7 @@ and_i_see_the_timeline_entry end - scenario "with javascript", js: true do + scenario "with javascript", :js do given_there_is_an_edition_with_attachments when_i_go_to_the_attachments_page and_i_click_to_reorder_the_attachments diff --git a/spec/features/editing_file_attachments/delete_file_attachment_spec.rb b/spec/features/editing_file_attachments/delete_file_attachment_spec.rb index f94806ad86..d30c0c9943 100644 --- a/spec/features/editing_file_attachments/delete_file_attachment_spec.rb +++ b/spec/features/editing_file_attachments/delete_file_attachment_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Delete a file attachment", js: true do +RSpec.feature "Delete a file attachment", :js do scenario "inline" do given_there_is_an_edition_with_attachments when_i_insert_an_attachment diff --git a/spec/features/editing_file_attachments/preview_file_attachment_spec.rb b/spec/features/editing_file_attachments/preview_file_attachment_spec.rb index f0155bb1c4..f55241aa71 100644 --- a/spec/features/editing_file_attachments/preview_file_attachment_spec.rb +++ b/spec/features/editing_file_attachments/preview_file_attachment_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Preview file attachment", js: true do +RSpec.feature "Preview file attachment", :js do scenario do given_there_is_an_edition_with_attachments and_the_attachment_is_available diff --git a/spec/features/editing_file_attachments/replace_file_attachment_file_spec.rb b/spec/features/editing_file_attachments/replace_file_attachment_file_spec.rb index 4302808eed..77441f5e5e 100644 --- a/spec/features/editing_file_attachments/replace_file_attachment_file_spec.rb +++ b/spec/features/editing_file_attachments/replace_file_attachment_file_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Replace a file attachment file", js: true do +RSpec.feature "Replace a file attachment file", :js do scenario "inline" do given_there_is_an_edition_with_an_attachment when_i_click_to_insert_an_attachment diff --git a/spec/features/editing_file_attachments/upload_file_attachment_spec.rb b/spec/features/editing_file_attachments/upload_file_attachment_spec.rb index 40ba1297c9..1f1cf0b5c1 100644 --- a/spec/features/editing_file_attachments/upload_file_attachment_spec.rb +++ b/spec/features/editing_file_attachments/upload_file_attachment_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Upload file attachment", js: true do +RSpec.feature "Upload file attachment", :js do scenario "inline attachment" do given_there_is_an_edition when_i_go_to_edit_the_edition diff --git a/spec/features/editing_images/choose_lead_image_spec.rb b/spec/features/editing_images/choose_lead_image_spec.rb index 694201c5c6..6c273cda5a 100644 --- a/spec/features/editing_images/choose_lead_image_spec.rb +++ b/spec/features/editing_images/choose_lead_image_spec.rb @@ -35,7 +35,7 @@ def and_i_edit_the_image_metadata end def and_i_tick_the_image_is_the_lead_image - expect(find_field("lead_image").checked?).to eq false + expect(find_field("lead_image").checked?).to be false check(I18n.t!("images.edit.form_labels.lead_image")) click_on "Save" end diff --git a/spec/features/editing_images/delete_image_spec.rb b/spec/features/editing_images/delete_image_spec.rb index 28e342be56..ff3588002f 100644 --- a/spec/features/editing_images/delete_image_spec.rb +++ b/spec/features/editing_images/delete_image_spec.rb @@ -17,7 +17,7 @@ and_i_see_the_timeline_entry end - scenario "inline image", js: true do + scenario "inline image", :js do given_there_is_an_edition_with_images when_i_insert_an_inline_image and_i_delete_the_image diff --git a/spec/features/editing_images/edit_image_spec.rb b/spec/features/editing_images/edit_image_spec.rb index f839993acf..6dc9b33474 100644 --- a/spec/features/editing_images/edit_image_spec.rb +++ b/spec/features/editing_images/edit_image_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Edit image", js: true do +RSpec.feature "Edit image", :js do scenario "lead image" do given_there_is_an_edition_with_a_lead_image when_i_visit_the_images_page diff --git a/spec/features/editing_images/remove_lead_image_spec.rb b/spec/features/editing_images/remove_lead_image_spec.rb index b377e9326b..85529fa4e2 100644 --- a/spec/features/editing_images/remove_lead_image_spec.rb +++ b/spec/features/editing_images/remove_lead_image_spec.rb @@ -43,7 +43,7 @@ def and_i_edit_the_image_metadata end def and_i_untick_the_image_is_the_lead_image - expect(find_field("lead_image").checked?).to eq true + expect(find_field("lead_image").checked?).to be true uncheck(I18n.t!("images.edit.form_labels.lead_image")) click_on "Save" end diff --git a/spec/features/editing_images/upload_image_spec.rb b/spec/features/editing_images/upload_image_spec.rb index da2b07f1ce..71ad7ae06a 100644 --- a/spec/features/editing_images/upload_image_spec.rb +++ b/spec/features/editing_images/upload_image_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Upload an image", js: true do +RSpec.feature "Upload an image", :js do scenario "lead image" do given_there_is_an_edition when_i_visit_the_images_page diff --git a/spec/features/editing_topics/edit_topics_search_spec.rb b/spec/features/editing_topics/edit_topics_search_spec.rb index d7cf06913d..6231aec845 100644 --- a/spec/features/editing_topics/edit_topics_search_spec.rb +++ b/spec/features/editing_topics/edit_topics_search_spec.rb @@ -1,4 +1,4 @@ -RSpec.feature "Edit topics using search", js: true do +RSpec.feature "Edit topics using search", :js do include TopicsHelper scenario do diff --git a/spec/features/workflow/publish_spec.rb b/spec/features/workflow/publish_spec.rb index aa1b05729a..bb2fea7b8f 100644 --- a/spec/features/workflow/publish_spec.rb +++ b/spec/features/workflow/publish_spec.rb @@ -79,7 +79,7 @@ def and_i_receive_a_confirmation_email tos = ActionMailer::Base.deliveries.map(&:to) message = ActionMailer::Base.deliveries.first - expect(tos).to match_array [[@creator.email], [current_user.email]] + expect(tos).to contain_exactly([@creator.email], [current_user.email]) expect(message.body).to have_content("https://www.test.gov.uk/news/banana-pricing-updates") expect(message.body).to have_content(document_path(@edition.document)) diff --git a/spec/features/workflow/publish_without_review_spec.rb b/spec/features/workflow/publish_without_review_spec.rb index 413517e2d9..caa8a23edc 100644 --- a/spec/features/workflow/publish_without_review_spec.rb +++ b/spec/features/workflow/publish_without_review_spec.rb @@ -76,7 +76,7 @@ def and_the_editors_receive_an_email tos = ActionMailer::Base.deliveries.map(&:to) message = ActionMailer::Base.deliveries.first - expect(tos).to match_array [[@creator.email], [current_user.email]] + expect(tos).to contain_exactly([@creator.email], [current_user.email]) expect(message.body).to have_content("https://www.test.gov.uk/news/banana-pricing-updates") expect(message.body).to have_content(document_path(@edition.document)) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 33c0576b00..2562a49911 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -12,7 +12,7 @@ .to match(%(You can email me here - email123@gmail.com)) end - it "returns a body of text that converts html tags to html entities " do + it "returns a body of text that converts html tags to html entities" do text = "Some html tags

bold paragraph

" expect(helper.escape_and_link(text)) .to match("Some html tags <p><b>bold paragraph</b></p>") diff --git a/spec/jobs/populate_bulk_data_job_spec.rb b/spec/jobs/populate_bulk_data_job_spec.rb index b1f70982e3..7c447deecb 100644 --- a/spec/jobs/populate_bulk_data_job_spec.rb +++ b/spec/jobs/populate_bulk_data_job_spec.rb @@ -9,7 +9,7 @@ it "populates government caches older than 5 minutes" do freeze_time do - repository = instance_double("BulkData::GovernmentRepository") + repository = instance_double(BulkData::GovernmentRepository) allow(BulkData::GovernmentRepository).to receive(:new).and_return(repository) expect(repository).to receive(:populate_cache) .with(older_than: 5.minutes.ago) diff --git a/spec/lib/edition_filter_spec.rb b/spec/lib/edition_filter_spec.rb index 9220ff5306..378334dfc4 100644 --- a/spec/lib/edition_filter_spec.rb +++ b/spec/lib/edition_filter_spec.rb @@ -21,7 +21,7 @@ edition2 = create(:edition, title: "Second", base_path: "/doc_2") editions = described_class.new(user, filters: { title_or_url: " " }).editions - expect(editions).to match_array([edition1, edition2]) + expect(editions).to contain_exactly(edition1, edition2) editions = described_class.new(user, filters: { title_or_url: "Fir" }).editions expect(editions).to eq([edition1]) @@ -38,7 +38,7 @@ edition2 = create(:edition, document_type_id: "type_2") editions = described_class.new(user, filters: { document_type: " " }).editions - expect(editions).to match_array([edition1, edition2]) + expect(editions).to contain_exactly(edition1, edition2) editions = described_class.new(user, filters: { document_type: "type_1" }).editions expect(editions).to eq([edition1]) @@ -49,7 +49,7 @@ edition2 = create(:edition, state: "submitted_for_review") editions = described_class.new(user, filters: { status: " " }).editions - expect(editions).to match_array([edition1, edition2]) + expect(editions).to contain_exactly(edition1, edition2) editions = described_class.new(user, filters: { status: "non-existant" }).editions expect(editions).to be_empty @@ -63,7 +63,7 @@ edition2 = create(:edition, state: "published_but_needs_2i") editions = described_class.new(user, filters: { status: "published" }).editions - expect(editions).to match_array([edition1, edition2]) + expect(editions).to contain_exactly(edition1, edition2) editions = described_class.new(user, filters: { status: "published_but_needs_2i" }).editions expect(editions).to eq([edition2]) @@ -78,10 +78,10 @@ edition3 = create(:edition, tags: { organisations: [org_id2] }) editions = described_class.new(user, filters: { organisation: " " }).editions - expect(editions).to match_array([edition1, edition2, edition3]) + expect(editions).to contain_exactly(edition1, edition2, edition3) editions = described_class.new(user, filters: { organisation: org_id1 }).editions - expect(editions).to match_array([edition1, edition2]) + expect(editions).to contain_exactly(edition1, edition2) end it "filters the editions that get history mode" do @@ -89,10 +89,10 @@ edition2 = create(:edition, :political) editions = described_class.new(user, filters: { gets_history_mode: "yes" }).editions - expect(editions).to match_array([edition2]) + expect(editions).to contain_exactly(edition2) editions = described_class.new(user, filters: { gets_history_mode: "no" }).editions - expect(editions).to match_array([edition1]) + expect(editions).to contain_exactly(edition1) end it "filters the editions that are in history mode" do @@ -102,10 +102,10 @@ edition2 = create(:edition, :political, government: past_government) editions = described_class.new(user, filters: { in_history_mode: "yes" }).editions - expect(editions).to match_array([edition2]) + expect(editions).to contain_exactly(edition2) editions = described_class.new(user, filters: { in_history_mode: "no" }).editions - expect(editions).to match_array([edition1]) + expect(editions).to contain_exactly(edition1) end it "ignores other kinds of filter" do @@ -212,19 +212,19 @@ end context "when the edition's document type is tagged as pre release" do - let!(:edition1) { create(:edition) } - let!(:edition2) { create(:edition, document_type: build(:document_type, :pre_release)) } + let!(:first_edition) { create(:edition) } + let!(:second_edition) { create(:edition, document_type: build(:document_type, :pre_release)) } it "includes the edition for users with pre_release_features permission" do pre_release_user = build(:user) editions = described_class.new(pre_release_user).editions - expect(editions).to match_array([edition1, edition2]) + expect(editions).to contain_exactly(first_edition, second_edition) end it "excludes the edition for users without pre_release_features permission" do user = build(:user, permissions: []) editions = described_class.new(user).editions - expect(editions).to match_array([edition1]) + expect(editions).to contain_exactly(first_edition) end end end diff --git a/spec/lib/requirements/preview/content_checker_spec.rb b/spec/lib/requirements/preview/content_checker_spec.rb index 485c1c7792..1c0dce95a5 100644 --- a/spec/lib/requirements/preview/content_checker_spec.rb +++ b/spec/lib/requirements/preview/content_checker_spec.rb @@ -7,12 +7,12 @@ end it "delegates to return issues with content fields" do - issues = Requirements::CheckerIssues.new(%w[issue]) - body_field = instance_double(DocumentType::BodyField, preview_issues: issues) + expected_issues = Requirements::CheckerIssues.new(%w[issue]) + body_field = instance_double(DocumentType::BodyField, preview_issues: expected_issues) document_type = build :document_type, contents: [body_field] edition = build(:edition, document_type:) - issues = described_class.call(edition) - expect(issues).to eq issues + actual_issues = described_class.call(edition) + expect(actual_issues.issues).to eq expected_issues.issues end end end diff --git a/spec/lib/requirements/publish/content_checker_spec.rb b/spec/lib/requirements/publish/content_checker_spec.rb index 7c44cf32b5..15c5bbb365 100644 --- a/spec/lib/requirements/publish/content_checker_spec.rb +++ b/spec/lib/requirements/publish/content_checker_spec.rb @@ -7,12 +7,12 @@ end it "delegates to return issues with content fields" do - issues = Requirements::CheckerIssues.new(%w[issue]) - body_field = instance_double(DocumentType::BodyField, publish_issues: issues) + expected_issues = Requirements::CheckerIssues.new(%w[issue]) + body_field = instance_double(DocumentType::BodyField, publish_issues: expected_issues) document_type = build :document_type, contents: [body_field] edition = build(:edition, document_type:) - issues = described_class.call(edition) - expect(issues).to eq issues + actual_issues = described_class.call(edition) + expect(actual_issues.issues).to eq expected_issues.issues end it "returns an issue if a major change note is blank" do diff --git a/spec/lib/versioning/revision_updater/file_attachment_spec.rb b/spec/lib/versioning/revision_updater/file_attachment_spec.rb index 872a5d4649..caa1de9e87 100644 --- a/spec/lib/versioning/revision_updater/file_attachment_spec.rb +++ b/spec/lib/versioning/revision_updater/file_attachment_spec.rb @@ -12,7 +12,7 @@ next_revision = updater.next_revision expect(next_revision.file_attachment_revisions) - .to match_array [attachment_revision, new_attachment] + .to contain_exactly(attachment_revision, new_attachment) end it "appends to the ordering when there are featured attachments" do @@ -62,7 +62,7 @@ updater.remove_file_attachment(attachment_revision) next_revision = updater.next_revision - expect(next_revision.file_attachment_revisions).to match_array [other_attachment_revision] + expect(next_revision.file_attachment_revisions).to contain_exactly(other_attachment_revision) end it "updates the ordering when there are featured attachments" do @@ -92,7 +92,7 @@ updater.update_file_attachment(updated_attachment) next_revision = updater.next_revision - expect(next_revision.file_attachment_revisions).to match_array [updated_attachment] + expect(next_revision.file_attachment_revisions).to contain_exactly(updated_attachment) end it "raises an error if there is no file attachment to update" do diff --git a/spec/lib/versioning/revision_updater/image_spec.rb b/spec/lib/versioning/revision_updater/image_spec.rb index 68c5975ead..beb9947263 100644 --- a/spec/lib/versioning/revision_updater/image_spec.rb +++ b/spec/lib/versioning/revision_updater/image_spec.rb @@ -11,7 +11,7 @@ updater.add_image(new_image) next_revision = updater.next_revision - expect(next_revision.image_revisions).to match_array [image_revision, new_image] + expect(next_revision.image_revisions).to contain_exactly(image_revision, new_image) end it "raises an error if the image already exists" do @@ -32,7 +32,7 @@ updater.update_image(updated_image) next_revision = updater.next_revision - expect(next_revision.image_revisions).to match_array [updated_image] + expect(next_revision.image_revisions).to contain_exactly(updated_image) end it "raises an error if there is no image to update" do @@ -126,7 +126,7 @@ updater.remove_image(image_revision) next_revision = updater.next_revision - expect(next_revision.image_revisions).to match_array [other_image_revision] + expect(next_revision.image_revisions).to contain_exactly(other_image_revision) end it "preserves another existing image as the lead" do diff --git a/spec/lib/whitehall_importer/create_edition_spec.rb b/spec/lib/whitehall_importer/create_edition_spec.rb index cc06023ed6..00858b9f05 100644 --- a/spec/lib/whitehall_importer/create_edition_spec.rb +++ b/spec/lib/whitehall_importer/create_edition_spec.rb @@ -269,7 +269,7 @@ def perform_call(**options) ) end - it "sets a previous status of the edition of the publishing status " do + it "sets a previous status of the edition of the publishing status" do edition = perform_call(whitehall_edition:) previous_status, current_status = edition.statuses.order(created_at: :desc) diff --git a/spec/lib/whitehall_importer/create_migration_spec.rb b/spec/lib/whitehall_importer/create_migration_spec.rb index a41ace4c94..8182674b6e 100644 --- a/spec/lib/whitehall_importer/create_migration_spec.rb +++ b/spec/lib/whitehall_importer/create_migration_spec.rb @@ -2,12 +2,12 @@ include ActiveJob::TestHelper describe ".call" do let(:whitehall_host) { Plek.external_url_for("whitehall-admin") } - let(:whitehall_export_page_1) do + let(:first_whitehall_export_page) do build(:whitehall_export_index, documents: build_list(:whitehall_export_index_document, 100)) end - let(:whitehall_export_page_2) do + let(:second_whitehall_export_page) do build(:whitehall_export_index, documents: build_list(:whitehall_export_index_document, 10)) end @@ -15,9 +15,9 @@ context "with organisation and type specified" do before do stub_request(:get, "#{whitehall_host}/government/admin/export/document?lead_organisation=123&page_count=100&page_number=1&type=news_article") - .to_return(status: 200, body: whitehall_export_page_1.to_json) + .to_return(status: 200, body: first_whitehall_export_page.to_json) stub_request(:get, "#{whitehall_host}/government/admin/export/document?lead_organisation=123&page_count=100&page_number=2&type=news_article") - .to_return(status: 200, body: whitehall_export_page_2.to_json) + .to_return(status: 200, body: second_whitehall_export_page.to_json) end it "creates a WhitehallMigration" do @@ -38,7 +38,7 @@ it "sets the content_id on the WhitehallMigration::DocumentImport" do described_class.call("123", "news_article") - expect(WhitehallMigration::DocumentImport.last.content_id).to eq(whitehall_export_page_2["documents"].last["content_id"]) + expect(WhitehallMigration::DocumentImport.last.content_id).to eq(second_whitehall_export_page["documents"].last["content_id"]) end it "queues a job for each listed document" do @@ -50,9 +50,9 @@ context "with organisation, type and subtype specified" do before do stub_request(:get, "#{whitehall_host}/government/admin/export/document?lead_organisation=123&page_count=100&page_number=1&type=news_article&subtypes[]=news_story&subtypes[]=press_release") - .to_return(status: 200, body: whitehall_export_page_1.to_json) + .to_return(status: 200, body: first_whitehall_export_page.to_json) stub_request(:get, "#{whitehall_host}/government/admin/export/document?lead_organisation=123&page_count=100&page_number=2&type=news_article&subtypes[]=news_story&subtypes[]=press_release") - .to_return(status: 200, body: whitehall_export_page_2.to_json) + .to_return(status: 200, body: second_whitehall_export_page.to_json) end it "creates a WhitehallMigration" do diff --git a/spec/lib/whitehall_importer/import_spec.rb b/spec/lib/whitehall_importer/import_spec.rb index 0d76bdfae2..f31a187aa3 100644 --- a/spec/lib/whitehall_importer/import_spec.rb +++ b/spec/lib/whitehall_importer/import_spec.rb @@ -209,7 +209,7 @@ expect { described_class.call(document_import) }.to raise_error("forced error") expect(document_import.changed?).to be false - expect(document_import.document).to be nil + expect(document_import.document).to be_nil end end diff --git a/spec/lib/whitehall_importer/integrity_checker_spec.rb b/spec/lib/whitehall_importer/integrity_checker_spec.rb index 1ec5b940a3..0a2d522e50 100644 --- a/spec/lib/whitehall_importer/integrity_checker_spec.rb +++ b/spec/lib/whitehall_importer/integrity_checker_spec.rb @@ -590,19 +590,19 @@ def problem_description(message, expected, actual) let(:time) { Time.zone.now } it "returns true when times match" do - expect(described_class.time_matches?(time.rfc3339, time.rfc3339)).to eq true + expect(described_class.time_matches?(time.rfc3339, time.rfc3339)).to be true end it "returns true when times are sufficiently similar" do - expect(described_class.time_matches?((time + 4).rfc3339, time.rfc3339)).to eq true + expect(described_class.time_matches?((time + 4).rfc3339, time.rfc3339)).to be true end it "returns false when times are not sufficiently similar" do - expect(described_class.time_matches?((time + 30).rfc3339, time.rfc3339)).to eq false + expect(described_class.time_matches?((time + 30).rfc3339, time.rfc3339)).to be false end it "returns false when times are invalid" do - expect(described_class.time_matches?("Not a time", nil)).to eq false + expect(described_class.time_matches?("Not a time", nil)).to be false end end diff --git a/spec/models/whitehall_migration/asset_import_spec.rb b/spec/models/whitehall_migration/asset_import_spec.rb index 0334b67810..3607216a5f 100644 --- a/spec/models/whitehall_migration/asset_import_spec.rb +++ b/spec/models/whitehall_migration/asset_import_spec.rb @@ -2,22 +2,22 @@ describe ".content_publisher_asset" do it "returns the file attachment asset when associated with one" do asset = build(:whitehall_migration_asset_import, :for_file_attachment) - expect(asset.content_publisher_asset).to be_kind_of(FileAttachment::Asset) + expect(asset.content_publisher_asset).to be_a(FileAttachment::Asset) end it "returns the 960 image asset when associated with an image" do asset = build(:whitehall_migration_asset_import, :for_image) expect(asset.content_publisher_asset) - .to be_kind_of(Image::Asset).and eq(asset.image_revision.asset("960")) + .to be_a(Image::Asset).and eq(asset.image_revision.asset("960")) end it "returns the correct sized image when called on a recognised image size" do image_300_wide = build(:whitehall_migration_asset_import, :for_image, variant: "s300") image_960_wide = build(:whitehall_migration_asset_import, :for_image, variant: "s960") expect(image_300_wide.content_publisher_asset) - .to be_kind_of(Image::Asset).and eq(image_300_wide.image_revision.asset("300")) + .to be_a(Image::Asset).and eq(image_300_wide.image_revision.asset("300")) expect(image_960_wide.content_publisher_asset) - .to be_kind_of(Image::Asset).and eq(image_960_wide.image_revision.asset("960")) + .to be_a(Image::Asset).and eq(image_960_wide.image_revision.asset("960")) end it "returns nil when called on an unrecognised image size" do diff --git a/spec/services/preview_asset_service_spec.rb b/spec/services/preview_asset_service_spec.rb index 88ec42eae6..181aec932b 100644 --- a/spec/services/preview_asset_service_spec.rb +++ b/spec/services/preview_asset_service_spec.rb @@ -16,8 +16,7 @@ end before do - allow(asset).to receive(:draft?).and_return(false) - allow(asset).to receive(:absent?).and_return(true) + allow(asset).to receive_messages(draft?: false, absent?: true) file = PreviewAssetService::UploadedFile.new(asset) payload = instance_double(PreviewAssetService::Payload) @@ -51,8 +50,7 @@ context "when a draft asset is on Asset Manager" do before do - allow(asset).to receive(:draft?).and_return(true) - allow(asset).to receive(:absent?).and_return(false) + allow(asset).to receive_messages(draft?: true, absent?: false) payload = instance_double(PreviewAssetService::Payload) allow(payload).to receive(:for_update).and_return(foo: "bar") @@ -80,8 +78,7 @@ context "when a live asset is on Asset Manager" do it "does not update the asset" do request = stub_asset_manager_update_asset("id") - allow(asset).to receive(:draft?).and_return(false) - allow(asset).to receive(:absent?).and_return(false) + allow(asset).to receive_messages(draft?: false, absent?: false) described_class.call(edition, asset) expect(request).not_to have_been_requested end