Created
October 21, 2011 14:53
-
-
Save coderifous/1304035 to your computer and use it in GitHub Desktop.
Test for broken deletes on habtm relations in Mongoid.
This file contains hidden or 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
source "http://rubygems.org" | |
# Test passes with version 2.2.3 | |
# gem "mongoid", "2.2.3" | |
# Test fails with version 2.3.2 | |
gem "mongoid", "2.3.2" |
This file contains hidden or 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 "bundler/setup" | |
require "mongoid" | |
require "minitest/spec" | |
require 'minitest/autorun' | |
Mongoid.configure do |config| | |
config.skip_version_check = true | |
config.database = Mongo::Connection.new.db("mongoid_sandbox") | |
end | |
class Person | |
include Mongoid::Document | |
has_and_belongs_to_many :companies | |
end | |
class Company | |
include Mongoid::Document | |
has_and_belongs_to_many :people | |
end | |
describe "mongoid habtm" do | |
before do | |
@jim = Person.create | |
@busyconf = Company.create | |
@busyconf.people << @jim | |
@busyconf.reload | |
assert_equal 1, @busyconf.people.count | |
end | |
# This test fails in Mongoid 2.3 | |
it "should handle appends/deletes properly" do | |
@busyconf.people.delete(@jim) | |
@busyconf.reload | |
assert_equal 0, @busyconf.people.count | |
end | |
# This test passes in Mongoid 2.3 | |
it "should not be affected by this" do | |
@busyconf.people.load_all! # <== this is the only difference from the previous test. | |
@busyconf.people.delete(@jim) | |
@busyconf.reload | |
assert_equal 0, @busyconf.people.count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment