Skip to content

Commit

Permalink
add GenericWorkerHelpersTest
Browse files Browse the repository at this point in the history
  • Loading branch information
vasconsaurus committed Sep 20, 2024
1 parent 935f44f commit 2c9c1d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
34 changes: 34 additions & 0 deletions test/lib/generic_worker_helpers_test.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions test/models/project_media_8_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2c9c1d0

Please sign in to comment.