From 1bd2c16ef1233025418b324973a9a5803dad0dbf Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 20 Jul 2010 14:01:56 -0700 Subject: [PATCH] DG IZ started the collection spec --- app/models/collection.rb | 13 +++++++++++++ app/models/person.rb | 1 + spec/models/collection_spec.rb | 31 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 app/models/collection.rb create mode 100644 spec/models/collection_spec.rb diff --git a/app/models/collection.rb b/app/models/collection.rb new file mode 100644 index 000000000..4184ffdbb --- /dev/null +++ b/app/models/collection.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 968ba5dd7..be06c0b26 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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! diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb new file mode 100644 index 000000000..4e6ef55eb --- /dev/null +++ b/spec/models/collection_spec.rb @@ -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