Skip to content

Commit

Permalink
add SearchByLeadOrganisation to Content Block Documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Harriethw committed Oct 25, 2024
1 parent d6bba6f commit 4fbbba2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ContentBlockManager
module ContentBlock
class Document < ApplicationRecord
include Scopes::SearchableByKeyword
include Scopes::SearchableByLeadOrganisation

extend FriendlyId
friendly_id :title, use: :slugged, slug_column: :content_id_alias, routes: :default
Expand Down
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
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

0 comments on commit 4fbbba2

Please sign in to comment.