@@ -63,6 +63,66 @@ def test_where_with_clauses
6363 assert_kind_of StreetAddress , addresses . first
6464 end
6565
66+ def test_where_with_multiple_where_clauses
67+ ActiveResource ::HttpMock . respond_to . get "/people.json?id=2&name=david" , { } , @people_david
68+
69+ people = Person . where ( id : 2 ) . where ( name : "david" )
70+ assert_equal 1 , people . size
71+ assert_kind_of Person , people . first
72+ assert_equal 2 , people . first . id
73+ assert_equal "David" , people . first . name
74+ end
75+
76+ def test_where_chained_from_all
77+ ActiveResource ::HttpMock . respond_to . get "/records.json?id=2" , { } , @people_david
78+
79+ people = Person . all ( from : "/records.json" ) . where ( id : 2 )
80+ assert_equal 1 , people . size
81+ assert_kind_of Person , people . first
82+ assert_equal 2 , people . first . id
83+ assert_equal "David" , people . first . name
84+ end
85+
86+ def test_where_with_chained_into_all
87+ ActiveResource ::HttpMock . respond_to . get "/records.json?id=2&name=david" , { } , @people_david
88+
89+ people = Person . where ( id : 2 ) . all ( from : "/records.json" , params : { name : "david" } )
90+ assert_equal 1 , people . size
91+ assert_kind_of Person , people . first
92+ assert_equal 2 , people . first . id
93+ assert_equal "David" , people . first . name
94+ end
95+
96+ def test_where_loading
97+ ActiveResource ::HttpMock . respond_to . get "/people.json?id=2" , { } , @people_david
98+ people = Person . where ( id : 2 )
99+
100+ assert_changes -> { ActiveResource ::HttpMock . requests . count } , from : 0 , to : 1 do
101+ people . load
102+ end
103+ assert_no_changes -> { ActiveResource ::HttpMock . requests . count } , from : 1 do
104+ 10 . times { people . load }
105+ end
106+ end
107+
108+ def test_where_reloading
109+ ActiveResource ::HttpMock . respond_to . get "/people.json?id=2" , { } , @people_david
110+ people = Person . where ( id : 2 )
111+
112+ assert_changes -> { ActiveResource ::HttpMock . requests . count } , from : 0 , to : 1 do
113+ assert_equal 1 , people . size
114+ end
115+ assert_no_changes -> { ActiveResource ::HttpMock . requests . count } , from : 1 do
116+ assert_equal 1 , people . size
117+ end
118+ assert_changes -> { ActiveResource ::HttpMock . requests . count } , from : 1 , to : 2 do
119+ people . reload
120+ end
121+ assert_no_changes -> { ActiveResource ::HttpMock . requests . count } , from : 2 do
122+ assert_equal 1 , people . size
123+ end
124+ end
125+
66126 def test_where_clause_with_unpermitted_params
67127 params = StrongParameters . new ( person_id : "1" )
68128 assert_raises ( ActiveModel ::ForbiddenAttributesError ) { StreetAddress . where ( params ) }
0 commit comments