Skip to content

Commit

Permalink
Fix #1159, #1747
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Sep 18, 2020
1 parent f31a672 commit f9b693a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv
- Override browser shortcuts on task hotkeys [#1738]

## Fixed
- Matrix rows/items prevent OTU (and collection object) from being destroyed [#1159]
- Scope of dynamic taxon name row item [#1747]
- Processing of values (in distance_in_meters) to limit significant digits of results of unit conversions. Decimal degrees not affected at this time. [#1512]
- Character state order not correct in Nexus format [#1574]
- Not able to destroy matrix rows or matrices [#1520], [#1123]
Expand All @@ -49,6 +51,9 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv
- Enable search button after pick a collecting event date on Filter collection objects task [#1728]
- Misppeling collecting_event_ids parameter [#1729]


[#1159]: https://github.com/SpeciesFileGroup/taxonworks/issues/1159
[#1747]: https://github.com/SpeciesFileGroup/taxonworks/issues/1747
[#1512]: https://github.com/SpeciesFileGroup/taxonworks/issues/1512
[#1526]: https://github.com/SpeciesFileGroup/taxonworks/issues/1526
[#1727]: https://github.com/SpeciesFileGroup/taxonworks/issues/1727
Expand Down
2 changes: 1 addition & 1 deletion app/models/collecting_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class CollectingEvent < ApplicationRecord
has_many :georeferences, dependent: :destroy
has_many :error_geographic_items, through: :georeferences, source: :error_geographic_item
has_many :geographic_items, through: :georeferences # See also all_geographic_items, the union
has_many :geo_locate_georeferences, class_name: 'Georeference::GeoLocate', dependent: :destroy
has_many :geo_locate_georeferences, class_name: '::Georeference::GeoLocate', dependent: :destroy
has_many :gpx_georeferences, class_name: 'Georeference::GPX', dependent: :destroy

has_many :otus, through: :collection_objects
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/shared/matrix_hooks/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def out_of_scope_observation_matrix_row_items
[]
end


def in_scope_observation_matrix_column_items
[]
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/otu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class Otu < ApplicationRecord

has_many :content_topics, through: :contents, source: :topic

has_many :observation_matrix_row_items, inverse_of: :otu, dependent: :destroy, class_name: 'ObservationMatrixRowItem::Single::Otu'
has_many :observation_matrix_rows, inverse_of: :collection_object
has_many :observation_matrix_row_items, inverse_of: :otu, dependent: :delete_all, class_name: 'ObservationMatrixRowItem::Single::Otu'
has_many :observation_matrix_rows, inverse_of: :collection_object, dependent: :delete_all
has_many :observation_matrices, through: :observation_matrix_rows

has_many :observations, inverse_of: :otu, dependent: :restrict_with_error
Expand Down
2 changes: 1 addition & 1 deletion app/models/tag/matrix_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Tag::MatrixHooks
end
end

after_destroy :purge_from_matrices, if: -> { %w{Descriptor Otu CollectionObject}.include? tag_object_type }
after_destroy :purge_from_matrices, if: -> { %w{Descriptor Otu CollectionObject}.include? tag_object_type } # was cleanup_matrices

end

Expand Down
2 changes: 1 addition & 1 deletion app/models/taxon_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def self.parent
# TODO: think of a different name, and test
has_many :historical_taxon_names, class_name: 'TaxonName', foreign_key: :cached_valid_taxon_name_id

has_many :observation_matrix_row_items, inverse_of: :taxon_name, class_name: 'ObservationMatrixRowItem::Dynamic::TaxonName', dependent: :destroy
has_many :observation_matrix_row_items, inverse_of: :taxon_name, class_name: 'ObservationMatrixRowItem::Dynamic::TaxonName', dependent: :delete_all
has_many :observation_matrices, through: :observation_matrix_row_items


Expand Down
7 changes: 3 additions & 4 deletions app/models/taxon_name/matrix_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ def coordinate_observation_matrix_row_items
end

def in_scope_observation_matrix_row_items
return [] unless parent_id_changed? && parent_id_change.first
return [] unless parent_id_changed?
TaxonName.find(parent_id_change.last).coordinate_observation_matrix_row_items
end

def out_of_scope_observation_matrix_row_items
return [] unless parent_id_changed? && parent_id_change.last
TaxonName.find(parent_id_change.compact.first).coordinate_observation_matrix_row_items
return [] unless parent_id_changed? && parent_id_change.first
TaxonName.find(parent_id_change.first).coordinate_observation_matrix_row_items
end

end

28 changes: 21 additions & 7 deletions spec/models/taxon_name/matrix_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@
end
end

context 'add species' do
let!(:d) { ::ObservationMatrixRowItem::Dynamic::TaxonName.create!( observation_matrix: observation_matrix, taxon_name: genus1 )}
let!(:species2) { Protonym.create!(name: 'gus', parent: genus1, rank_class: Ranks.lookup(:iczn, :species)) }
let!(:otu2) { Otu.create!(taxon_name: species2) }

specify 'adding species to scope 1' do
expect(observation_matrix.observation_matrix_rows.count).to eq(2)
end

specify 'adding species to scope 2' do
expect(observation_matrix.observation_matrix_rows.map(&:otu)).to contain_exactly(otu, otu2)
end

specify 'otus can be destroyed' do
expect(otu2.destroy!).to be_truthy
end
end

context 'dynamic' do
let!(:species2) { Protonym.create!(name: 'gus', parent: genus2, rank_class: Ranks.lookup(:iczn, :species)) }

Expand All @@ -77,11 +95,6 @@
expect(species2.in_scope_observation_matrix_row_items).to contain_exactly(d)
end

specify '#out_of_scope_observation_matrix_row_items' do
species2.parent_id = genus2.id
expect(species2.out_of_scope_observation_matrix_row_items).to contain_exactly()
end

specify '#dynamic_update_matrix_row_items' do
expect(species2.dynamic_update_matrix_row_items?).to be_falsey
end
Expand All @@ -100,12 +113,12 @@
expect(d.otus).to contain_exactly(otu, otu2)
end

specify 'd#row_objects' do
specify '#row_objects' do
species2.update(parent: genus1)
expect(d.row_objects).to contain_exactly(otu, otu2)
end

specify 'd#row_objects 2' do
specify '#row_objects 2' do
species2.update!(parent: species, rank_class: Ranks.lookup(:iczn, :subspecies))
expect(d.row_objects).to contain_exactly(otu, otu2)
end
Expand Down Expand Up @@ -138,6 +151,7 @@
end
end

# TODO: move to tag matrix hook specs
context 'tag alone' do
let(:keyword) { FactoryBot.create(:valid_keyword) }
let!(:t) { ::ObservationMatrixRowItem::Dynamic::Tag.create!( observation_matrix: observation_matrix, controlled_vocabulary_term: keyword )}
Expand Down

0 comments on commit f9b693a

Please sign in to comment.