From 51fd87db36c46e24a65026d2951715e5b61e804a Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 20 Jul 2010 15:15:11 -0700 Subject: [PATCH] no ideas why collection saving isn't working... --- app/models/collection.rb | 4 +--- app/models/photo.rb | 4 ++++ spec/models/collection_spec.rb | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/models/collection.rb b/app/models/collection.rb index 4184ffdbb..daaceab05 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -4,10 +4,8 @@ class Collection key :name, String belongs_to :person, :class_name => 'Person' + many :photos, :class_name => 'Photo', :foreign_key => :collection_id validates_presence_of :name - #many :posts, :class_name => 'Post', :foreign_key => :collection_id - - end diff --git a/app/models/photo.rb b/app/models/photo.rb index 70e65cb64..10bd71276 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -2,4 +2,8 @@ class Photo < Post require 'carrierwave/orm/mongomapper' include MongoMapper::Document mount_uploader :image, ImageUploader + + key :collection_id, ObjectId + + belongs_to :collection, :class_name => 'Collection' end diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index 4e6ef55eb..fd80f2d7b 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -23,7 +23,22 @@ describe Collection do end it 'should contain photos' do + collection = Collection.create(:name => "test collection") + + photo = Photo.create(:person => @user) + + puts photo.valid? + puts collection.valid? + + puts photo.inspect + puts collection.photos.inspect + + puts 'asdojasd' + puts photo.collection + puts 'asdojasd' + + collection.photos.count.should == 1 end