From 0c73e637181277c25ff5db8db32d8b5c571c0654 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Thu, 6 Nov 2025 19:54:24 -0500 Subject: [PATCH] Define `WhereClause#collection` Follow-up to https://github.com/rails/activeresource/pull/460 Expose the underlying `ActiveResource::Collection` instance for the `WhereClause` class returned from `Base.all` and `Base.where`. To do so, rename the previously private `resources` method to `collection`, and move it to a public declaration. --- lib/active_resource/where_clause.rb | 19 ++++++++++--------- test/cases/finder_test.rb | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/active_resource/where_clause.rb b/lib/active_resource/where_clause.rb index 62bc318c7a..c1072122d2 100644 --- a/lib/active_resource/where_clause.rb +++ b/lib/active_resource/where_clause.rb @@ -2,13 +2,13 @@ module ActiveResource class WhereClause < BasicObject # :nodoc: - delegate :==, to: :resources - delegate_missing_to :resources + delegate :==, to: :collection + delegate_missing_to :collection def initialize(resource_class, options = {}) @resource_class = resource_class @options = options - @resources = nil + @collection = nil @loaded = false end @@ -22,7 +22,7 @@ def all(options = {}) def load unless @loaded - @resources = @resource_class.find(:all, @options) + @collection = @resource_class.find(:all, @options) @loaded = true end @@ -34,14 +34,15 @@ def reload load end + def collection + load + @collection + end + private - def resources - load - @resources - end def reset - @resources = nil + @collection = nil @loaded = false end end diff --git a/test/cases/finder_test.rb b/test/cases/finder_test.rb index d2cad8e30d..8bb2f809f1 100644 --- a/test/cases/finder_test.rb +++ b/test/cases/finder_test.rb @@ -85,6 +85,7 @@ def test_where_with_multiple_where_clauses ActiveResource::HttpMock.respond_to.get "/people.json?id=2&name=david", {}, @people_david people = Person.where(id: 2).where(name: "david") + assert_kind_of Person.collection_parser, people.collection assert_equal 1, people.size assert_kind_of Person, people.first assert_equal 2, people.first.id