@@ -96,7 +96,7 @@ class Exercise < ApplicationRecord
9696 scope :can_release_to_a15k , -> { where ( release_to_a15k : true ) }
9797 scope :not_released_to_a15k , -> { where ( a15k_identifier : nil ) }
9898
99- before_validation :set_context , :set_slug_tags
99+ before_validation :set_context , :set_slug_tags!
100100
101101 def content_equals? ( other_exercise )
102102 return false unless other_exercise . is_a? ActiveRecord ::Base
@@ -247,7 +247,7 @@ def set_context(archive_version: nil)
247247 return
248248 end
249249
250- def set_slug_tags
250+ def set_slug_tags!
251251 existing_book_slug_tags , other_tags = tags . partition do |tag |
252252 tag . name . starts_with? 'book-slug:'
253253 end
@@ -268,10 +268,10 @@ def set_slug_tags
268268 "module-slug:#{ slug [ :book ] } :#{ slug [ :page ] } "
269269 end
270270
271- kept_book_slug_tags = existing_book_slug_tags . filter do |tag |
271+ kept_book_slug_tags , removed_book_slug_tags = existing_book_slug_tags . partition do |tag |
272272 desired_book_slugs . include? tag . name
273273 end
274- kept_page_slug_tags = existing_page_slug_tags . filter do |tag |
274+ kept_page_slug_tags , removed_page_slug_tags = existing_page_slug_tags . partition do |tag |
275275 desired_page_slugs . include? tag . name
276276 end
277277
@@ -284,5 +284,11 @@ def set_slug_tags
284284 self . tags = non_slug_tags +
285285 kept_book_slug_tags + kept_page_slug_tags +
286286 new_book_slugs + new_page_slugs
287+
288+ # Return whether or not any tags changed
289+ !removed_book_slug_tags . empty? ||
290+ !removed_page_slug_tags . empty? ||
291+ !new_book_slugs . empty? ||
292+ !new_page_slugs . empty?
287293 end
288294end
0 commit comments