-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
Given two classes
class Item include Mongoid::Document has_and_belongs_to_many :tags end class Tag include Mongoid::Document end
If a tag is added to the item.tags collection. item.tag_ids_was returns the current list of ids, rather than the previous list of ids. The same holds true if a tag is removed.
These tests demonstrate the failure
describe "Mongoid relations" do let(:item){ Item.create() } let(:tag){ Tag.create() } context "when a tag is added" do it "reports tag_ids_was == []" do item.tags << tag item.tag_ids_was.should be_empty end end context "when a tag is removed" do before(:each){ item.tags.push(tag); item.save! } it "reports tag_ids_was == [tag.id]" do item.tags.delete tag item.tag_ids_was.should include(tag.id) end end end