@@ -61,6 +61,28 @@ def test_all
6161 assert_equal "David" , all . last . name
6262 end
6363
64+ def test_all_immediately_finds_by_default
65+ requests = ActiveResource ::HttpMock . requests
66+
67+ collection = Person . all
68+
69+ assert_equal [ "/people.json" ] , requests . map ( &:path )
70+ assert_kind_of Person , collection . first
71+ end
72+
73+ def test_all_with_lazy_collections
74+ requests = ActiveResource ::HttpMock . requests
75+
76+ collection = DeferredPerson . all
77+
78+ assert_empty requests . map ( &:path )
79+
80+ resource = collection . first
81+
82+ assert_equal [ "/people.json" ] , requests . map ( &:path )
83+ assert_kind_of Person , resource
84+ end
85+
6486 def test_all_with_params
6587 all = StreetAddress . all ( params : { person_id : 1 } )
6688 assert_equal 1 , all . size
@@ -84,7 +106,7 @@ def test_where_with_clauses
84106 def test_where_with_multiple_where_clauses
85107 ActiveResource ::HttpMock . respond_to . get "/people.json?id=2&name=david" , { } , @people_david
86108
87- people = Person . where ( id : 2 ) . where ( name : "david" )
109+ people = DeferredPerson . where ( id : 2 ) . where ( name : "david" )
88110 assert_equal 1 , people . size
89111 assert_kind_of Person , people . first
90112 assert_equal 2 , people . first . id
@@ -94,7 +116,7 @@ def test_where_with_multiple_where_clauses
94116 def test_where_chained_from_all
95117 ActiveResource ::HttpMock . respond_to . get "/records.json?id=2" , { } , @people_david
96118
97- people = Person . all ( from : "/records.json" ) . where ( id : 2 )
119+ people = DeferredPerson . all ( from : "/records.json" ) . where ( id : 2 )
98120 assert_equal 1 , people . size
99121 assert_kind_of Person , people . first
100122 assert_equal 2 , people . first . id
@@ -104,7 +126,7 @@ def test_where_chained_from_all
104126 def test_where_with_chained_into_all
105127 ActiveResource ::HttpMock . respond_to . get "/records.json?id=2&name=david" , { } , @people_david
106128
107- people = Person . where ( id : 2 ) . all ( from : "/records.json" , params : { name : "david" } )
129+ people = DeferredPerson . where ( id : 2 ) . all ( from : "/records.json" , params : { name : "david" } )
108130 assert_equal 1 , people . size
109131 assert_kind_of Person , people . first
110132 assert_equal 2 , people . first . id
@@ -113,7 +135,7 @@ def test_where_with_chained_into_all
113135
114136 def test_where_loading
115137 ActiveResource ::HttpMock . respond_to . get "/people.json?id=2" , { } , @people_david
116- people = Person . where ( id : 2 )
138+ people = DeferredPerson . where ( id : 2 )
117139
118140 assert_changes -> { ActiveResource ::HttpMock . requests . count } , from : 0 , to : 1 do
119141 people . load
@@ -125,7 +147,7 @@ def test_where_loading
125147
126148 def test_where_reloading
127149 ActiveResource ::HttpMock . respond_to . get "/people.json?id=2" , { } , @people_david
128- people = Person . where ( id : 2 )
150+ people = DeferredPerson . where ( id : 2 )
129151
130152 assert_changes -> { ActiveResource ::HttpMock . requests . count } , from : 0 , to : 1 do
131153 assert_equal 1 , people . size
0 commit comments