Skip to content

Commit

Permalink
Better test example [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnn committed Jun 2, 2014
1 parent 182cc32 commit fdd963e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions examples/mongoid_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'mongoid'
require 'mongoid/support/query_counter'
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)

Mongoid.configure.connect_to("mongoid_test")

Expand All @@ -20,12 +23,16 @@ class Person
field :name
end

p = Person.create!(name: 'arthurnn')
post1 = Post.create!(person: p)
post2 = Post.create!(person: p)
class BugTest < Minitest::Test
def test_query_count
p = Person.create!(name: 'arthurnn')
Post.create!(person: p)
Post.create!(person: p)

query_counter = count_queries do
Person.includes(:posts).all.to_a
end
query_counter = count_queries do
Person.includes(:posts).all.to_a
end

p query_counter
assert_equal 2, query_counter
end
end

0 comments on commit fdd963e

Please sign in to comment.