From 3d7fe4c3a97a730fc0d6a5cac71ba0da835b54e8 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 8 Feb 2016 12:28:09 -0500 Subject: [PATCH] Bugfix `TagList#concat` with non-duplicates. `uniq!` behaves differently depending on whether duplicates are found or not: if they are, the de-duped list is returned, otherwise `nil` is returned. --- lib/acts_as_taggable_on/tag_list.rb | 1 + spec/acts_as_taggable_on/tag_list_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/acts_as_taggable_on/tag_list.rb b/lib/acts_as_taggable_on/tag_list.rb index bbd9ca427..a79031429 100644 --- a/lib/acts_as_taggable_on/tag_list.rb +++ b/lib/acts_as_taggable_on/tag_list.rb @@ -41,6 +41,7 @@ def +(other_tag_list) # Appends the elements of +other_tag_list+ to +self+. def concat(other_tag_list) super(other_tag_list).send(:clean!) + self end ## diff --git a/spec/acts_as_taggable_on/tag_list_spec.rb b/spec/acts_as_taggable_on/tag_list_spec.rb index 7959b84cc..d8dcc0612 100644 --- a/spec/acts_as_taggable_on/tag_list_spec.rb +++ b/spec/acts_as_taggable_on/tag_list_spec.rb @@ -83,6 +83,18 @@ new_tag_list = tag_list.concat(another_tag_list) expect(new_tag_list.class).to eq(ActsAsTaggableOn::TagList) end + + context 'without duplicates' do + let(:arr) { ['crazy', 'alien'] } + let(:another_tag_list) { ActsAsTaggableOn::TagList.new(*arr) } + it 'adds other list' do + expect(tag_list.concat(another_tag_list)).to eq(%w[awesome radical crazy alien]) + end + + it 'adds other array' do + expect(tag_list.concat(arr)).to eq(%w[awesome radical crazy alien]) + end + end end describe '#to_s' do