Skip to content

Commit

Permalink
added citation and citation_topic linkages, added string utility to t…
Browse files Browse the repository at this point in the history
…rim and set to nil if empty
  • Loading branch information
eef committed Nov 5, 2013
1 parent 30228db commit 2a6d3cd
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 47 deletions.
3 changes: 3 additions & 0 deletions app/models/biological_association.rb
@@ -1,4 +1,7 @@
class BiologicalAssociation < ActiveRecord::Base

include Shared::Citable

belongs_to :biological_relationship

# TODO Must rename object
Expand Down
2 changes: 2 additions & 0 deletions app/models/biological_associations_graph.rb
@@ -1,5 +1,7 @@
class BiologicalAssociationsGraph < ActiveRecord::Base

include Shared::Citable

has_many :biological_associations


Expand Down
8 changes: 7 additions & 1 deletion app/models/citation.rb
@@ -1,6 +1,12 @@
# Citation is like Roles in that it is also a linking table between a data object & a source.
# (Assertion that the subject was referenced in a source)
class Citation < ActiveRecord::Base

belongs_to :citation_object, polymorphic: :true
belongs_to :source
belongs_to :source, inverse_of: :citations

has_many :citation_topics, inverse_of: :citation

validates_presence_of :citation_object_id, :citation_object_type, :source_id
validates_uniqueness_of :citation_object_id, :citation_object_type, :source_id
end
12 changes: 5 additions & 7 deletions app/models/citation_topic.rb
@@ -1,15 +1,13 @@
class CitationTopic < ActiveRecord::Base
belongs_to :topic
belongs_to :citation
belongs_to :topic, inverse_of: :citation_topics
belongs_to :citation, inverse_of: :citation_topics

validates_presence_of :topic_id, :citation_id
validates_uniqueness_of :topic_id, :citation_id

before_save :trim_pages
nil_trim_attributes(:pages)


protected

def trim_pages # pages should have content or be empty
self.pages = self.pages.to_str.strip
end
end
end
3 changes: 3 additions & 0 deletions app/models/collecting_event.rb
@@ -1,4 +1,7 @@
class CollectingEvent < ActiveRecord::Base

include Shared::Citable # ?

# several lines commented out per Matt ('old stuff')
# belongs_to :geographic_area
# belongs_to :confidence
Expand Down
1 change: 1 addition & 0 deletions app/models/collection_object.rb
Expand Up @@ -2,6 +2,7 @@ class CollectionObject < ActiveRecord::Base

include Shared::Identifiable
include Shared::Containable
include Shared::Citable

belongs_to :preparation_type

Expand Down
3 changes: 2 additions & 1 deletion app/models/controlled_vocabulary_term/topic.rb
@@ -1,2 +1,3 @@
class ControlledVocabularyTerm::Topic < ControlledVocabularyTerm
class ControlledVocabularyTerm::Topic < ControlledVocabularyTerm
has_many :citation_topics, inverse_of: :topic
end
2 changes: 2 additions & 0 deletions app/models/otu.rb
@@ -1,6 +1,8 @@
class Otu < ActiveRecord::Base

include Shared::Identifiable
include Shared::Citable # ?

has_many :taxon_determinations

has_many :contents
Expand Down
5 changes: 4 additions & 1 deletion app/models/source.rb
@@ -1,6 +1,9 @@
class Source < ActiveRecord::Base
include Shared::Identifiable
include Shared::HasRoles
include Shared::HasRoles

has_many :citations, inverse_of: :source
has_many :cited_objects, through: :citations, source: :citation_object # not ordered

#validate :not_empty

Expand Down
1 change: 1 addition & 0 deletions app/models/taxon_determination.rb
Expand Up @@ -19,6 +19,7 @@
class TaxonDetermination < ActiveRecord::Base

include Shared::HasRoles
include Shared::Citable

belongs_to :otu
belongs_to :biological_collection_object
Expand Down
3 changes: 3 additions & 0 deletions app/models/type_specimen.rb
@@ -1,4 +1,7 @@
class TypeSpecimen < ActiveRecord::Base

include Shared::Citable

belongs_to :biological_object
belongs_to :taxon_name

Expand Down
36 changes: 36 additions & 0 deletions lib/activerecord_utilities.rb
@@ -0,0 +1,36 @@
module ActiverecordUtilities
# this is for shared utilies, like string manipulation methods.

extend ActiveSupport::Concern

included do
# these are the extensions (like has_many)
before_validation :trim_attributes
class_attribute :attributes_to_trim

