Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created July 23, 2010 18:59
Show Gist options
  • Save bernerdschaefer/487877 to your computer and use it in GitHub Desktop.
Save bernerdschaefer/487877 to your computer and use it in GitHub Desktop.
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