class

ActiveRecord::Relation

v3.2.8 - Show latest stable - Superclass: Object

Active Record Relation

Included modules

  • ActiveRecord::Batches
  • ActiveRecord::Calculations
  • ActiveRecord::Delegation
  • ActiveRecord::Explain
  • ActiveRecord::FinderMethods
  • ActiveRecord::QueryMethods
  • ActiveRecord::SpawnMethods

Constants

ASSOCIATION_METHODS = [:includes, :eager_load, :preload]

JoinOperation = Struct.new(:relation, :join_class, :on)

MULTI_VALUE_METHODS = [:select, :group, :order, :joins, :where, :having, :bind]

SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :from, :reordering, :reverse_order, :uniq]

Attributes

[RW]default_scoped
[RW]default_scoped?
[RW]extensions
[R]klass
[R]loaded
[R]loaded?
[R]table

Files

  • activerecord/lib/active_record/relation.rb

1Note

expect_any_instance_of(ActiveRecord::Relation).to receive(:create_with) and others do not work

michalhantl ยท Aug 26, 2019

If you're doing

expect_any_instance_of(ActiveRecord::Relation).to receive(:create_with) 

and it does not work, try:

expect_any_instance_of(ActiveRecord::Associations::CollectionProxy).to receive(:create_with) { |proxy, attributes|
expect(proxy.klass).to eq(RecordClass)
expect(attributes[:....]).to eq(...)
double('find_or_create_by!' => Proc.new {})
}

or when testing "find_or_create_by"

expect_any_instance_of(ActiveRecord::Associations::CollectionProxy).to receive(:find_or_create_by) { |proxy, attributes|
expect(proxy.klass).to eq(RecordClass)
expect(attributes[:....]).to eq(...)
}