Skip to content

Commit

Permalink
Draft controller test for provisional names
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCohen committed Aug 6, 2024
1 parent 4e8049c commit c366ad0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
32 changes: 29 additions & 3 deletions app/controllers/observations/inat_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions test/controllers/observations/inat_imports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c366ad0

Please sign in to comment.