Created
May 19, 2015 17:35
-
-
Save JKring/38ebf5348d8a6d837979 to your computer and use it in GitHub Desktop.
Mongoid Criteria .to_a redundancy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### make sure the mongoid.yml is a file in the same directory: | |
# test: | |
# sessions: | |
# default: | |
# database: db | |
# hosts: | |
# - localhost:27017 | |
### run with: | |
# export MONGOID_ENV=test; ruby mongoid_criteria_array_bug.rb | |
require 'rubygems' | |
require 'mongoid' | |
require 'minitest/autorun' | |
Mongoid.load!('mongoid.yml') | |
class Person | |
include Mongoid::Document | |
has_many :pets | |
end | |
class Pet | |
include Mongoid::Document | |
belongs_to :person | |
end | |
describe Person do | |
before do | |
@person = Person.create | |
5.times { Pet.create(person: @person) } | |
end | |
describe "when asked about it's pets" do | |
describe "after finding a pet" do | |
it "does not return redundant pets" do | |
@person.pets.find(@person.pets.first.id) | |
@person.pets.count.must_equal(@person.pets.to_a.size) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment