Skip to content

Commit

Permalink
Fix an error occurred for FactoryBot/IdSequence when sequence wit…
Browse files Browse the repository at this point in the history
…h non-symbol argment or without argument

Fix: #80
  • Loading branch information
ydah committed Jan 5, 2024
1 parent 2815a90 commit 85f0891
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix an error occurred for `FactoryBot/IdSequence` when `sequence` with non-symbol argument or without argument. ([@ydah])

## 2.25.0 (2024-01-04)

- Fix a false positive for `FactoryBot/FactoryNameStyle` when namespaced models. ([@ydah])
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/factory_bot/id_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class IdSequence < ::RuboCop::Cop::Base
RESTRICT_ON_SEND = %i[sequence].freeze

def on_send(node)
return unless node.first_argument.value == :id
return unless node.first_argument&.sym_type? &&
node.first_argument.value == :id

add_offense(node) do |corrector|
range_to_remove = range_by_whole_lines(
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/factory_bot/id_sequence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,20 @@
end
RUBY
end

it 'does not register an offense for a `sequence` with non-symbol argment' do
expect_no_offenses(<<~RUBY)
FactoryBot.define do
sequence(id)
end
RUBY
end

it 'does not register an offense for a `sequence` without argument' do
expect_no_offenses(<<~RUBY)
FactoryBot.define do
sequence
end
RUBY
end
end

0 comments on commit 85f0891

Please sign in to comment.