From 2c9c1d0e8c8e93d86657a7cc3b060059990f2a8e Mon Sep 17 00:00:00 2001 From: manu vasconcelos Date: Fri, 20 Sep 2024 09:21:59 -0300 Subject: [PATCH] add GenericWorkerHelpersTest --- test/lib/generic_worker_helpers_test.rb | 34 +++++++++++++++++++++++++ test/models/project_media_8_test.rb | 15 ----------- 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 test/lib/generic_worker_helpers_test.rb diff --git a/test/lib/generic_worker_helpers_test.rb b/test/lib/generic_worker_helpers_test.rb new file mode 100644 index 000000000..11d390d99 --- /dev/null +++ b/test/lib/generic_worker_helpers_test.rb @@ -0,0 +1,34 @@ +require_relative '../test_helper' + +class GenericWorkerHelpersTest < ActionView::TestCase + def setup + require 'sidekiq/testing' + Sidekiq::Worker.clear_all + end + + def teardown + end + + test "should run a job, without raising an error, for a method that takes a hash as a parameter" do + Sidekiq::Testing.inline! + + assert_difference "Team.where(name: 'BackgroundTeam', slug: 'background-team').count" do + Team.run_later('create!', name: 'BackgroundTeam', slug: 'background-team') + end + end + + test "should run a job, without raising an error, for a method that takes standalone parameters" do + Sidekiq::Testing.inline! + + team = create_team + project = create_project team: team + pm = create_project_media project: project + + project_media_id = pm.id + tags_json = ['one', 'two', 'three'].to_json + + ProjectMedia.run_later_in(0.second, 'create_tags', project_media_id, tags_json, user_id: pm.user_id) + + assert_equal 3, pm.annotations('tag').count + end +end diff --git a/test/models/project_media_8_test.rb b/test/models/project_media_8_test.rb index 0f2c818b6..42f9b9c41 100644 --- a/test/models/project_media_8_test.rb +++ b/test/models/project_media_8_test.rb @@ -69,19 +69,4 @@ def teardown assert_equal 1, GenericWorker.jobs.size end - - test "when using :run_later_in to schedule multiple tags creation, tags should be created" do - Sidekiq::Testing.inline! - - team = create_team - project = create_project team: team - pm = create_project_media project: project - - project_media_id = pm.id - tags_json = ['one', 'two', 'three'].to_json - - ProjectMedia.run_later_in(0.second, 'create_tags', project_media_id, tags_json, user_id: pm.user_id) - - assert_equal 3, pm.annotations('tag').count - end end