-
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 SearchByLeadOrganisation to Content Block Documents
- Loading branch information
Showing
3 changed files
with
33 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
12 changes: 12 additions & 0 deletions
12
...ls/content_block_manager/content_block/document/scopes/searchable_by_lead_organisation.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,12 @@ | ||
module ContentBlockManager | ||
module ContentBlock::Document::Scopes::SearchableByLeadOrganisation | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :with_lead_organisation, | ||
lambda { |id| | ||
joins(latest_edition: :edition_organisation).where("content_block_edition_organisations.organisation_id = :id", id:) | ||
} | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
.../app/models/content_block_edition/document/scopes/searchable_by_lead_organisation_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,20 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::SearchableByLeadOrganisationTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
describe ".with_lead_organisation" do | ||
test "finds documents with lead organisation on latest edition" do | ||
matching_organisation = create(:organisation, id: "1234") | ||
document_with_org = create(:content_block_document, :email_address) | ||
_edition_with_org = create(:content_block_edition, | ||
:email_address, | ||
document: document_with_org, | ||
organisation: matching_organisation) | ||
document_without_org = create(:content_block_document, :email_address) | ||
_edition_without_org = create(:content_block_edition, :email_address, document: document_without_org) | ||
_document_without_latest_edition = create(:content_block_document, :email_address) | ||
assert_equal [document_with_org], ContentBlockManager::ContentBlock::Document.with_lead_organisation("1234") | ||
end | ||
end | ||
end |