diff --git a/app/models/observation.rb b/app/models/observation.rb index 7364031ce2..8a539011b1 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -915,6 +915,10 @@ def self.no_notes {} end + def notes + self[:notes] || {} + end + # no_notes persisted in the db def self.no_notes_persisted no_notes.to_yaml @@ -1172,14 +1176,13 @@ def turn_off_specimen_if_no_more_records ############################################################################## # Which agent created this observation? - enum source: - { - mo_website: 1, - mo_android_app: 2, - mo_iphone_app: 3, - mo_api: 4, - mo_inat_import: 5 - } + enum :source, { + mo_website: 1, + mo_android_app: 2, + mo_iphone_app: 3, + mo_api: 4, + mo_inat_import: 5 + } # Message to use to credit the agent which created this observation. # Intended to be used with .tpl to render as HTML: diff --git a/test/models/observation_test.rb b/test/models/observation_test.rb index d3e6524fbf..fb8f4feb87 100644 --- a/test/models/observation_test.rb +++ b/test/models/observation_test.rb @@ -917,6 +917,19 @@ def test_notes_parts_values assert_equal("pine", obs.notes_part_value("Nearby trees")) end + def test_notes_nil + User.current = mary + obs = Observation.create!(name_id: names(:fungi).id, when_str: "2020-07-05") + + assert_nothing_raised do + obs.notes[:Collector] + rescue StandardError => e + flunk( + "It shouldn't throw \"#{e.message}\" when reading part of a nil Note" + ) + end + end + def test_make_sure_no_observations_are_misspelled good = names(:peltigera) bad = names(:petigera)