-
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.
search by keyword in details and title of Content Block
This now matches keywords agains the user generated free text on a block. Select options will be added for Organisation, date etc. If any other free text options were added (such as internal instructions, description) we'd need to add them to this keyword match here too.
- Loading branch information
Showing
11 changed files
with
101 additions
and
58 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
2 changes: 1 addition & 1 deletion
2
lib/engines/content_block_manager/app/models/content_block_manager/content_block/document.rb
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
18 changes: 18 additions & 0 deletions
18
...r/app/models/content_block_manager/content_block/document/scopes/searchable_by_keyword.rb
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,18 @@ | ||
module ContentBlockManager | ||
module ContentBlock::Document::Scopes::SearchableByKeyword | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :with_keyword, | ||
lambda { |keywords| | ||
split_keywords = keywords.split | ||
pattern = split_keywords.map { |k| | ||
escaped_word = Regexp.escape(k) | ||
"(?=.*#{escaped_word})" | ||
}.join | ||
joins(:latest_edition) | ||
.where("content_block_documents.title REGEXP :pattern OR content_block_editions.details REGEXP :pattern", pattern:) | ||
} | ||
end | ||
end | ||
end |
18 changes: 0 additions & 18 deletions
18
...ger/app/models/content_block_manager/content_block/document/scopes/searchable_by_title.rb
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
..._manager/app/views/content_block_manager/content_block/documents/_filter_options.html.erb
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
<%= form_with url: content_block_manager.content_block_manager_content_block_documents_path, method: :get do %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Title", | ||
text: "Keyword", | ||
bold: true, | ||
}, | ||
hint: 'For example, "driving standards"', | ||
name: "title", | ||
id: "title_filter", | ||
value: [email protected]? && @filters[:title], | ||
name: "keyword", | ||
id: "keyword_filter", | ||
value: [email protected]? && @filters[:keyword], | ||
} %> | ||
<%= render "govuk_publishing_components/components/button", { | ||
|
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 |
---|---|---|
|
@@ -187,16 +187,17 @@ | |
@content_blocks.push(@content_block) | ||
end | ||
|
||
Given("an email address content block has been created with the title {string}") do |title| | ||
Given("an email address content block has been created with the following email address and title:") do |table| | ||
fields = table.rows_hash | ||
@content_blocks ||= [] | ||
@email_address = "[email protected]" | ||
organisation = create(:organisation) | ||
document = create(:content_block_document, :email_address, title:) | ||
document = create(:content_block_document, :email_address, title: fields[:title]) | ||
@content_block = create( | ||
:content_block_edition, | ||
:email_address, | ||
document:, | ||
details: { email_address: @email_address }, | ||
details: { email_address: fields[:email_address] }, | ||
creator: @user, | ||
organisation:, | ||
) | ||
|
@@ -476,8 +477,8 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ | |
fill_in_date_and_time_field(past_date) | ||
end | ||
|
||
When("I enter the title {string}") do |title| | ||
fill_in "Title", with: title | ||
When("I enter the keyword {string}") do |keyword| | ||
fill_in "Keyword", with: keyword | ||
end | ||
|
||
Then("the edition should have been scheduled successfully") do | ||
|
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
52 changes: 52 additions & 0 deletions
52
.../test/unit/app/models/content_block_edition/document/scopes/searchable_by_keyword_test.rb
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,52 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::SearchableByKeywordTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
describe ".with_keyword" do | ||
test "should find documents with title containing keyword" do | ||
document_with_first_keyword = create(:content_block_document, :email_address, title: "klingons and such") | ||
_edition_with_first_keyword = create(:content_block_edition, | ||
:email_address, | ||
document: document_with_first_keyword, | ||
details: { "email_address" => "[email protected]" }) | ||
document_without_first_keyword = create(:content_block_document, :email_address, title: "this document is about muppets") | ||
_edition_without_first_keyword = create(:content_block_edition, :email_address, document: document_without_first_keyword) | ||
assert_equal [document_with_first_keyword], ContentBlockManager::ContentBlock::Document.with_keyword("klingons") | ||
end | ||
|
||
test "should find documents with title containing keywords not in order" do | ||
document_with_first_keyword = create(:content_block_document, :email_address, title: "klingons and such") | ||
_edition_with_first_keyword = create(:content_block_edition, | ||
:email_address, | ||
document: document_with_first_keyword, | ||
details: { "email_address" => "[email protected]" }) | ||
_document_without_first_keyword = create(:content_block_document, :email_address, title: "muppets and such") | ||
assert_equal [document_with_first_keyword], ContentBlockManager::ContentBlock::Document.with_keyword("such klingons") | ||
end | ||
|
||
test "should find documents with latest edition's details containing keyword" do | ||
document_with_first_keyword = create(:content_block_document, :email_address, title: "example title") | ||
_edition_with_first_keyword = create(:content_block_edition, | ||
document: document_with_first_keyword, | ||
details: { "foo" => "Foo text", "bar" => "Bar text" }) | ||
document_without_first_keyword = create(:content_block_document, :email_address, title: "this document is about muppets") | ||
_edition_without_first_keyword = create(:content_block_edition, | ||
document: document_without_first_keyword, | ||
details: { "something" => "something" }) | ||
assert_equal [document_with_first_keyword], ContentBlockManager::ContentBlock::Document.with_keyword("foo bar") | ||
end | ||
|
||
test "should find documents with details or title containing keyword" do | ||
document_with_keyword_in_details = create(:content_block_document, :email_address, title: "example title") | ||
_edition_with_keyword = create(:content_block_edition, | ||
document: document_with_keyword_in_details, | ||
details: { "foo" => "Foo text", "bar" => "Bar text" }) | ||
document_with_keyword_in_title = create(:content_block_document, :email_address, title: "this document is about bar foo") | ||
_edition_without_keyword = create(:content_block_edition, | ||
document: document_with_keyword_in_title, | ||
details: { "something" => "something" }) | ||
assert_equal [document_with_keyword_in_details, document_with_keyword_in_title], ContentBlockManager::ContentBlock::Document.with_keyword("foo bar") | ||
end | ||
end | ||
end |
21 changes: 0 additions & 21 deletions
21
...er/test/unit/app/models/content_block_edition/document/scopes/searchable_by_title_test.rb
This file was deleted.
Oops, something went wrong.