Skip to content

Commit b8b020d

Browse files
committed
test avoiding N+1 without additional query when join used in query
1 parent c8c7d6f commit b8b020d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ruby_event_store-active_record/spec/event_repository_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,21 @@ module ActiveRecord
292292
end
293293
end
294294

295+
specify "avoid N+1 without additional query when join is used for querying" do
296+
repository.append_to_stream(
297+
[SRecord.new, SRecord.new],
298+
Stream.new("stream"),
299+
ExpectedVersion.auto
300+
)
301+
expect { repository.read(specification.stream("stream").of_type("type").result) }.to match_query_count(1)
302+
expect { repository.read(specification.stream("stream").as_of.result) }.to match_query_count(1)
303+
expect { repository.read(specification.stream("stream").as_at.result) }.to match_query_count(1)
304+
expect { repository.read(specification.stream("stream").older_than(Time.now).result) }.to match_query_count(1)
305+
expect { repository.read(specification.stream("stream").older_than_or_equal(Time.now).result) }.to match_query_count(1)
306+
expect { repository.read(specification.stream("stream").newer_than(Time.now).result) }.to match_query_count(1)
307+
expect { repository.read(specification.stream("stream").newer_than_or_equal(Time.now).result) }.to match_query_count(1)
308+
end
309+
295310
specify "don't join events when no event filtering criteria when counting" do
296311
expect {
297312
repository.count(specification.stream("stream").result)

0 commit comments

Comments
 (0)