Skip to content

Commit

Permalink
Merge branch 'hotfix-0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnieszka Figiel committed Aug 4, 2014
2 parents 94321fa + 4ec020c commit 2d9c320
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/checklist/timelines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 8 additions & 1 deletion app/models/checklist/timeline_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion app/models/m_listing_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
Expand Down
29 changes: 29 additions & 0 deletions spec/models/checklist/timeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2d9c320

Please sign in to comment.