Skip to content

Instantly share code, notes, and snippets.

@opsb
Created December 10, 2010 09:10
Show Gist options
  • Save opsb/736002 to your computer and use it in GitHub Desktop.
Save opsb/736002 to your computer and use it in GitHub Desktop.
Mongoid embeds_many bug - loses create after some some destroy_all/create sequences
require 'rubygems'
require 'mongoid'
require 'rspec'
require 'method_lister'
Mongoid.configure do |config|
name = "association_bug"
config.master = Mongo::Connection.new.db(name)
end
class Commit
include Mongoid::Document
embeds_many :tasks
end
class Task
include Mongoid::Document
embedded_in :commit, :inverse_of => :tasks
end
def show_methods(object)
puts (object.methods.sort - Object.new.methods).join(", ")
end
describe Commit do
before do
@commit = Commit.create
end
it "passes" do
@commit.tasks.destroy_all
@commit.tasks.create
@commit.tasks.destroy_all
@commit.tasks.create
end
it "passes" do
@commit.tasks.destroy_all
@commit.tasks.create
@commit.tasks.create
@commit.tasks.create
end
it "fails" do
@commit.tasks.create
@commit.tasks.create
@commit.tasks.destroy_all
@commit.tasks.create # this call fails
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment