Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors TypeSpecimen to TypeMaterial, adds basic tests for TypeMate…
…rial. Code organization in Protonym.
- Loading branch information
Showing
13 changed files
with
220 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
class TypeDesignator < Role::ProjectRole | ||
|
||
include Housekeeping | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class TypeMaterial < ActiveRecord::Base | ||
belongs_to :source | ||
|
||
include Housekeeping | ||
include Shared::Citable | ||
|
||
ICZN_TYPES = { | ||
'holotype' => Specimen, | ||
'paratype' => Specimen, | ||
'neotype' => Specimen, | ||
'lectotype' => Specimen, | ||
'paratypes' => Lot, | ||
'syntypes' => Lot | ||
} | ||
|
||
ICN_TYPES = {} | ||
|
||
belongs_to :material, foreign_key: :biological_object_id, class_name: 'CollectionObject' | ||
belongs_to :protonym | ||
has_many :type_designator_roles, class_name: 'TypeDesignator', as: :role_object | ||
has_many :type_designators, through: :type_designator_roles, source: :person | ||
|
||
validates :protonym, presence: true | ||
validates :material, presence: true | ||
validates_presence_of :type_type | ||
|
||
validate :check_type_type | ||
|
||
protected | ||
|
||
def check_type_type | ||
if self.protonym | ||
code = self.protonym.rank_class.nomenclatural_code | ||
if (code == :iczn && !ICZN_TYPES.keys.include?(self.type_type)) || (code == :icn && !ICN_TYPES.keys.include?(self.type_type)) | ||
errors.add(:type_type, 'Not a legal type for the nomenclatural code provided') | ||
end | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateTypeMaterials < ActiveRecord::Migration | ||
def change | ||
create_table :type_materials do |t| | ||
t.integer :protonym_id | ||
t.integer :biological_object_id | ||
t.string :type_type | ||
t.references :source, index: true | ||
t.integer :created_by_id | ||
t.integer :updated_by_id | ||
t.integer :project_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class DropTypeSpecimenTable < ActiveRecord::Migration | ||
def change | ||
drop_table :type_specimens | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FactoryGirl.define do | ||
factory :type_material, traits: [:housekeeping] do | ||
factory :valid_type_material do | ||
type_type 'holotype' | ||
association :protonym, factory: :iczn_species | ||
association :material, factory: :valid_specimen | ||
end | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
require 'spec_helper' | ||
|
||
describe TypeMaterial do | ||
let(:type_material) { FactoryGirl.build(:type_material) } | ||
|
||
context 'associations' do | ||
context 'belongs to' do | ||
specify 'protonym' do | ||
expect(type_material).to respond_to(:protonym) | ||
end | ||
specify 'material' do | ||
expect(type_material).to respond_to(:material) | ||
end | ||
specify 'source' do | ||
expect(type_material).to respond_to(:source) | ||
end | ||
end | ||
end | ||
|
||
context 'validations' do | ||
context 'require' do | ||
before(:each) { | ||
type_material.valid? | ||
} | ||
specify 'protonym' do | ||
expect(type_material.errors.include?(:protonym)).to be_true | ||
end | ||
|
||
specify 'material' do | ||
expect(type_material.errors.include?(:material)).to be_true | ||
end | ||
|
||
specify 'type_type' do | ||
expect(type_material.errors.include?(:type_type)).to be_true | ||
end | ||
end | ||
|
||
context 'Protonym restrictions and linkages' do | ||
before(:each) { | ||
@iczn_type = FactoryGirl.build(:type_material, protonym: FactoryGirl.build(:iczn_species)) | ||
@icn_type = FactoryGirl.build(:type_material, protonym: FactoryGirl.build(:icn_species)) | ||
} | ||
|
||
specify 'type_type is one of ICZN_TYPES.keys for ICZN name' do | ||
@iczn_type.type_type = 'foo' | ||
@iczn_type.valid? | ||
expect(@iczn_type.errors.include?(:type_type)).to be_true | ||
expect(@iczn_type.errors.messages[:type_type]).to eq(['Not a legal type for the nomenclatural code provided']) | ||
@iczn_type.type_type = 'holotype' | ||
@iczn_type.valid? | ||
expect(@iczn_type.errors.include?(:type_type)).to be_false | ||
end | ||
|
||
specify 'type_type is one of ICN_TYPES.keys for ICN name' do | ||
pending | ||
end | ||
end | ||
|
||
context 'Material restrictions' do | ||
before(:each) { | ||
type_material.protonym = FactoryGirl.build(:iczn_species) | ||
} | ||
|
||
specify 'type_type restricts the BiologicalObject subclass to an _TYPES.value' do | ||
end | ||
|
||
specify 'collection_object is a BiologicalCollectionObject' do | ||
end | ||
end | ||
|
||
context 'type_type restrictions' do | ||
pending 'only one of holotype, lectotype, neotype per iczn species' | ||
end | ||
|
||
end | ||
|
||
context 'methods' do | ||
before(:each) { | ||
iczn_type = FactoryGirl.build(:valid_type_material) | ||
icn_type = FactoryGirl.build(:valid_type_material, protonym: FactoryGirl.build(:icn_species)) | ||
} | ||
pending 'Source is the Protonym source when not provided locally.' | ||
pending 'TypeDesignator role(s) should be possible when a specific person needs to be identified as the person who designated the type' | ||
pending 'a source citation can identify (override the source_id in Protonym) where the type designation was made' | ||
end | ||
|
||
context 'soft validation' do | ||
pending 'no source provided if self.source.nil && self.protonym.source.nil?' | ||
end | ||
|
||
end | ||
|
Oops, something went wrong.