Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions app/controllers/placements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ def new
Placement.new(
name: @name, preferred: true, parent: @name.parent,
publication: @name.assigned_in,
incertae_sedis: @name.incertae_sedis,
incertae_sedis_text: @name.incertae_sedis_text
).save!
end

unless @name.placement
@placement.parent = @name.parent
@placement.publication = @name.assigned_in
@placement.incertae_sedis = @name.incertae_sedis
@placement.incertae_sedis_text = @name.incertae_sedis_text
@placement.preferred = true
end
end
Expand Down Expand Up @@ -108,7 +104,6 @@ def create_or_update(back_action)
end
@name.update!(
parent: @placement.parent, assigned_in: @placement.publication,
incertae_sedis: nil, incertae_sedis_text: nil
)
end
rescue
Expand All @@ -130,8 +125,8 @@ def prefer
@name.placement.try(:update!, preferred: false)
@placement.update!(preferred: true)
@name.update!(
parent: @placement.parent, assigned_in: @placement.publication,
incertae_sedis: nil, incertae_sedis_text: nil
parent: @placement.parent,
assigned_in: @placement.publication
)
ok = true
end
Expand Down
38 changes: 5 additions & 33 deletions app/models/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Name < ApplicationRecord
:placements, -> { includes(:parent) },
dependent: :destroy, inverse_of: :name
)
delegate(
:incertae_sedis, :incertae_sedis?, :incertae_sedis_html,
:incertae_sedis_text, to: :placement, allow_nil: true
)
has_many(
:child_placements, -> { includes(:name) },
class_name: 'Placement', foreign_key: 'parent_id', dependent: :destroy
Expand Down Expand Up @@ -115,7 +119,6 @@ class Name < ApplicationRecord
has_rich_text(:description)
has_rich_text(:notes)
has_rich_text(:etymology_text)
has_rich_text(:incertae_sedis_text) # deprecated, but values still in DB

validates(:name, presence: true, uniqueness: true)
validates(
Expand All @@ -125,13 +128,6 @@ class Name < ApplicationRecord
message: 'can only contain letters, dashes, dots, and apostrophe'
}
)
validates(:incertae_sedis, presence: true, allow_nil: true)
validates(
:incertae_sedis, absence: {
if: :parent,
message: 'cannot be declared if the parent taxon is set'
}
)
validates(
:nomenclatural_type_type,
presence: {
Expand Down Expand Up @@ -1001,12 +997,6 @@ def type_name_alt_placement
place if place != self
end

def incertae_sedis_html
return '' unless incertae_sedis?

incertae_sedis.gsub(/(incertae sedis)/i, '<i>\\1</i>').html_safe
end

def inferred_rank
@inferred_rank ||=
if rank?
Expand Down Expand Up @@ -1175,18 +1165,6 @@ def propose_lineage_name(rank)
end
end

def incertae_sedis_explain
(placement || self).incertae_sedis_text
end

def incertae_sedis
placement ? placement.incertae_sedis : self[:incertae_sedis]
end

def incertae_sedis?
incertae_sedis.present?
end

def taxonomic_data?
description? || notes? || parent || incertae_sedis? ||
taxonomic_status? || !children.empty? || !alt_child_placements.empty?
Expand Down Expand Up @@ -1481,12 +1459,7 @@ def harmonize_register_and_status
end

def ensure_consistent_placement
placement_incertae_sedis =
if saved_change_to_incertae_sedis?
self[:incertae_sedis]
else
incertae_sedis
end
placement_incertae_sedis = incertae_sedis

if parent_id.present? || placement_incertae_sedis.present?
pp = placements.where(
Expand All @@ -1504,7 +1477,6 @@ def ensure_consistent_placement
name_id: id,
parent_id: parent_id,
incertae_sedis: placement_incertae_sedis,
incertae_sedis_text: incertae_sedis_text,
preferred: true
).save
end
Expand Down
24 changes: 18 additions & 6 deletions app/models/tutorial/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def batch_step_01(params, user)
default_pars = { status: 0, created_by: user }
param_names.each do |par|
new_par = {}
placement_par = nil

# Parents
if par['parent']
Expand All @@ -356,12 +357,16 @@ def batch_step_01(params, user)
parent = Name.new(default_pars.merge(name: par['parent'].name))
parent.save!
end
new_par[:parent] = parent
new_par[:incertae_sedis] = nil
placement_par = {
parent: parent,
incertae_sedis: nil
}
elsif par['incertae_sedis']
new_par[:parent] = nil
new_par[:incertae_sedis] = par['incertae_sedis']
new_par[:incertae_sedis_text] = par['description']
placement_par = {
parent: nil,
incertae_sedis: par['incertae_sedis'],
incertae_sedis_text: par['description']
}
end

# Nomenclatural types
Expand All @@ -384,7 +389,14 @@ def batch_step_01(params, user)

name = Name.find_by_variants(par['name'])
name.update!(new_par)
name.update_column(:incertae_sedis, nil) if par['incertae_sedis']
if placement_par

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to review if we can do this a bit simpler/re-use existing code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not great, but I think it is easier to handle it after we are done with the incertae sedis-related changes. Then we can either go with the Name#preferred_placement proposal or implement some shared Name#set_preferred_placement method.

placement = name.placements.find_or_initialize_by(
parent: placement_par[:parent],
incertae_sedis: placement_par[:incertae_sedis]
)
name.placements.where.not(id: placement.id).update_all(preferred: false)
placement.update!(placement_par.merge(preferred: true))
end
end

# If all is good, go to next step
Expand Down
2 changes: 1 addition & 1 deletion app/views/names/_taxonomy.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<% if @name.incertae_sedis? %>
<div class="border-left px-3">
<b><%= @name.incertae_sedis_html %>:</b>
<%= @name.incertae_sedis_explain %>
<%= @name.incertae_sedis_text %>
</div>
<% elsif @name.parent %>
<%= display_link(@name.parent, :name_html_correctness) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/registers/table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<td>
<% if name.incertae_sedis? %>
<b><%= name.incertae_sedis_html %>:</b>
<%= name.incertae_sedis_explain %>
<%= name.incertae_sedis_text %>
<% elsif !name.parent %>
<u>Unknown</u>
<% elsif @register.names.include? name %>
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20260819100000_remove_incertae_sedis_from_names.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# Removes the legacy incertae sedis attributes now represented by placements.
class RemoveIncertaeSedisFromNames < ActiveRecord::Migration[6.1]
def up
execute <<~SQL.squish
DELETE FROM action_text_rich_texts
WHERE record_type = 'Name'
AND name = 'incertae_sedis_text'
SQL

remove_column :names, :incertae_sedis, :string if column_exists?(:names, :incertae_sedis)
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2026_08_08_100000) do
ActiveRecord::Schema.define(version: 2026_08_19_100000) do

# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
Expand Down Expand Up @@ -234,7 +234,6 @@
t.datetime "irmng_at"
t.text "col_json"
t.datetime "col_at"
t.string "incertae_sedis"
t.bigint "tutorial_id"
t.bigint "genome_id"
t.text "gbif_json"
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/names.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ bacillales:
rank: order
status: 15 # SeqCode

nanobdellaceae:
name: Nanobdellaceae
rank: family
status: 15 # SeqCode

nanoclepta_minutus:
name: Nanoclepta minutus
rank: species
status: 15 # SeqCode

luteria_ianthellae:
name: Luteria ianthellae
rank: species
status: 15 # SeqCode

incertae_sedis:
name: Escherichia marmotae
rank: species
status: 15 # SeqCode

type_genome_with_locations:
name: Testimonas mappensis
rank: species
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/placements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ escherichia_coli:
name: escherichia_coli
parent: escherichia
preferred: true

incertae_sedis:
name: incertae_sedis
preferred: true
incertae_sedis: Incertae sedis (Bacteria)
8 changes: 8 additions & 0 deletions test/models/name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ class NameTest < ActiveSupport::TestCase
assert_includes name.errors[:register], 'must be a draft'
assert_nil name.reload.register
end

test 'incertae sedis HTML comes from the preferred placement' do
name = names(:incertae_sedis)

assert_equal(
'<i>Incertae sedis</i> (Bacteria)', name.incertae_sedis_html
)
end
end
Loading