Skip to content

Commit

Permalink
Add spec testing that FieldOccurrences can be destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
kleintom committed Feb 10, 2025
1 parent 19e8a56 commit 520c045
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spec/models/field_occurrence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
field_occurrence.is_absent = true
field_occurrence.valid?
expect(field_occurrence.errors.messages).to include(:total)
end
end

context 'a taxon_determination is required' do
before do
Expand Down Expand Up @@ -54,7 +54,7 @@
end

specify 'providing a taxon_determination with #taxon_determinations << validates' do
field_occurrence.taxon_determinations << TaxonDetermination.new(otu:)
field_occurrence.taxon_determinations << TaxonDetermination.new(otu:)
expect(field_occurrence.save).to be_truthy
expect(field_occurrence.taxon_determinations.count).to eq(1)
end
Expand All @@ -70,6 +70,14 @@
end

context 'attempting to delete last taxon_determination' do
specify 'permitted when deleting self' do
field_occurrence.taxon_determination = TaxonDetermination.new(otu:)
expect(field_occurrence.save).to be_truthy
expect(field_occurrence.taxon_determinations.count).to eq(1)
expect(field_occurrence.destroy).to be_truthy
expect(FieldOccurrence.count).to be(0)
end

specify 'when taxon_determination is origin_ciation' do
field_occurrence.otu = otu
field_occurrence.save!
Expand All @@ -78,7 +86,7 @@
end

specify 'when taxon_determination is not origin taxon_determination' do
field_occurrence.taxon_determinations << TaxonDetermination.new(otu:)
field_occurrence.taxon_determinations << TaxonDetermination.new(otu:)
expect(field_occurrence.save).to be_truthy
expect(field_occurrence.taxon_determinations.count).to eq(1)
expect(field_occurrence.taxon_determinations.reload.first.destroy).to be_falsey
Expand Down

0 comments on commit 520c045

Please sign in to comment.