From 2a4c39f7ae863ac7e4d14e0110aba11fce4a822f Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Mon, 8 Jul 2013 16:34:28 +0200 Subject: Simply Relationship.next_free_id by depending on number of cached instances. Only drawback: Setting @next_freed_id_counter to 1000 in tc_helper.rb is no longer possible. But this was useful mainly while adding / fixing test cases when implementing the Relationship instance cache. --- lib/axlsx/rels/relationship.rb | 4 +--- test/tc_helper.rb | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index 64356d46..5e75a98a 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -14,9 +14,7 @@ module Axlsx # Generate and return a unique id. Used for setting {#Id}. # @return [String] def next_free_id - @next_free_id_counter ||= 0 - @next_free_id_counter += 1 - "rId#{@next_free_id_counter}" + "rId#{@instances.size + 1}" end end diff --git a/test/tc_helper.rb b/test/tc_helper.rb index c09446b7..af40a1e4 100644 --- a/test/tc_helper.rb +++ b/test/tc_helper.rb @@ -8,7 +8,3 @@ end require 'test/unit' require "timecop" require "axlsx.rb" - -# Make sure all valid rIds are > 1000 - this should help catching the cases where rId is still -# determined by looking at the index of an object in an array etc. -Axlsx::Relationship.instance_variable_set :@next_free_id_counter, 1000 -- cgit v1.2.3