diff --git a/app/controllers/checklist/timelines_controller.rb b/app/controllers/checklist/timelines_controller.rb index 8ba7c28e4b..a09306ce9e 100644 --- a/app/controllers/checklist/timelines_controller.rb +++ b/app/controllers/checklist/timelines_controller.rb @@ -2,6 +2,7 @@ class Checklist::TimelinesController < ApplicationController def index return render :json => [] if params[:taxon_concept_ids].nil? + return render :json => [] unless params[:taxon_concept_ids].kind_of?(Array) res = params[:taxon_concept_ids].map do |tc_id| tc = MTaxonConcept.find_by_id(tc_id) Checklist::TimelinesForTaxonConcept.new(tc) unless tc.nil? diff --git a/app/models/checklist/timeline_event.rb b/app/models/checklist/timeline_event.rb index 8fca3911d6..28eb17980c 100644 --- a/app/models/checklist/timeline_event.rb +++ b/app/models/checklist/timeline_event.rb @@ -15,7 +15,14 @@ class Checklist::TimelineEvent #:hash_ann_parent_symbol e.g. CoP15 #:pos - position (%) def initialize(options) - @id = (options[:taxon_concept_id] << 8) + options[:id] + # if it is an auto-inserted deletion it won't have an id + id = options[:id] || ( + (options[:species_listing_id] << 16) + + (options[:change_type_id] << 12) + + (options[:effective_at].to_i << 8) + + (options[:party_id] || 0) + ) + @id = (options[:taxon_concept_id] << 8) + id @pos = options[:pos] @party_id = options[:party_id] @change_type_name = options[:change_type_name] diff --git a/app/models/m_listing_change.rb b/app/models/m_listing_change.rb index 9fcb208c8a..2425fc118d 100644 --- a/app/models/m_listing_change.rb +++ b/app/models/m_listing_change.rb @@ -48,7 +48,8 @@ def to_timeline_event Checklist::TimelineEvent.new( self.as_json( :only => [ - :id, :taxon_concept_id, :change_type_name, :species_listing_name, :party_id, + :id, :taxon_concept_id, :change_type_id, :change_type_name, + :species_listing_id, :species_listing_name, :party_id, :is_current, :hash_ann_symbol, :hash_ann_parent_symbol, :effective_at, :auto_note, :inclusion_taxon_concept_id ], diff --git a/spec/models/checklist/timeline_spec.rb b/spec/models/checklist/timeline_spec.rb index f5f249c4c0..5349ee5bd7 100644 --- a/spec/models/checklist/timeline_spec.rb +++ b/spec/models/checklist/timeline_spec.rb @@ -232,4 +232,33 @@ specify{ subject.timeline_intervals[1].end_pos.should == 1 } end + context "when automatic deletion from ancestor listing" do + let(:tc){ + genus = create_cites_eu_genus + tc = create_cites_eu_species(parent: genus) + create_cites_I_addition( + :taxon_concept => genus, + :effective_at => '1975-06-06', + :is_current => true + ) + create_cites_II_addition( + :taxon_concept => tc, + :effective_at => '1976-06-08', + :is_current => true + ) + # tc should have a cascaded ADD I from parent and an auto DEL I + Sapi::StoredProcedures.rebuild_cites_taxonomy_and_listings + MTaxonConcept.find(tc.id) + } + let(:ttc){ Checklist::TimelinesForTaxonConcept.new(tc)} + let(:subject){ ttc.timelines.first } + + specify{ + subject.timeline_events.map(&:change_type_name).should == + ['ADDITION', 'DELETION'] + } + specify{ subject.timeline_intervals.count.should == 1 } + specify{ subject.timeline_intervals[0].end_pos.should == subject.timeline_events[1].pos } + end + end