-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rake task to report on a regex in editionable content
Sometimes we want to identify which published content matches a regular expression (e.g. if we make a change to govspeak and need to republish affected content). Therefore adding a rake task that will report on the content that includes a given regex in the currently published edition. This is being broken down into batches of 1000, as our infrastructure does not support large queries being made on a Rails console.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "test_helper" | ||
require "rake" | ||
|
||
class ReportingRake < ActiveSupport::TestCase | ||
setup do | ||
@document_1 = create(:published_edition, body: "Some text 1") | ||
@document_2 = create(:draft_edition, body: "Some text 2") | ||
@document_3 = create(:published_edition, body: "Some other text 1") | ||
end | ||
|
||
teardown do | ||
Rake::Task["reporting:matching_docs"].reenable | ||
end | ||
|
||
test "it prints the content IDs of the matching documents from published editions" do | ||
assert_output(/#{@document_1.document.content_id}/) { Rake.application.invoke_task "reporting:matching_docs[Some text]" } | ||
end | ||
|
||
test "it does not print the content IDs of the matching documents from draft editions" do | ||
assert_output(/^(?!.*#{@document_2.document.content_id}).*$/) { Rake.application.invoke_task "reporting:matching_docs[Some text]" } | ||
end | ||
|
||
test "it does not print the content IDs of the non-matching documents from published editions" do | ||
assert_output(/^(?!.*#{@document_3.document.content_id}).*$/) { Rake.application.invoke_task "reporting:matching_docs[Some text]" } | ||
end | ||
end |