Active Record Relation

Constants

VALUE_METHODS = MULTI_VALUE_METHODS + SINGLE_VALUE_METHODS + CLAUSE_METHODS

INVALID_METHODS_FOR_DELETE_ALL = [:distinct, :with]

CLAUSE_METHODS = [:where, :having, :from]

SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :reordering, :strict_loading, :reverse_order, :distinct, :create_with, :skip_query_cache]

MULTI_VALUE_METHODS = [:includes, :eager_load, :preload, :select, :group, :order, :joins, :left_outer_joins, :references, :extending, :unscope, :optimizer_hints, :annotate, :with]

Attributes

[R] loaded?
[R] model
[RW] skip_preloading_value
[R] predicate_builder
[R] loaded
[R] klass
[R] table
Show files where this class is defined (6 files)
Register or log in to add new notes.
August 26, 2019
0 thanks

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

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(...)
}