Skip to content

Instantly share code, notes, and snippets.

@JKring
Created May 19, 2015 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JKring/38ebf5348d8a6d837979 to your computer and use it in GitHub Desktop.
Save JKring/38ebf5348d8a6d837979 to your computer and use it in GitHub Desktop.
Mongoid Criteria .to_a redundancy
### 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