Skip to content

Commit

Permalink
CV2-3694: update updated_at column after delete tags (#1726)
Browse files Browse the repository at this point in the history
* CV2-3694: trigger update column after delete tags

* CV2-3694: fix tests
  • Loading branch information
melsawy authored Nov 13, 2023
1 parent d623958 commit c5e498d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/models/annotations/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ def add_update_es_tags(op)
end

def destroy_elasticsearch_tag
destroy_es_items('tags', 'destroy_doc_nested', self.annotated_id) if self.annotated_type == 'ProjectMedia'
if self.annotated_type == 'ProjectMedia'
destroy_es_items('tags', 'destroy_doc_nested', self.annotated_id)
if User.current.present?
pm = self.annotated
pm.update_recent_activity(pm)
end
end
end

def update_tags_count
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/elastic_search_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def setup
# destroy tag
ElasticSearchWorker.clear
t.destroy
assert_equal 1, ElasticSearchWorker.jobs.size
assert_equal 2, ElasticSearchWorker.jobs.size
end
end

Expand Down
13 changes: 12 additions & 1 deletion test/controllers/elastic_search_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,24 @@ def setup
sleep 2
result = CheckSearch.new({sort: "recent_activity"}.to_json)
assert_equal [pm1.id, pm3.id, pm2.id], result.medias.map(&:id)
create_tag annotated: pm3, tag: 'in_progress', disable_es_callbacks: false
tag_3 = create_tag annotated: pm3, tag: 'in_progress', disable_es_callbacks: false
sleep 1
result = CheckSearch.new({sort: "recent_activity"}.to_json)
assert_equal [pm3.id, pm1.id, pm2.id], result.medias.map(&:id)
# should sort by recent activity with project and status filters
result = CheckSearch.new({verification_status: ['in_progress'], sort: "recent_activity"}.to_json)
assert_equal 1, result.project_medias.count
tag_1 = create_tag annotated: pm1, tag: 'in_progress', disable_es_callbacks: false
tag_2 = create_tag annotated: pm2, tag: 'in_progress', disable_es_callbacks: false
sleep 1
result = CheckSearch.new({sort: "recent_activity"}.to_json)
assert_equal [pm2.id, pm1.id, pm3.id], result.medias.map(&:id)
tag_3.destroy!
sleep 1
result = CheckSearch.new({sort: "recent_activity"}.to_json)
assert_equal [pm3.id, pm2.id, pm1.id], result.medias.map(&:id)
result = CheckSearch.new({tags: ['in_progress'], sort: "recent_activity"}.to_json)
assert_equal [pm2.id, pm1.id], result.medias.map(&:id)
end
end

Expand Down

0 comments on commit c5e498d

Please sign in to comment.