Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/active_resource/where_clause.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/cases/finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down