end

module ClassMethods
# any def inside here is a class method
def nil_trim_attributes(*attributes) # this assigns the attributes to be trimmed
self.attributes_to_trim = attributes
end
end

protected
# any def below this is an instance method
def trim_attributes
if !self.attributes_to_trim.nil?
self.attributes_to_trim.each do |a|
self.send("#{a}=".to_sym, Utilities::Strings.nil_strip(self.send(a)))
end
end
end

end

class ActiveRecord::Base
include ActiverecordUtilities
end


1 change: 1 addition & 0 deletions lib/taxonworks.rb
Expand Up @@ -7,4 +7,5 @@


module TaxonWorks
require 'activerecord_utilities'
end
10 changes: 10 additions & 0 deletions lib/utilities/strings.rb
@@ -0,0 +1,10 @@
module Utilities::Strings

def self.nil_strip(string) # string should have content or be empty
if !string.nil?
string.strip!
string = nil if string == ''
end
string
end
end
10 changes: 10 additions & 0 deletions spec/lib/activerecord_utilities_spec.rb
@@ -0,0 +1,10 @@
require 'spec_helper'
require 'activerecord_utilities'

#include dummy class to test the activerecord_utilities

class TestStringsManipulations
# include ActiverecordUtilities


end
5 changes: 5 additions & 0 deletions spec/models/citation_spec.rb
Expand Up @@ -4,6 +4,7 @@
let(:citation) {Citation.new}

context 'associations' do

context 'belongs_to' do
specify 'citation_object' do
expect(citation).to respond_to(:citation_object)
Expand All @@ -15,6 +16,10 @@
end
end

context 'validations' do
# check for all required fields.
end

context 'concerns' do
specify 'isolate and create concern citable (see identifiable concern)'
end
Expand Down
74 changes: 37 additions & 37 deletions spec/models/source/bibtex_spec.rb
Expand Up @@ -359,8 +359,44 @@
end
end
end



context 'class methods' do
# create_with_roles(bibtex_entry, opts = {})
# opts = {
# use_vetted_people: false
# }.merge!(opts)
context 'create_with_roles(BibTeX::Entry instance)' do

specify 'creates author/editor roles with Person::Unvetted by default' do
pending
end

context 'parameters' do
specify '{use_vetted_people: true} - uses exactly matching Person::Vetted found, otherwise creates new editors/authors' do
pending
end
end
end
end

context 'supporting libs' do
context 'if I have a zotero bibliography' do
context 'and I import it to TW' do
context 'when I update a record in zotero' do
specify 'then TW should be aware and notify me of discrepancies' do
pending 'not implemented yet'
end
end
end
end

context 'Hackathon requirements' do
# TODO: code lib/bibtex
pending 'Should be able to round trip data a whole file '
#(e.g. import a BibTex file, then output a BibTex file and have them be the same.)
end
end
context('Beth') do
=begin
notes/things to do:
Expand Down Expand Up @@ -389,42 +425,6 @@
# bs3.save
#end

context 'class methods' do
# create_with_roles(bibtex_entry, opts = {})
# opts = {
# use_vetted_people: false
# }.merge!(opts)
context 'create_with_roles(BibTeX::Entry instance)' do

specify 'creates author/editor roles with Person::Unvetted by default' do
pending
end

context 'parameters' do
specify '{use_vetted_people: true} - uses exactly matching Person::Vetted found, otherwise creates new editors/authors' do
pending
end
end
end
end

context 'supporting libs' do
context 'if I have a zotero bibliography' do
context 'and I import it to TW' do
context 'when I update a record in zotero' do
specify 'then TW should be aware and notify me of discrepancies' do
pending 'not implemented yet'
end
end
end
end

context 'Hackathon requirements' do
# TODO: code lib/bibtex
pending 'Should be able to round trip data a whole file '
#(e.g. import a BibTex file, then output a BibTex file and have them be the same.)
end
end
end

context 'concerns' do
Expand Down
8 changes: 8 additions & 0 deletions spec/models/source_spec.rb
Expand Up @@ -4,6 +4,14 @@
let(:source) { Source.new }


context 'associtations' do
specify 'sources have citations' do
expect(source).to respond_to(:citations)
end
specify 'sources have cited_objects' do
expect(source).to respond_to(:cited_objects)
end
end

context "concerns" do
it_behaves_like 'identifiable'
Expand Down

0 comments on commit 2a6d3cd

Please sign in to comment.