Skip to content

Commit c6d0f37

Browse files
committed
adding test that shows the error: chaining scopes modifies the parent scope
1 parent b4e5804 commit c6d0f37

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/unit/query_builder_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,19 @@ def test_can_specify_empty_string_filter_value
220220
Article.where(:'author.id' => '').to_a
221221
end
222222

223+
def test_scopes_are_nondestructive
224+
first_stub = stub_request(:get, "http://example.com/articles?page[page]=1&page[per_page]=1")
225+
.to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: [] }.to_json)
226+
227+
all_stub = stub_request(:get, "http://example.com/articles")
228+
.to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: [] }.to_json)
229+
230+
scope = Article.where()
231+
232+
scope.first
233+
scope.all
234+
235+
assert_requested first_stub, times: 1
236+
assert_requested all_stub, times: 1
237+
end
223238
end

0 commit comments

Comments
 (0)