File: job_generator_test.rb

package info (click to toggle)
rails 2%3A7.2.2.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 43,352 kB
  • sloc: ruby: 349,799; javascript: 30,703; yacc: 46; sql: 43; sh: 29; makefile: 27
file content (55 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

require "generators/generators_test_helper"
require "rails/generators/job/job_generator"

class JobGeneratorTest < Rails::Generators::TestCase
  include GeneratorsTestHelper

  def test_job_skeleton_is_created
    run_generator ["refresh_counters"]
    assert_file "app/jobs/refresh_counters_job.rb" do |job|
      assert_match(/class RefreshCountersJob < ApplicationJob/, job)
    end
  end

  def test_job_queue_param
    run_generator ["refresh_counters", "--queue", "important"]
    assert_file "app/jobs/refresh_counters_job.rb" do |job|
      assert_match(/class RefreshCountersJob < ApplicationJob/, job)
      assert_match(/queue_as :important/, job)
    end
  end

  def test_job_parent_param
    run_generator ["refresh_counters", "--parent", "awesome_job"]
    assert_file "app/jobs/refresh_counters_job.rb" do |job|
      assert_match(/class RefreshCountersJob < AwesomeJob/, job)
    end
  end

  def test_job_namespace
    run_generator ["admin/refresh_counters", "--queue", "admin"]
    assert_file "app/jobs/admin/refresh_counters_job.rb" do |job|
      assert_match(/class Admin::RefreshCountersJob < ApplicationJob/, job)
      assert_match(/queue_as :admin/, job)
    end
  end

  def test_application_job_skeleton_is_created
    run_generator ["refresh_counters"]
    assert_file "app/jobs/application_job.rb" do |job|
      assert_match(/class ApplicationJob < ActiveJob::Base/, job)
    end
  end

  def test_job_suffix_is_not_duplicated
    run_generator ["notifier_job"]

    assert_no_file "app/jobs/notifier_job_job.rb"
    assert_file "app/jobs/notifier_job.rb"

    assert_no_file "test/jobs/notifier_job_job_test.rb"
    assert_file "test/jobs/notifier_job_test.rb"
  end
end