test/test_dase.rb in dase-3.2.2 vs test/test_dase.rb in dase-3.2.4

- old
+ new

@@ -55,15 +55,44 @@ # the order is: Bobby, Joe, Teddy - due to order(:name) true_counts = [1, 2, 0] # see books.yml compare_counts(traditional_counts, dase_counts, true_counts) end - # Not yet implemented - #should "count quotations" do - # traditional_counts = Author.order(:name).map { |a| a.quotes.count } - # dase_counts = Author.order(:name).includes_count_of(:quotes).map { |a| a.quotes_count } + should "count books for year 2012 using :only option" do + dase_counts = Author.includes_count_of(:books, :only => Book.year2012).order(:name).map { |a| a.books_count } + # the order is: Bobby, Joe, Teddy - due to order(:name) + true_counts = [0, 1, 0] # see books.yml + assert_equal true_counts, dase_counts, "results mismatch" + end + + #should "count using block conditions (arity: 0)" do + # dase_counts = Author.includes_count_of(:books){where(:year => 2012)}.order(:name).map { |a| a.books_count } # # the order is: Bobby, Joe, Teddy - due to order(:name) - # true_counts = [2, 1, 0] # see quotes.yml - # compare_counts(traditional_counts, dase_counts, true_counts) + # true_counts = [0, 1, 0] # see books.yml + # assert_equal true_counts, dase_counts, "results mismatch" #end + # + #should "count using block conditions (arity: 1)" do + # @y = 2012 + # dase_counts = Author.includes_count_of(:books){ |books| books.where(:year => @y)}.order(:name).map { |a| a.books_count } + # # the order is: Bobby, Joe, Teddy - due to order(:name) + # true_counts = [0, 1, 0] # see books.yml + # assert_equal true_counts, dase_counts, "results mismatch" + #end + + should "count likes" do + dase_counts = Author.order(:name).includes_count_of(:scores).map { |a| a.scores_count } + # the order is: Bobby, Joe, Teddy - due to order(:name) + true_counts = [0, 2, 0] # see likes.yml + assert_equal true_counts, dase_counts, "results mismatch" + end + + should "count quotations" do + traditional_counts = Author.order(:name).map { |a| a.quotes.count } + dase_counts = Author.order(:name).includes_count_of(:quotes).map { |a| a.quotes_count } + # the order is: Bobby, Joe, Teddy - due to order(:name) + true_counts = [2, 1, 0] # see quotes.yml + compare_counts(traditional_counts, dase_counts, true_counts) + end + end end