DG IZ started the collection spec

This commit is contained in:
ilya 2010-07-20 14:01:56 -07:00
parent 0f95b93bab
commit 1bd2c16ef1
3 changed files with 45 additions and 0 deletions

13
app/models/collection.rb Normal file
View file

@ -0,0 +1,13 @@
class Collection
include MongoMapper::Document
key :name, String
belongs_to :person, :class_name => 'Person'
validates_presence_of :name
#many :posts, :class_name => 'Post', :foreign_key => :collection_id
end

View file

@ -16,6 +16,7 @@ class Person
one :profile, :class_name => 'Profile'
many :posts, :class_name => 'Post', :foreign_key => :person_id
many :collections, :class_name => 'Collection', :foreign_key => :person_id
timestamps!

View file

@ -0,0 +1,31 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Collection do
before do
@user = Factory.create(:user)
@collection = Collection.new(:name => "test collection")
end
it 'should belong to a person' do
person = Factory.create(:person)
@collection.person = person
@collection.valid?.should be true
@collection.save
person.collections.count.should == 1
end
it 'should require a name' do
@collection.name = "test collection"
@collection.valid?.should be true
@collection.name = nil
@collection.valid?.should be false
end
it 'should contain photos' do
end
end