Skip to content

Commit 4e7600c

Browse files
authored
Merge pull request mbleigh#1030 from gr-eg/count-perf
Use none? instead of count.zero?
2 parents 509a3e6 + 426d960 commit 4e7600c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/acts_as_taggable_on/tagging.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def remove_unused_tags
2828
if ActsAsTaggableOn.tags_counter
2929
tag.destroy if tag.reload.taggings_count.zero?
3030
else
31-
tag.destroy if tag.reload.taggings.count.zero?
31+
tag.destroy if tag.reload.taggings.none?
3232
end
3333
end
3434
end

spec/acts_as_taggable_on/tagging_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@
4949
ActsAsTaggableOn.remove_unused_tags = previous_setting
5050
end
5151

52+
it 'should destroy unused tags after tagging destroyed when not using tags_counter' do
53+
remove_unused_tags_previous_setting = ActsAsTaggableOn.remove_unused_tags
54+
tags_counter_previous_setting = ActsAsTaggableOn.tags_counter
55+
ActsAsTaggableOn.remove_unused_tags = true
56+
ActsAsTaggableOn.tags_counter = false
57+
58+
ActsAsTaggableOn::Tag.destroy_all
59+
@taggable = TaggableModel.create(name: 'Bob Jones')
60+
@taggable.update_attribute :tag_list, 'aaa,bbb,ccc'
61+
@taggable.update_attribute :tag_list, ''
62+
expect(ActsAsTaggableOn::Tag.count).to eql(0)
63+
64+
ActsAsTaggableOn.remove_unused_tags = remove_unused_tags_previous_setting
65+
ActsAsTaggableOn.tags_counter = tags_counter_previous_setting
66+
end
67+
5268
describe 'context scopes' do
5369
before do
5470
@tagging_2 = ActsAsTaggableOn::Tagging.new

0 commit comments

Comments
 (0)