DG IZ started the collection spec
This commit is contained in:
parent
0f95b93bab
commit
1bd2c16ef1
3 changed files with 45 additions and 0 deletions
13
app/models/collection.rb
Normal file
13
app/models/collection.rb
Normal 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
|
||||
|
|
@ -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!
|
||||
|
||||
|
|
|
|||
31
spec/models/collection_spec.rb
Normal file
31
spec/models/collection_spec.rb
Normal 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
|
||||
Loading…
Reference in a new issue