diff --git a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition/documentable.rb b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition/documentable.rb index 3e6fb23860e..c34506714f7 100644 --- a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition/documentable.rb +++ b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition/documentable.rb @@ -12,19 +12,12 @@ module ContentBlock::Edition::Documentable end def block_type - document&.block_type || @block_type + @block_type ||= document&.block_type end def ensure_presence_of_document - if document.blank? - self.document = ContentBlock::Document.new( - content_id: create_random_id, - block_type: @block_type, - sluggable_string: title, - ) - elsif document.new_record? + if document.new_record? document.content_id = create_random_id if document.content_id.blank? - document.block_type = @block_type if document.block_type.blank? document.sluggable_string = title if document.sluggable_string.blank? end end diff --git a/lib/engines/content_block_manager/test/unit/app/validators/organisation_validator_test.rb b/lib/engines/content_block_manager/test/unit/app/validators/organisation_validator_test.rb index 5c779cddf7b..7877c0b6fad 100644 --- a/lib/engines/content_block_manager/test/unit/app/validators/organisation_validator_test.rb +++ b/lib/engines/content_block_manager/test/unit/app/validators/organisation_validator_test.rb @@ -4,7 +4,7 @@ class ContentBlockManager::OrganisationValidatorTest < ActiveSupport::TestCase extend Minitest::Spec::DSL test "it validates presence of a lead organisation" do - content_block_edition = build(:content_block_edition, organisation: nil) + content_block_edition = build(:content_block_edition, organisation: nil, document: build(:content_block_document, :email_address)) assert_equal false, content_block_edition.valid? assert_equal ["cannot be blank"], content_block_edition.errors.messages[:lead_organisation]