Skip to content

Commit

Permalink
Fix tests for rubocop and assertions
Browse files Browse the repository at this point in the history
Ran some automations to fix rubocop.
Fix some assertions which were testing the wrong objects due to variable declarations.
  • Loading branch information
lauraghiorghisor-tw authored and minhngocd committed Jul 2, 2024
1 parent b78900a commit eb5e8f4
Show file tree
Hide file tree
Showing 33 changed files with 71 additions and 74 deletions.
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_content/govspeak_preview_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_content/insert_contact_embed_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_content/insert_inline_image_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_content/insert_video_embed_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_content/url_preview_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_images/choose_lead_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_images/delete_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_images/edit_image_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_images/remove_lead_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_images/upload_image_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/editing_topics/edit_topics_search_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/workflow/publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion spec/features/workflow/publish_without_review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.to match(%(You can email me here - <a href=\"mailto:[email protected]\" class="govuk-link">[email protected]</a>))
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 <p><b>bold paragraph</b></p>"
expect(helper.escape_and_link(text))
.to match("Some html tags &lt;p&gt;&lt;b&gt;bold paragraph&lt;/b&gt;&lt;/p&gt;")
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/populate_bulk_data_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions spec/lib/edition_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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])
Expand All @@ -78,21 +78,21 @@
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
edition1 = create(:edition, :not_political)
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/requirements/preview/content_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions spec/lib/requirements/publish/content_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/versioning/revision_updater/file_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/versioning/revision_updater/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/whitehall_importer/create_edition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit eb5e8f4

Please sign in to comment.