feat: ensure the clean-up logic works

This commit is contained in:
Shivam Mishra
2023-05-09 14:24:35 +05:30
parent ae5deca24b
commit 1a74e52445
2 changed files with 15 additions and 1 deletions
+7
View File
@@ -3,6 +3,7 @@ module Labelable
included do
acts_as_taggable_on :labels
before_save :clear_labels_cache
end
def update_labels(labels = nil)
@@ -24,4 +25,10 @@ module Labelable
@labels_cache || []
end
private
def clear_labels_cache
@labels_cache = nil
end
end
+8 -1
View File
@@ -244,10 +244,17 @@ RSpec.describe Conversation, type: :model do
end
it 'ensures preloaded labels are always in sync with the database' do
labels = [first_label, fourth_label].map(&:title)
labels = [first_label].map(&:title)
expect(conversation.update_labels(labels)).to be(true)
expect(conversation.label_list).to match_array(labels)
expect(conversation.preloaded_label_list).to match_array(labels)
updated_labels = [second_label].map(&:title)
# reload this so that the taggins collection is updated
conversation.reload
expect(conversation.update_labels(updated_labels)).to be(true)
expect(conversation.label_list).to match_array(updated_labels)
expect(conversation.preloaded_labelfe_list).to match_array(updated_labels)
end
it 'adds and removes previously added labels' do