Created
December 10, 2010 09:10
-
-
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
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
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