Merge branch 'master' of github.com:diaspora/diaspora_rails into ostatus

This commit is contained in:
maxwell 2010-07-22 11:54:07 -07:00
commit daf0de2eb0
10 changed files with 57 additions and 41 deletions

View file

@ -2,12 +2,10 @@ class PhotosController < ApplicationController
before_filter :authenticate_user!
def create
@photo = Photo.new(params[:photo])
@photo = Photo.instantiate(params[:photo])
@photo.person = current_user
#@photo.album = Album.first(:id => params[:photo][:album_id])
if @photo.save
#@photo.album.save
flash[:notice] = "Successfully uploaded photo."
redirect_to @photo.album
else

View file

@ -36,4 +36,7 @@ class Album
photos.each{|p| p.destroy}
end
def propagate_retraction
Retraction.for(self).notify_people
end
end

View file

@ -14,9 +14,16 @@ class Photo < Post
validates_presence_of :album
def self.instantiate params = {}
image_file = params[:image]
params.delete :image
photo = Photo.new(params)
photo.image.store! image_file
photo
end
def remote_photo
User.first.url.chop + image.path
User.owner.url.chop + image.url
end
def remote_photo= remote_path

View file

@ -10,7 +10,7 @@ class ImageUploader < CarrierWave::Uploader::Base
def extension_white_list
%w(jpg jpeg gif png)
end
version :thumb_small do
process :resize_to_fill => [30,30]
end

View file

@ -2,6 +2,6 @@ CarrierWave.configure do |config|
#config.grid_fs_database = "#diaspora-#{Rails.env}"
#config.grid_fs_host = 'localhost'
#config.grid_fs_access_url = "/images"
#config.storage = :grid_fs
config.storage = :file
config.storage = :grid_fs
#config.storage = :file
end

View file

@ -35,7 +35,7 @@ module Diaspora
object.person = parse_owner_from_xml post.to_s if object.respond_to? :person
objects << object
rescue
puts "Not a real type: #{object.to_s}"
Rails.logger.info "Not a real type: #{object.to_s}"
end
end
objects

View file

@ -44,4 +44,8 @@ end
Factory.define :post do |p|
end
Factory.define :photo do |p|
p.image File.open( File.dirname(__FILE__) + '/fixtures/bp.jpeg')
end
Factory.define(:comment) {}

View file

@ -24,16 +24,16 @@ describe Album do
it 'should contain photos' do
album = Album.create(:name => "test collection")
photo = Photo.new(:person => @user)
photo = Factory.build(:photo, :person => @user)
album.photos << photo
album.photos.count.should == 1
end
it 'should remove all photos on album delete' do
photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now)
photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now-1)
photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now-2)
photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now)
photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-1)
photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-2)
@album.photos += [photo_one, photo_two, photo_three]
@ -45,9 +45,9 @@ describe Album do
describe 'traversing' do
before do
@album = Album.create(:name => "test collection")
@photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now)
@photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now+1)
@photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2)
@photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now)
@photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+1)
@photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2)
@album.photos += [@photo_one, @photo_two, @photo_three]
end
@ -76,9 +76,6 @@ describe Album do
@album.person = @user
@album.save
@xml = @album.to_xml.to_s
@photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now)
@photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now+1)
@photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2)
end
it 'should have a person' do
@xml.include?(@album.person.id.to_s).should be true

View file

@ -5,16 +5,35 @@ describe Photo do
@user = Factory.create(:user)
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
@photo = Photo.new(:person => @user, :album => Album.create(:name => "foo"))
@album = Album.create(:name => "foo", :person => @user)
@photo = Photo.new(:person => @user, :album => @album)
end
it 'should have a constructor' do
photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name))
photo.save.should be true
photo.image.read.nil?.should be false
end
it 'should save a @photo to GridFS' do
file = File.open(@fixture_name)
@photo.image = file
@photo.image.store! File.open(@fixture_name)
@photo.save.should == true
binary = @photo.image.read
fixture_binary = File.open(@fixture_name).read
binary.should == fixture_binary
end
it 'must have an album' do
photo = Photo.new(:person => @user)
photo.image = File.open(@fixture_name)
photo.save
photo.valid?.should be false
photo.album = Album.create(:name => "foo", :person => @user)
photo.save
Photo.first.album.name.should == 'foo'
end
describe 'non-image files' do
it 'should not store' do
file = File.open(@fail_fixture_name)
@ -33,13 +52,7 @@ describe Photo do
end
it 'must have an album' do
photo = Photo.new(:person => @user)
photo.valid?.should be false
photo.album = Album.new(:name => "foo")
photo.save
Photo.first.album.name.should == 'foo'
end
end
describe 'with encryption' do
@ -53,9 +66,9 @@ describe Photo do
end
it 'should save a signed @photo to GridFS' do
@photo.image = File.open(@fixture_name)
@photo.save.should == true
@photo.verify_creator_signature.should be true
photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name))
photo.save.should == true
photo.verify_creator_signature.should be true
end
end
@ -63,21 +76,15 @@ describe Photo do
describe 'remote photos' do
it 'should write the url on serialization' do
@photo.image = File.open(@fixture_name)
@photo.image.store!
@photo.save
xml = @photo.to_xml.to_s
xml.include?(@photo.image.path).should be true
remote_photo = Photo.from_xml xml
@photo.destroy
remote_photo.image.read.nil?.should be false
xml.include?(@photo.image.url).should be true
end
it 'should have an album id on serialization' do
@photo.image = File.open(@fixture_name)
xml = @photo.to_xml.to_s
xml.include?(@photo.album.id.to_s).should be true
remote_photo = Photo.from_xml xml
@photo.destroy
remote_photo.save.should be true
remote_photo.album.nil?.should be false
end
end
end

View file

@ -156,7 +156,7 @@ describe 'user encryption' do
message = Factory.create(:status_message, :person => @user)
@user.comment "Yeah, it was great", :on => message
message.comments.first.verify_creator_signature.should be true
StatusMessage.first.comments.first.verify_post_creator_signature.should be true
StatusMessage.first(:message => message.message).comments.first.verify_post_creator_signature.should be true
end
it 'should verify a comment made on a remote post by a different friend' do