diff --git a/app/models/collection.rb b/app/models/collection.rb new file mode 100644 index 000000000..daaceab05 --- /dev/null +++ b/app/models/collection.rb @@ -0,0 +1,11 @@ +class Collection + include MongoMapper::Document + + key :name, String + + belongs_to :person, :class_name => 'Person' + many :photos, :class_name => 'Photo', :foreign_key => :collection_id + + validates_presence_of :name + +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/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/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 78f907600..ccb15f9a7 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -42,7 +42,6 @@ = form_for Photo.new, :html => {:multipart => true} do |f| = f.error_messages %p - %label{:for => "image_form"} Image = f.file_field :image %p = f.submit 'post it!', :class => 'button' diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 3b9ad7a11..e7037c671 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -17,9 +17,6 @@ a { a:hover { color: #018790; } -#show_photo img { - width: 100%; } - #flash_notice, #flash_error, #flash_alert { @@ -233,6 +230,9 @@ li.comment > img.person_picture { .request_buttons > li:first-child { margin-right: 1em; } +#show_photo img { + max-width: 100%; } + #debug_info { margin-top: 20px; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index bc2cc58e2..1d9d85fa2 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -274,7 +274,7 @@ li.comment > img.person_picture #show_photo img - :width 100% + :max-width 100% diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb new file mode 100644 index 000000000..fd80f2d7b --- /dev/null +++ b/spec/models/collection_spec.rb @@ -0,0 +1,46 @@ +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 + 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 + + + +end