Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BicurationGroups. Tag positioning. ControlledVocabulary related facto…
…ries and specs.
- Loading branch information
Showing
18 changed files
with
152 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class BiocurationClass < ControlledVocabularyTerm | ||
|
||
has_many :biocuration_classifications | ||
has_many :biological_objects | ||
|
||
include Shared::Taggable | ||
|
||
has_many :biocuration_classifications | ||
has_many :biological_collection_objects, through: :biocuration_classifications, class_name: 'CollectionObject::BiologicalCollectionObject' | ||
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
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,7 @@ | ||
class BiocurationGroup < Keyword | ||
|
||
# Watch out this is borked with squeel | ||
has_many :biocuration_classes, through: :tags, source: 'tag_object', source_type: 'ControlledVocabularyTerm' | ||
|
||
|
||
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
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,2 +1,9 @@ | ||
class Keyword < ControlledVocabularyTerm | ||
|
||
has_many :tags, foreign_key: :keyword_id | ||
|
||
def tagged_objects | ||
self.tags.collect{|t| t.tag_object} | ||
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
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,10 +1,13 @@ | ||
class Tag < ActiveRecord::Base | ||
include Housekeeping | ||
|
||
acts_as_list scope: [:keyword_id] | ||
|
||
belongs_to :keyword | ||
belongs_to :tag_object, polymorphic: true | ||
|
||
validates :tag_object, presence: true | ||
validates :keyword, presence: true | ||
validates_uniqueness_of :keyword_id, scope: [:tag_object] | ||
validates_uniqueness_of :keyword_id, scope: [ :tag_object_id, :tag_object_type] | ||
|
||
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 AddPositionToTags < ActiveRecord::Migration | ||
def change | ||
add_column :tags, :position, :integer | ||
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
FactoryGirl.define do | ||
factory :biocuration_classification, traits: [:housekeeping] do | ||
biocuration_class nil | ||
biological_collection_object nil | ||
position 1 | ||
factory :valid_biocuration_classification do | ||
association :biocuration_class, factory: :valid_biocuration_class | ||
association :biological_collection_object, factory: :valid_specimen | ||
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,8 @@ | ||
FactoryGirl.define do | ||
factory :biocuration_group, traits: [:housekeeping] do | ||
factory :valid_biocuration_group do | ||
name 'life stage' | ||
definition 'A group of life stages.' | ||
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 @@ | ||
FactoryGirl.define do | ||
factory :container_box, class: Container::Box, traits: [:housekeeping] do | ||
factory :valid_container_box | ||
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
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,31 @@ | ||
require 'spec_helper' | ||
|
||
describe BiocurationGroup do | ||
|
||
let(:biocuration_group) {FactoryGirl.build(:biocuration_group)} | ||
|
||
context 'has many' do | ||
before(:each) { | ||
@biocuration_group = FactoryGirl.create(:valid_biocuration_group, name: 'Stages.', definition: 'Life stages.') | ||
@bc1 = BiocurationClass.create(name: 'Adult', definition: 'A mature indivdiual.') | ||
@bc2 = BiocurationClass.create(name: 'Larva', definition: 'Not a mature indivdiual.') | ||
} | ||
|
||
specify 'tags (through Keywords)' do | ||
expect(biocuration_group.tags << Tag.new(keyword: FactoryGirl.create(:valid_keyword))).to be_true | ||
end | ||
|
||
specify 'biocuration_classes' do | ||
expect(biocuration_group).to respond_to(:biocuration_classes) | ||
t1 =Tag.create(keyword: @biocuration_group, tag_object: @bc1) | ||
t2 = Tag.create(keyword: @biocuration_group, tag_object: @bc2) | ||
|
||
# Something to not match | ||
t3 = Tag.create(keyword: FactoryGirl.create(:valid_keyword), tag_object: @bc1) | ||
|
||
expect(@biocuration_group.biocuration_classes).to have(2).things | ||
expect(@biocuration_group.biocuration_classes.to_a.map(&:class)).to eq([BiocurationClass, BiocurationClass]) | ||
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 |
---|---|---|
@@ -1,15 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
describe Keyword do | ||
let(:topic) { Keyword.new } | ||
let(:keyword) { FactoryGirl.build(:keyword) } | ||
|
||
context "associations" do | ||
context "validation" do | ||
before(:each) { @k = FactoryGirl.create(:valid_keyword) } | ||
|
||
specify "can be used for tags" do | ||
t = Tag.new(keyword: @k, tag_object: FactoryGirl.build(:valid_otu)) | ||
expect(t.save).to be_true | ||
end | ||
|
||
specify "can not be used for other things" do | ||
expect {c = CitationTopic.new(topic: @k)}.to raise_error | ||
end | ||
end | ||
|
||
context "validation" do | ||
specify "can be used for tags" | ||
specify "can not be used for citations" | ||
context 'associations' do | ||
context 'has_many' do | ||
specify 'tags' do | ||
expect(keyword.tags << FactoryGirl.build(:valid_tag)).to be_true | ||
end | ||
end | ||
end | ||
|
||
specify 'tagged_objects' do | ||
expect(keyword).to respond_to(:tagged_objects) | ||
k = FactoryGirl.create(:valid_keyword) | ||
t1 = Tag.create(keyword: k, tag_object: FactoryGirl.create(:valid_otu)) | ||
t2 = Tag.create(keyword: k, tag_object: FactoryGirl.create(:valid_specimen)) | ||
expect(k.tagged_objects).to have(2).things | ||
expect(k.tags).to have(2).things | ||
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