Skip to content

Commit c4a6575

Browse files
Nick FlückigerJonRowe
authored andcommitted
Implement check to prevent duplicate job naming (#2496)
* Implement check to prevent duplicate job naming
1 parent bc9687f commit c4a6575

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/generators/rspec/job/job_generator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Generators
55
# @private
66
class JobGenerator < Base
77
def create_job_spec
8-
template 'job_spec.rb.erb', File.join('spec/jobs', class_path, "#{file_name}_job_spec.rb")
8+
file_suffix = file_name.end_with?('job') ? 'spec.rb' : 'job_spec.rb'
9+
template 'job_spec.rb.erb', File.join('spec/jobs', class_path, [file_name, file_suffix].join('_'))
910
end
1011
end
1112
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22

33
<% module_namespacing do -%>
4-
RSpec.describe <%= class_name %>Job, <%= type_metatag(:job) %> do
4+
RSpec.describe <%= class_name %><%= "Job" unless class_name.end_with?("Job")%>, <%= type_metatag(:job) %> do
55
pending "add some examples to (or delete) #{__FILE__}"
66
end
77
<% end -%>

spec/generators/rspec/job/job_generator_spec.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@
66
setup_default_destination
77

88
describe 'the generated files' do
9-
before { run_generator %w[user] }
9+
before { run_generator [file_name] }
1010

11-
subject { file('spec/jobs/user_job_spec.rb') }
11+
context 'with file_name without job as suffix' do
12+
let(:file_name) { 'user' }
13+
subject { file('spec/jobs/user_job_spec.rb') }
1214

13-
it { is_expected.to exist }
14-
it { is_expected.to contain(/require 'rails_helper'/) }
15-
it { is_expected.to contain(/describe UserJob, #{type_metatag(:job)}/) }
15+
it { is_expected.to exist }
16+
it { is_expected.to contain(/require 'rails_helper'/) }
17+
it { is_expected.to contain(/describe UserJob, #{type_metatag(:job)}/) }
18+
end
1619

20+
context 'with file_name with job as suffix' do
21+
let(:file_name) { 'user_job' }
22+
23+
subject { file('spec/jobs/user_job_spec.rb') }
24+
25+
it { is_expected.to exist }
26+
it { is_expected.to contain(/require 'rails_helper'/) }
27+
it { is_expected.to contain(/describe UserJob, #{type_metatag(:job)}/) }
28+
end
1729
end
1830
end

0 commit comments

Comments
 (0)