diff --git a/app/models/citation_topic.rb b/app/models/citation_topic.rb index bfed880082..6ea7813580 100644 --- a/app/models/citation_topic.rb +++ b/app/models/citation_topic.rb @@ -1,4 +1,15 @@ class CitationTopic < ActiveRecord::Base belongs_to :topic belongs_to :citation + + validates_presence_of :topic_id, :citation_id + validates_uniqueness_of :topic_id, :citation_id + + before_save :trim_pages + + protected + + def trim_pages # pages should have content or be empty + self.pages = self.pages.to_str.strip + end end diff --git a/spec/models/citation_spec.rb b/spec/models/citation_spec.rb index 1e3b3cc00e..b21bd5f74b 100644 --- a/spec/models/citation_spec.rb +++ b/spec/models/citation_spec.rb @@ -19,4 +19,12 @@ specify 'isolate and create concern citable (see identifiable concern)' end + context 'Beth' do + context 'create a citation' do + # create a citation linking a specimen (collection_object?) to a source + # create a citation linking a nomenclatural act (what object represents this?) to a source. + end + + end + end diff --git a/spec/models/citation_topic_spec.rb b/spec/models/citation_topic_spec.rb index 354aeecd30..2a3796820d 100644 --- a/spec/models/citation_topic_spec.rb +++ b/spec/models/citation_topic_spec.rb @@ -1,5 +1,33 @@ require 'spec_helper' describe CitationTopic do + let(:citationtopic) { CitationTopic.new } + pending "add some examples to (or delete) #{__FILE__}" + + context 'Beth' do + context 'validation' do + before do + citationtopic.valid? + end + + context 'required fields' do + specify 'citation_id' do + expect(citationtopic.errors.include?(:citation_id)).to be_true + end + + specify 'topic_id' do + expect(citationtopic.errors.include?(:topic_id)).to be_true + end + end + + context 'no duplicates' do + # create citation + # create topic + # create cite_topic + # save & reload + # try to save again - maybe with added pages + end + end + end end