Created
July 23, 2010 18:59
-
-
Save bernerdschaefer/487877 to your computer and use it in GitHub Desktop.
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 'mongoid' | |
require 'rspec' | |
Mongoid.configure do |config| | |
config.master = Mongo::Connection.new.db('testing') | |
end | |
class Inventory | |
include Mongoid::Document | |
field :item_name | |
field :codes, :type => Array | |
key :item_name | |
def add_code(code) | |
if codes.nil? || codes.class != Array | |
self.codes = [] | |
end | |
self.codes << code | |
end | |
collection.remove | |
end | |
inv = Inventory.create(:item_name => "1") | |
inv.add_code('foo') | |
inv.save.should == true | |
Inventory.first.codes.should == ['foo'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment