From 74cb5aea26cebecf9fea8709c73aecb6363c0345 Mon Sep 17 00:00:00 2001 From: "keerthi.siv" Date: Sat, 16 Apr 2016 14:02:41 -0400 Subject: [PATCH] fix issue with custom delimiter --- lib/acts_as_taggable_on/taggable/cache.rb | 2 +- spec/acts_as_taggable_on/caching_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/acts_as_taggable_on/taggable/cache.rb b/lib/acts_as_taggable_on/taggable/cache.rb index 72c4d715d..c573cefe4 100644 --- a/lib/acts_as_taggable_on/taggable/cache.rb +++ b/lib/acts_as_taggable_on/taggable/cache.rb @@ -73,7 +73,7 @@ def save_cached_tag_list tag_types.map(&:to_s).each do |tag_type| if self.class.send("caching_#{tag_type.singularize}_list?") if tag_list_cache_set_on(tag_type) - list = tag_list_cache_on(tag_type).to_a.flatten.compact.join(', ') + list = tag_list_cache_on(tag_type).to_a.flatten.compact.join("#{ActsAsTaggableOn.delimiter} ") self["cached_#{tag_type.singularize}_list"] = list end end diff --git a/spec/acts_as_taggable_on/caching_spec.rb b/spec/acts_as_taggable_on/caching_spec.rb index d80675929..18acae984 100644 --- a/spec/acts_as_taggable_on/caching_spec.rb +++ b/spec/acts_as_taggable_on/caching_spec.rb @@ -77,6 +77,28 @@ end end + describe 'with a custom delimiter' do + before(:each) do + @taggable = CachedModel.new(name: 'Bob Jones') + @another_taggable = OtherCachedModel.new(name: 'John Smith') + ActsAsTaggableOn.delimiter = ';' + end + + after(:all) do + ActsAsTaggableOn.delimiter = ',' + end + + it 'should cache tags with custom delimiter' do + @taggable.update_attributes(tag_list: 'awesome; epic') + expect(@taggable.tag_list).to eq(['awesome', 'epic']) + expect(@taggable.cached_tag_list).to eq('awesome; epic') + + @taggable = CachedModel.find_by_name('Bob Jones') + expect(@taggable.tag_list).to eq(['awesome', 'epic']) + expect(@taggable.cached_tag_list).to eq('awesome; epic') + end + end + describe 'CachingWithArray' do pending '#TODO' end