Skip to content

Commit

Permalink
More detailed test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCohen committed Aug 3, 2024
1 parent e37639e commit 1f3f289
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/observations/inat_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def inat_manager_key
end

def inat_manager
User.where(login: "MO Webmaster").first
User.find_by(login: "MO Webmaster")
end

def add_namings(inat_obs)
Expand Down
47 changes: 41 additions & 6 deletions test/controllers/observations/inat_imports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,46 @@ def test_import_tremella_mesenterica
end

def test_import_namings
# This iNat id has two identifications:
# Tremella mesenterica, which in is fixtures
# "Naematelia aurantia, which is not
Name.new(text_name: "Naematelia aurantia",
author: "(Schwein.) Burt",
display_name: "Naematelia aurantia",
rank: "Species",
user: rolf).save
# iNat Community Taxon, which is not an identification for this iNat obs
Name.new(text_name: "Tremellales",
author: "Fr.",
display_name: "Tremellales",
rank: "Order",
user: rolf).save

tremellales = Name.find_by(text_name: "Tremellales")
t_mesenterica = Name.find_by(text_name: "Tremella mesenterica")
n_aurantia = Name.find_by(text_name: "Naematelia aurantia")

obs = import_mock_observation("tremella_mesenterica")

# iNat obs has two namings:
# Tremella mesenterica, by the obs creator
# Naematelia aurantia (maps to Fungi in tests) by another iNat user
assert_equal(tremellales, obs.name)

namings = obs.namings
assert_equal(2, namings.length)
assert_equal(obs.user, namings.first.user)
assert_equal(users(:webmaster), namings.last.user)
assert_includes(
namings, namings.find_by(name: t_mesenterica),
"Missing Proposed Name by MO User who is doing the import"
)
assert_includes(
namings, namings.find_by(name: t_mesenterica, user: User.current),
"Proposed Name has wrong User"
)
assert_includes(
namings, namings.find_by(name: n_aurantia),
"Missing Proposed Name by iNat user who isn't doing the import"
)
assert_includes(
namings, namings.find_by(name: n_aurantia, user: inat_manager),
"Proposed Name has wrong User"
)
end

def test_import_lycoperdon
Expand Down Expand Up @@ -296,6 +327,10 @@ def test_import_all
end
end

def inat_manager
User.find_by(login: "MO Webmaster")
end

# Turn results with many pages into results with one page
# By ignoring all pages but the first
def limited_to_first_page(mock_search_result)
Expand Down

0 comments on commit 1f3f289

Please sign in to comment.