diff --git a/app/controllers/observations/inat_imports_controller.rb b/app/controllers/observations/inat_imports_controller.rb index f96d0ae2ef..bf7ffd2ae5 100644 --- a/app/controllers/observations/inat_imports_controller.rb +++ b/app/controllers/observations/inat_imports_controller.rb @@ -220,13 +220,12 @@ def import_one_result(result) add_inat_images(inat_obs.inat_obs_photos) add_namings(inat_obs) - + add_inat_sequences(inat_obs) + add_inat_summmary_data(inat_obs) # TODO: Other things done by Observations#create # save_everything_else(params.dig(:naming, :reasons)) # strip_images! if @observation.gps_hidden # update_field_slip(@observation, params[:field_code]) - add_inat_sequences(inat_obs) - add_inat_summmary_data(inat_obs) end def inat_import @@ -304,6 +303,7 @@ def add_namings(inat_obs) user: user, value: 0).save end + add_provisional_namings(inat_obs) adjust_consensus_name_naming end @@ -325,7 +325,33 @@ def naming_user(identification) end end + def add_provisional_namings(inat_obs) + nom_prov = inat_obs.provisional_name + return if nom_prov.blank? + + mo_counterpart = Name.where(text_name: nom_prov) + return if mo_counterpart.many? + + if mo_counterpart.none? + # TO_DO: include sort name + mo_counterpart = + Name.create( + text_name: nom_prov, author: "crypt. temp.", + display_name: "**__#{nom_prov}__** crypt. temp.", + rank: "Species", + user: inat_manager + ) + end + + # If iNat user created a provisional name, make it the MO consensus, and + # let the calling method (add_namings) add a Naming and Vote + @observation.name = mo_counterpart + @observation.text_name = nom_prov + @observation.save + end + def adjust_consensus_name_naming + debugger naming = Naming.find_by(observation: @observation, name: @observation.name) diff --git a/test/controllers/observations/inat_imports_controller_test.rb b/test/controllers/observations/inat_imports_controller_test.rb index c94e536cdd..a55266768f 100644 --- a/test/controllers/observations/inat_imports_controller_test.rb +++ b/test/controllers/observations/inat_imports_controller_test.rb @@ -245,6 +245,30 @@ def test_import_lycoperdon assert(obs.sequences.one?, "Obs should have a sequence") end + def test_import_arrhenia_sp_NY02 # rubocop:disable Naming/MethodName + skip("under construction") + user = rolf + name = Name.new( + text_name: 'Arrhenia "sp-NY02"', + author: "S.D. Russell crypt. temp.", + display_name: '**__Arrhenia "sp-NY02"__** S.D. Russell crypt. temp.', + rank: "Species", + user: user + ) + + obs = import_mock_observation("arrhenia_sp_NY02") + + namings = obs.namings + naming = namings.find_by(name: name) + assert(naming.present?, "Missing Naming for provisional name") + assert_equal(inat_manager, naming.user, + "Naming without iNat ID should have user: inat_manager") + vote = Vote.find_by(naming: naming, user: naming.user) + assert(vote.present?, "Naming is missing a Vote") + assert_equal(name, obs.name, "Consensus ID should be provisional name") + assert(vote.value.positive?, "Vote for MO consensus should be positive") + end + def test_import_plant user = rolf filename = "ceanothus_cordulatus"