Eno::Section ยป #assert_all_touched
assert_all_touched
assert_all_touched(options)
assert_all_touched(message, options)
assert_all_touched(message_proc, options)
assert_all_touched(options) { |name, value| message_block }
Assert that all elements of this section (and also, recursively, of all subsections) that were present in the parsed eno document were also queried (and therefore touched) by the application. This, combined with eno's query methods, serves to ensure a two-way guarantee for both users and developers: No data that the application requires can be left out, and no data that the application does not process can be supplied.
enoImportant data A: I need to be processed!
Important data B: Me too!
rubydocument = Eno.parse(input)
data_a = document.field('Important data A')
# ... processing happens only for data_a
document.assert_all_touched # raises an error with the default message
document.assert_all_touched(only: ['Important data A']) # passes
document.assert_all_touched(except: ['Important data B']) # passes
document.assert_all_touched do |name, value| # raises an error "Important data B is not ..."
"#{name} is not supported by the application, please contact support if you think it should be"
end
Parameters
message, message_proc or message_blockOptional, usually the default message (An excess element named [NAME] was
found, is it possibly a typo?) will do fine. If you want to override it,
provide either a static message as a string, or alternatively a Proc
or block
returning a string. (The arguments passed are name
and value
, although
value
can be nil
if the untouched element is a fieldset or section)
only
An array of strings, e.g. ['name', 'email']
, which specifies to only check these elements for whether they've been touched.
except
An array of strings, e.g. ['phone number']
, which specifies to exclude these elements from checking whether they've been touched.