diff --git a/lib/quo/collection_backed_query.rb b/lib/quo/collection_backed_query.rb index d2b3111..403cf08 100644 --- a/lib/quo/collection_backed_query.rb +++ b/lib/quo/collection_backed_query.rb @@ -4,7 +4,7 @@ module Quo class CollectionBackedQuery < Query - prop :total_count, _Nilable(Integer) + prop :total_count, _Nilable(Integer), reader: false # Wrap an enumerable collection or a block that returns an enumerable collection # @rbs data: untyped, props: Symbol => untyped, block: () -> untyped @@ -43,7 +43,7 @@ def query end def results - Quo::CollectionResults.new(self, transformer: transformer) + Quo::CollectionResults.new(self, transformer: transformer, total_count: @total_count) end # @rbs override diff --git a/lib/quo/collection_results.rb b/lib/quo/collection_results.rb index e27e128..a2a8a7e 100644 --- a/lib/quo/collection_results.rb +++ b/lib/quo/collection_results.rb @@ -5,8 +5,9 @@ module Quo class CollectionResults < Results # @rbs override - def initialize(query, transformer: nil) + def initialize(query, transformer: nil, total_count: nil) raise ArgumentError, "Query must be a CollectionBackedQuery" unless query.is_a?(Quo::CollectionBackedQuery) + @total_count = total_count @query = query @configured_query = query.unwrap @transformer = transformer @@ -27,7 +28,7 @@ def empty? #: bool # of wrapped collection. # @rbs override def total_count #: Integer - @query.total_count || @query.unwrap_unpaginated.size + @total_count || @query.unwrap_unpaginated.size end # Gets the actual count of elements in the page of results (assuming paging is being used, otherwise the count of diff --git a/test/quo/minitest_helpers_test.rb b/test/quo/minitest_helpers_test.rb index 95c1be1..90528e7 100644 --- a/test/quo/minitest_helpers_test.rb +++ b/test/quo/minitest_helpers_test.rb @@ -6,33 +6,11 @@ class Quo::MinitestHelpersTest < ActiveSupport::TestCase include Quo::Minitest::Helpers - test "stub_query" do - stub_query(CommentNotSpamQuery, results: [1, 2]) do + test "fake_query" do + fake_query(CommentNotSpamQuery, results: [1, 2]) do q = CommentNotSpamQuery.new(spam_score_threshold: 0.8) assert_equal 2, q.results.count assert_equal 1, q.results.first end end - - test "mock_query with arguments" do - mock = mock_query(CommentNotSpamQuery, kwargs: {spam_score_threshold: 0.8}, results: [1, 2]) - stub_query(CommentNotSpamQuery, mock: mock, results: [1, 2]) do - q = CommentNotSpamQuery.new(spam_score_threshold: 0.8) - assert_equal 2, q.results.count - assert_equal 1, q.results.first - assert_mock mock - end - end - - test "raises when mock args don't match" do - mock = mock_query(CommentNotSpamQuery, kwargs: {spam_score_threshold: 0.8}, results: [1, 2]) - stub_query(CommentNotSpamQuery, mock: mock, results: [1, 2]) do - assert_raises(ArgumentError) do - CommentNotSpamQuery.new - end - assert_raises(MockExpectationError) do - CommentNotSpamQuery.new(spam_score_threshold: 0.9) - end - end - end end