Skip to content

Commit d53315f

Browse files
authored
Add an example for implicit with factory and traits
1 parent d5ef76c commit d53315f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spec/rubocop/cop/factory_bot/association_style_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ def inspected_source_filename
205205
RUBY
206206
end
207207
end
208+
context 'when implicit association has factory and traits' do
209+
'option' do
210+
it 'registers and corrects an offense' do
211+
expect_offense(<<~RUBY)
212+
factory :article do
213+
author factory: %i[user admin]
214+
^^^^^^^^^^^^^^^^^^^^^ Use explicit style to define associations.
215+
end
216+
RUBY
208217
context 'when implicit association has factory and traits' do
209218
'option' do
210219
it 'registers and corrects an offense' do
@@ -223,6 +232,14 @@ def inspected_source_filename
223232
end
224233
end
225234

235+
expect_correction(<<~RUBY)
236+
factory :article do
237+
association :author, :admin, factory: :user
238+
end
239+
RUBY
240+
end
241+
end
242+
226243
context 'when default non implicit association method name is used' do
227244
it 'does not register an offense' do
228245
expect_no_offenses(<<~RUBY)

0 commit comments

Comments
 (0)