class
ActiveRecord::Relation
v5.1.7 -
Show latest stable
- Superclass: Object
Active Record Relation
Included modules
- ActiveRecord::Batches
- ActiveRecord::Calculations
- ActiveRecord::Delegation
- ActiveRecord::Explain
- ActiveRecord::FinderMethods
- ActiveRecord::QueryMethods
- ActiveRecord::SpawnMethods
- Enumerable
Constants
CLAUSE_METHODS = [:where, :having, :from]
INVALID_METHODS_FOR_DELETE_ALL = [:limit, :distinct, :offset, :group, :having]
MULTI_VALUE_METHODS = [:includes, :eager_load, :preload, :select, :group,\n:order, :joins, :left_joins, :left_outer_joins, :references,\n:extending, :unscope]
SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :reordering,\n:reverse_order, :distinct, :create_with]
VALUE_METHODS = MULTI_VALUE_METHODS + SINGLE_VALUE_METHODS + CLAUSE_METHODS
Attributes
| [R] | klass |
| [R] | loaded |
| [R] | loaded? |
| [R] | model |
| [R] | predicate_builder |
| [R] | table |
Files
- activerecord/lib/active_record/relation.rb
- activerecord/lib/active_record/relation/from_clause.rb
- activerecord/lib/active_record/relation/merger.rb
- activerecord/lib/active_record/relation/query_attribute.rb
- activerecord/lib/active_record/relation/record_fetch_warning.rb
- activerecord/lib/active_record/relation/where_clause.rb
- activerecord/lib/active_record/relation/where_clause_factory.rb
1Note
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(...)
}