Skip to content

Commit 3819267

Browse files
committed
add test cases and expect_correction
1 parent d73c987 commit 3819267

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

spec/rubocop/cop/rails/redundant_active_record_all_method_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@
213213
end
214214
end
215215

216+
it 'registers an offense and corrects when the receiver for `all` is Active Record relation object' do
217+
expect_offense(<<~RUBY)
218+
user.articles.all.order(:created_at)
219+
^^^ Redundant `all` detected.
220+
RUBY
221+
222+
expect_correction(<<~RUBY)
223+
user.articles.order(:created_at)
224+
RUBY
225+
end
226+
216227
it 'does not register an offense when no method follows `all`' do
217228
expect_no_offenses(<<~RUBY)
218229
User.all
@@ -254,6 +265,12 @@ class User < ApplicationRecord
254265
^^^ Redundant `all` detected.
255266
end
256267
RUBY
268+
269+
expect_correction(<<~RUBY)
270+
class User < ApplicationRecord
271+
scope :admins, -> { where(admin: true) }
272+
end
273+
RUBY
257274
end
258275

259276
it 'registers an offense when inheriting `::ApplicationRecord`' do
@@ -263,6 +280,12 @@ class User < ::ApplicationRecord
263280
^^^ Redundant `all` detected.
264281
end
265282
RUBY
283+
284+
expect_correction(<<~RUBY)
285+
class User < ::ApplicationRecord
286+
scope :admins, -> { where(admin: true) }
287+
end
288+
RUBY
266289
end
267290

268291
it 'registers an offense when inheriting `ActiveRecord::Base`' do
@@ -272,6 +295,12 @@ class User < ActiveRecord::Base
272295
^^^ Redundant `all` detected.
273296
end
274297
RUBY
298+
299+
expect_correction(<<~RUBY)
300+
class User < ActiveRecord::Base
301+
scope :admins, -> { where(admin: true) }
302+
end
303+
RUBY
275304
end
276305

277306
it 'registers an offense when inheriting `::ActiveRecord::Base`' do
@@ -281,6 +310,12 @@ class User < ::ActiveRecord::Base
281310
^^^ Redundant `all` detected.
282311
end
283312
RUBY
313+
314+
expect_correction(<<~RUBY)
315+
class User < ::ActiveRecord::Base
316+
scope :admins, -> { where(admin: true) }
317+
end
318+
RUBY
284319
end
285320
end
286321
end

0 commit comments

Comments
 (0)