# === Custom Classes for Testing ===

class Planet_Create
  
  include Go_Mon::Model 

  key :name do
    anything
  end
  
  key :latin_name do
    in_array %w{ planetius }
  end
  
  pseudo :insult do
    anything
  end

  creator :anyone do
    allow_if true
    ask_for :latin_name
    demand :name
  end
  
end

describe 'Creating a document' do

  it 'raise Required_Key, with errors msg, if missing required field' do

    planet = Planet_Create.new
    lambda {
      planet.create nil, {}
    }.should.raise(Planet_Create::Required_Key).
      message.should =~ /"name", is required/
    
  end
  
  it 'does not save pseudo fields' do
    
    key = 'insult'
    doc      = Planet_Create.new
    doc.create( nil, 
               :name =>'New Name', 
               key =>"something"
              )
    new_doc  = Planet_Create.db.find_one('_id' => doc.data._id)
    %w{ _id name }.sort.should == new_doc.keys.sort
  end
  
end # === class _create


