213
213
end
214
214
end
215
215
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
+
216
227
it 'does not register an offense when no method follows `all`' do
217
228
expect_no_offenses ( <<~RUBY )
218
229
User.all
@@ -254,6 +265,12 @@ class User < ApplicationRecord
254
265
^^^ Redundant `all` detected.
255
266
end
256
267
RUBY
268
+
269
+ expect_correction ( <<~RUBY )
270
+ class User < ApplicationRecord
271
+ scope :admins, -> { where(admin: true) }
272
+ end
273
+ RUBY
257
274
end
258
275
259
276
it 'registers an offense when inheriting `::ApplicationRecord`' do
@@ -263,6 +280,12 @@ class User < ::ApplicationRecord
263
280
^^^ Redundant `all` detected.
264
281
end
265
282
RUBY
283
+
284
+ expect_correction ( <<~RUBY )
285
+ class User < ::ApplicationRecord
286
+ scope :admins, -> { where(admin: true) }
287
+ end
288
+ RUBY
266
289
end
267
290
268
291
it 'registers an offense when inheriting `ActiveRecord::Base`' do
@@ -272,6 +295,12 @@ class User < ActiveRecord::Base
272
295
^^^ Redundant `all` detected.
273
296
end
274
297
RUBY
298
+
299
+ expect_correction ( <<~RUBY )
300
+ class User < ActiveRecord::Base
301
+ scope :admins, -> { where(admin: true) }
302
+ end
303
+ RUBY
275
304
end
276
305
277
306
it 'registers an offense when inheriting `::ActiveRecord::Base`' do
@@ -281,6 +310,12 @@ class User < ::ActiveRecord::Base
281
310
^^^ Redundant `all` detected.
282
311
end
283
312
RUBY
313
+
314
+ expect_correction ( <<~RUBY )
315
+ class User < ::ActiveRecord::Base
316
+ scope :admins, -> { where(admin: true) }
317
+ end
318
+ RUBY
284
319
end
285
320
end
286
321
end
0 commit comments