Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def published?(name)
# Implicitly hidden
field = child_collection.schema[:fields][name]

if field.nil?
message = "Field '#{name}' not found in schema of collection '#{self.name}'"
ForestAdminAgent::Facades::Container.logger.log('Warn', message)
return false
end

if field.type == 'ManyToOne'
return (
datasource.published?(field.foreign_collection) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ module Publication
expect(@decorated_person.schema[:fields]).to have_key('my_book_person')
end
end

context 'when the relations is unknown (type nil)' do
it 'logs a warning and returns false when the field is not found in the schema' do
logger = instance_spy(Logger)
allow(ForestAdminAgent::Facades::Container).to receive(:logger).and_return(logger)

result = @decorated_book.published?('unknown_field')

expect(logger).to have_received(:log).with('Warn', "Field 'unknown_field' not found in schema of collection 'book'")
expect(result).to be(false)
end
end
end
end
end
Expand Down