1

In our application, we have used this

expect_any_instance_of(Order::ActiveRecord_Relation)
  .to receive(:something)

As we upgraded the application to rails 5.2 we are getting the following error

NameError:
   private constant #<Class:0x000055aa351fc9a0>::ActiveRecord_Relation referenced

Is there a way to check for ActiveRecord::Relation of a specific Model with expect_any_instance_of

There a issue raised for the same https://github.com/rails/rails/issues/30943

strivedi183
  • 4,749
  • 2
  • 31
  • 38
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88
  • There is clear explanation from core dev, you're trying to access private method. It's not a part of public API, so you can't use it. – Roman Kiselenko Sep 05 '18 at 08:03
  • I know, that's why I am asking if there is any way to check the same without using the `Class:>::ActiveRecord_Relation` – Deepak Mahakale Sep 05 '18 at 09:22
  • 1
    that's probably not the best test expectation, show us the code you're testing and we can give you an alternative perhaps – Anthony Sep 05 '18 at 16:25

2 Answers2

3

try this Order.const_get(:ActiveRecord_Relation). it should make it work in rails >= 5.2

H.Elsayed
  • 431
  • 2
  • 11
0
expect_any_instance_of(Order.const_get(:ActiveRecord_Relation))
  .to receive(:something)
spirito_libero
  • 1,206
  • 2
  • 13
  • 21