Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
Raphael 2010-11-04 13:34:57 -07:00
commit c1703edc22
40 changed files with 129 additions and 692 deletions

View file

@ -1,89 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class AlbumsController < ApplicationController
before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => [:index, :show]
def index
if params[:person_id]
@person = current_user.visible_people.find_by_person_id(params[:person_id])
end
@person ||= current_user.person
@albums = current_user.visible_posts(:_type => 'Album').paginate :page => params[:page], :per_page => 9, :order => 'created_at DESC'
respond_with @albums
end
def create
aspects = params[:album][:to]
@album = current_user.build_post(:album, params[:album])
if @album.save
raise 'MongoMapper failed to catch a failed save' unless @album.id
current_user.dispatch_post(@album, :to => aspects)
flash[:notice] = I18n.t 'albums.create.success', :name => @album.name
redirect_to :action => :show, :id => @album.id, :aspect =>aspects
else
flash[:error] = I18n.t 'albums.create.failure'
redirect_to albums_path(:aspect =>aspects)
end
end
def new
@album = Album.new
end
def destroy
@album = current_user.find_visible_post_by_id params[:id]
@album.destroy
flash[:notice] = I18n.t 'albums.destroy.success', :name => @album.name
respond_with :location => albums_url
end
def show
@person = current_user.visible_people.find_by_person_id(params[:person_id]) if params[:person_id]
@person ||= current_user.person
@album = :uploads if params[:id] == "uploads"
@album ||= current_user.find_visible_post_by_id(params[:id])
unless @album
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
if @album == :uploads
@album_id = nil
@album_name = "Uploads"
@album_photos = current_user.visible_posts(:_type => "Photo", :album_id => nil, :person_id => @person.id)
else
@album_id = @album.id
@album_name = @album.name
@album_photos = @album.photos
end
respond_with @album
end
end
def edit
@album = current_user.find_visible_post_by_id params[:id]
redirect_to @album unless current_user.owns? @album
end
def update
@album = current_user.find_visible_post_by_id params[:id]
if current_user.update_post( @album, params[:album] )
flash[:notice] = I18n.t 'albums.update.success', :name => @album.name
respond_with @album
else
flash[:error] = I18n.t 'albums.update.failure', :name => @album.name
render :action => :edit
end
end
end

View file

@ -56,15 +56,13 @@ class DevUtilitiesController < ApplicationController
def set_profile_photo
render :nothing => true
album = current_user.build_post(:album, :name => "Profile Photos")
current_user.dispatch_post(album, :to => current_user.aspects.first.id)
backer_number = YAML.load_file(Rails.root.join('config','backer_number.yml'))[:seed_number].to_i
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
@fixture_name = File.join(File.dirname(__FILE__), "..", "..", "public", "images", "user", "#{username}.jpg")
photo = Photo.new(:album => album)
photo = Photo.new
photo.person = current_user.person
photo.image.store! File.open(@fixture_name)
photo.save

View file

@ -10,18 +10,17 @@ class PhotosController < ApplicationController
def index
if params[:person_id]
@person = current_user.contact_for_person_id(params[:person_id]).person
@person = current_user.contact_for_person_id(params[:person_id])
@person = @person.person if @person
end
@person ||= current_user.person
@photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id)
@albums = current_user.visible_posts(:_type => "Album", :person_id => @person.id)
@aspect = :photos
end
def create
album = current_user.find_visible_post_by_id( params[:photo][:album_id] )
begin
params[:photo][:user_file] = file_handler(params)
@ -31,34 +30,32 @@ class PhotosController < ApplicationController
if @photo.save
raise 'MongoMapper failed to catch a failed save' unless @photo.id
current_user.dispatch_post(@photo, :to => params[:photo][:to])
respond_to do |format|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
end
else
respond_with :location => album, :error => message
respond_with :location => photos_path, :error => message
end
rescue TypeError
message = I18n.t 'photos.create.type_error'
respond_with :location => album, :error => message
respond_with :location => photos_path, :error => message
rescue CarrierWave::IntegrityError
message = I18n.t 'photos.create.integrity_error'
respond_with :location => album, :error => message
respond_with :location => photos_path, :error => message
rescue RuntimeError => e
message = I18n.t 'photos.create.runtime_error'
respond_with :location => album, :error => message
respond_with :location => photos_path, :error => message
raise e
end
end
def new
@photo = Photo.new
@album = current_user.album_by_id(params[:album_id])
render :partial => 'new_photo'
respond_with @photo
end
def destroy
@ -67,12 +64,9 @@ class PhotosController < ApplicationController
if photo
photo.destroy
flash[:notice] = I18n.t 'photos.destroy.notice'
redirect = photo.album
end
redirect ||= photos_path
respond_with :location => redirect
respond_with :location => photos_path
end
def show
@ -80,17 +74,15 @@ class PhotosController < ApplicationController
unless @photo
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@album = @photo.album
@ownership = current_user.owns? @photo
respond_with @photo, @album
respond_with @photo
end
end
def edit
@photo = current_user.my_posts.where(:_id => params[:id]).first
if @photo
@album = @photo.album
if @photo = current_user.my_posts.where(:_id => params[:id]).first
respond_with @photo
else
redirect_to photos_path
end

View file

@ -1,21 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module AlbumsHelper
def friends_albums_link
if params[:friends]
I18n.t('albums.helper.friends_albums')
else
link_to I18n.t('albums.helper.friends_albums'), albums_path({:friends => true})
end
end
def your_albums_link
if params[:friends]
link_to I18n.t('albums.helper.your_albums'), albums_path
else
I18n.t('albums.helper.your_albums')
end
end
end

View file

@ -1,17 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module PhotosHelper
def linked_scaled_photo(photo, album)
link_to (image_tag photo.url(:scaled_full)), photo_path(album.next_photo(photo)), :rel => "prefetch"
end
def url_to_prev(photo, album)
photo_path(album.prev_photo(photo))
end
def url_to_next(photo, album)
photo_path(album.next_photo(photo))
end
end

View file

@ -1,44 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Album < Post
xml_reader :name
key :name, String
many :photos, :class_name => 'Photo', :foreign_key => :album_id
timestamps!
validates_presence_of :name, :person
before_destroy :destroy_photos
attr_accessible :name
def self.mine_or_friends(friend_param, current_user)
friend_param ? Album.find_all_by_person_id(current_user.friend_ids) : current_user.person.albums
end
def prev_photo(photo)
n_photo = self.photos.where(:created_at.lt => photo.created_at).sort(:created_at.desc).first
n_photo ? n_photo : self.photos.sort(:created_at.desc).first
end
def next_photo(photo)
p_photo = self.photos.where(:created_at.gt => photo.created_at).sort(:created_at.asc).first
p_photo ? p_photo : self.photos.sort(:created_at.desc).last
end
def mutable?
true
end
protected
def destroy_photos
self.photos.each{|p| p.destroy}
end
end

View file

@ -11,6 +11,7 @@ class HandleValidator < ActiveModel::Validator
end
class Comment
require File.join(Rails.root, 'lib/diaspora/websocket')
include MongoMapper::Document
include ROXML
include Diaspora::Webhooks

View file

@ -30,7 +30,6 @@ class Person
diaspora_handle.downcase!
end
many :albums, :class_name => 'Album', :foreign_key => :person_id
belongs_to :owner, :class_name => 'User'
timestamps!

View file

@ -2,13 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class PhotoAlbumValidator < ActiveModel::Validator
def validate(document)
unless document.album.nil? || document.album.person_id == document.person_id
document.errors[:base] << "You post photos to that album"
end
end
end
class Photo < Post
require 'carrierwave/orm/mongomapper'
include MongoMapper::Document
@ -16,19 +9,13 @@ class Photo < Post
xml_accessor :remote_photo
xml_accessor :caption
xml_reader :album_id
key :album_id, ObjectId
key :caption, String
key :remote_photo_path
key :remote_photo_name
belongs_to :album, :class_name => 'Album'
timestamps!
validates_with PhotoAlbumValidator
attr_accessible :caption
before_destroy :ensure_user_picture
@ -37,7 +24,6 @@ class Photo < Post
photo = super(params)
image_file = params.delete(:user_file)
photo.album_id = params[:album_id]
photo.image.store! image_file
photo
end
@ -69,7 +55,7 @@ class Photo < Post
end
def thumb_hash
{:thumb_url => url(:thumb_medium), :id => id, :album_id => album_id}
{:thumb_url => url(:thumb_medium), :id => id, :album_id => nil}
end
def mutable?

View file

@ -30,17 +30,19 @@ class Retraction
def perform receiving_user_id
Rails.logger.debug "Performing retraction for #{post_id}"
unless Post.first(:diaspora_handle => person.diaspora_handle, :id => post_id)
raise "#{person.inspect} is trying to retract a post they do not own"
end
if self.type.constantize.find_by_id(post_id)
unless Post.first(:diaspora_handle => person.diaspora_handle, :id => post_id)
raise "#{person.inspect} is trying to retract a post they do not own"
end
begin
Rails.logger.debug("Retracting #{self.type} id: #{self.post_id}")
target = self.type.constantize.first(:id => self.post_id)
target.unsocket_from_uid receiving_user_id if target.respond_to? :unsocket_from_uid
target.destroy
rescue NameError
Rails.logger.info("Retraction for unknown type recieved.")
begin
Rails.logger.debug("Retracting #{self.type} id: #{self.post_id}")
target = self.type.constantize.first(:id => self.post_id)
target.unsocket_from_uid receiving_user_id if target.respond_to? :unsocket_from_uid
target.delete
rescue NameError
Rails.logger.info("Retraction for unknown type recieved.")
end
end
end
end

View file

@ -157,12 +157,7 @@ class User
end
def dispatch_post(post, opts = {})
if post.is_a?(Photo) && post.album_id
aspect_ids = aspects_with_post(post.album_id)
aspect_ids.map! { |aspect| aspect.id }
else
aspect_ids = opts.delete(:to)
end
aspect_ids = opts.delete(:to)
aspect_ids = validate_aspect_permissions(aspect_ids)
self.raw_visible_posts << post

View file

@ -1,18 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.album{:id => post.id, :class => ("mine" if current_user.owns?(post))}
%div.name
= link_to post.name, album_path(post)
%div.time
by
= link_to ((current_user.person == post.person)? t('.you') : post.person.real_name), person_path(post.person)
%br
= link_to(how_long_ago(post), album_path(post))
%div.image_cycle
- for photo in post.photos[0..3]
= link_to (image_tag photo.url(:thumb_large)), album_path(post)

View file

@ -1,12 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= form_for Album.new do |album|
= album.error_messages
%p
= album.label :name
= album.hidden_field :to, :value => aspect
= album.text_field :name
= album.submit t('.create'), :class => 'button'

View file

@ -1,25 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%h2= "#{t('.editing')} #{@album.name}"
- form_for @album do |album|
= album.error_messages
%h4
= t('.album_name')
= album.text_field :name
- for photo in @album.photos
.photo_edit_block= image_tag photo.url(:thumb_medium)
.submit_block
= link_to t('cancel'), root_path
or
= album.submit t('.update_album')
.button.delete
= link_to t('.delete_album'), @album, :confirm => t('are_you_sure'), :method => :delete

View file

@ -1,14 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.span-24.last
= render "shared/publisher", :type => :album, :aspect => @aspect
%div
- for album in @albums
= render "album", :post => album
#pagination
= will_paginate @albums

View file

@ -1,46 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
:javascript
$(document).ready(function(){
$(".image_thumb img").load( function() {
$(this).fadeIn("slow");
});
});
- if @album != :uploads
= render 'shared/author_info', :person => @person, :post => @album
- else
= render 'shared/author_info', :person => @person
%ul#breadcrumb
%li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@person)
%li= @album_name
.span-19.appends-1.last
#thumbnails
- for photo in @album_photos
.image_thumb
= link_to (image_tag photo.url(:thumb_medium)), object_path(photo)
.span-5.last
%h2
= @album_name
- if @album != :uploads
="#{t('.updated')} #{how_long_ago(@album)}"
-if current_user.person.id == @person.id
= render 'photos/new_photo', :album_id => @album_id, :aspect_id => "all"
- if @album != :uploads
= link_to t('.edit_album'), edit_album_path(@album_id), :class => 'button'
.album_id{:id => @album_id, :style => "display:hidden;"}
-unless current_user.person.id == @person.id
%h4= "#{t('by')} #{@person.real_name}"

View file

@ -7,11 +7,11 @@
.span-15.last
= render 'aspects/no_friends_message'
= render 'shared/publisher', :type => :status_message, :aspect => @aspect
= render 'shared/publisher', :aspect => @aspect
= render 'aspects/no_posts_message'
%ul#stream
- for post in @posts
= render type_partial(post), :post => post unless post.class == Album
= render type_partial(post), :post => post
#pagination
= will_paginate @posts

View file

@ -7,11 +7,11 @@
.span-15.last
= render 'aspects/no_friends_message'
= render 'shared/publisher', :type => :status_message, :aspect => @aspect
= render 'shared/publisher', :aspect => @aspect
= render 'aspects/no_posts_message'
%ul#stream
- for post in @posts
= render type_partial(post), :post => post unless post.class == Album
= render type_partial(post), :post => post
#pagination
= will_paginate @posts

View file

@ -46,7 +46,7 @@
- if @posts.count > 0
%ul#stream
- for post in @posts
= render type_partial(post), :post => post unless post.class == Album
= render type_partial(post), :post => post
= will_paginate @posts
- else
%h3= t('.no_posts')

View file

@ -6,7 +6,7 @@
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-upload'),
params: {'photo' : { 'album_id' : "#{album_id}", 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"},
params: {'photo' : { 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"},
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
action: "#{photos_path}"
});

View file

@ -22,11 +22,7 @@
.right
= link_to t('delete'), photo_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete"
- if !post.album_id.nil?
=t('.posted_a_new_photo_to')
= link_to post.album.name, object_path(post.album)
- else
posted a photo
posted a photo
%br
%br

View file

@ -6,18 +6,10 @@
%div{:id => @photo.id}
#show_photo
= linked_scaled_photo @photo, @album
= image_tag @photo.url(:scaled_full)
= form_for @photo do |photo|
= photo.label :caption
= photo.text_field :caption, :value => @photo.caption
= photo.submit
%div{:class => 'clear'}
#content_bottom
.back
= link_to "⇧ #{@album.name}", album_path(@album)
-if current_user.owns? @album
.button.right
= link_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete

View file

@ -21,19 +21,7 @@
.image_thumb
= link_to (image_tag photo.url(:thumb_medium)), photo_path(photo)
.span-24.last
%h3
Photos
%div
- for album in @albums
= render "albums/album", :post => album
= link_to "uploads", album_path("uploads")
.span-24.last
%h3
Albums
.span-24.last
#add_photo_pane
= render "photos/new_photo", :album_id => nil, :aspect_id => :all
= render "photos/new_photo", :aspect_id => :all

View file

@ -10,18 +10,15 @@
%ul#breadcrumb
%li= link_to "#{@photo.person.profile.first_name}'s Photos", person_photos_path(@photo.person)
- if !@photo.album_id.nil?
%li= link_to @album.name, album_path(@album)
- else
%li= link_to "uploads", album_path("uploads")
%li= @photo.caption
- if @photo.album
= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo"
|
= link_to "#{t('.full_size')}", @photo.url
|
= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo"
/ we need to do next photo here
/- if @photo.album
/= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo"
/|
/= link_to "#{t('.full_size')}", @photo.url
/|
/= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo"
.span-14.append-1.last
%div{:data=>{:guid=>@photo.id}}
@ -31,9 +28,10 @@
.edit_pane
.controls{:data=>{:actor=>"#{@photo.person.owner.id}",:actor_person=>"#{@photo.person.id}",:image_url=>"#{@photo.url(:thumb_medium)}"}}
= link_to 'make profile photo', '#', :class => "make_profile_photo"
= linked_scaled_photo @photo, @album
= image_tag @photo.url(:scaled_full)
-else
= linked_scaled_photo @photo, @album
= image_tag @photo.url(:scaled_full)
.caption
-if @ownership

View file

@ -22,46 +22,31 @@
#publisher
= owner_image_link
- if( !defined?(type) || type == :status_message )
= form_for StatusMessage.new, :remote => true do |status|
= status.error_messages
%p
= status.label :message, t('.post_a_message_to', :aspect => aspect)
= status.text_area :message, :rows => 2, :value => params[:prefill]
= form_for StatusMessage.new, :remote => true do |status|
= status.error_messages
%p
= status.label :message, t('.post_a_message_to', :aspect => aspect)
= status.text_area :message, :rows => 2, :value => params[:prefill]
= status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
= status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
.options_and_submit
- if aspect == :all
= status.submit t('.share'), :title => "Share with all aspects"
- else
= status.submit t('.share'), :title => "Share with #{aspect}"
.options_and_submit
- if aspect == :all
= status.submit t('.share'), :title => "Share with all aspects"
- else
= status.submit t('.share'), :title => "Share with #{aspect}"
- if aspect == :all
.public_toggle
= status.check_box( :public, {}, true, false )
= t('.make_public')
= link_to '(?)', "#question_mark_pane", :class => 'question_mark'
- if aspect == :all
.public_toggle
= status.check_box( :public, {}, true, false )
= t('.make_public')
= link_to '(?)', "#question_mark_pane", :class => 'question_mark'
.fancybox_content
#question_mark_pane
= render 'shared/public_explain'
.fancybox_content
#question_mark_pane
= render 'shared/public_explain'
#publisher_photo_upload
= t('or')
= render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id), :album_id => nil
- else
= form_for Album.new do |album|
= album.error_messages
%p
= album.label :name
= album.text_field :name
= album.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
.options_and_submit
= album.submit "Create", :class => 'button'
#publisher_photo_upload
= t('or')
= render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id)

View file

@ -81,35 +81,6 @@ en:
reshare: 'Reshare'
author_info:
view_profile: 'View profile'
albums:
album:
you: "you"
new_album:
create: "create"
add_a_new_album: "Add a new album"
show:
edit_album: "Edit Album"
albums: "albums"
updated: "updated"
edit:
album_name: "Album name"
editing: "Editing"
updated: "updated"
update_album: "Update album"
delete_album: "Delete Album"
index:
new_album: "New Album"
create:
success: "You've created an album called %{name}."
failure: "Failed to create album."
update:
success: "Album %{name} successfully edited."
failure: "Failed to edit album %{name}."
destroy:
success: "Album %{name} deleted."
helper:
friends_albums: "Friends Albums"
your_albums: "Your Albums"
aspects:
no_friends_message:
nobody: "We know you have friends — bring them to Diaspora!"
@ -159,7 +130,6 @@ en:
getting_started:
signup_steps: "Complete your sign-up by doing these things:"
'step_1':
albums: "Albums"
you_dont_have_any_photos: "You don't have any photos! Go to the"
page_to_upload_some: "page to upload some."
comments:
@ -268,7 +238,6 @@ en:
info: "Info"
picture: "Picture"
editing_profile: "Editing profile"
albums: "Albums"
you_dont_have_any_photos: "You don't have any photos! Go to the"
page_to_upload_some: "page to upload some."
requests:

View file

@ -8,7 +8,6 @@ Diaspora::Application.routes.draw do
resources :comments, :except => [:index]
resources :requests, :except => [:edit, :update]
resources :photos
resources :albums
resources :services
match '/auth/:provider/callback' => 'services#create'

View file

@ -7,18 +7,16 @@ module PhotoMover
FileUtils::mkdir_p temp_dir
Dir.chdir 'tmp/exports'
albums = user.visible_posts(:person_id => user.person.id, :_type => 'Album')
photos = user.visible_posts(:person_id => user.person.id, :_type => 'Photo')
albums.each do |album|
album_dir = "#{user.id}/#{album.name}"
FileUtils::mkdir_p album_dir
photos_dir = "#{user.id}/photos"
FileUtils::mkdir_p photos_dir
album.photos.each do |photo|
current_photo_location = "#{Rails.root}/public/uploads/images/#{photo.image_filename}"
new_photo_location = "#{album_dir}/#{photo.image_filename}"
photos.each do |photo|
current_photo_location = "#{Rails.root}/public/uploads/images/#{photo.image_filename}"
new_photo_location = "#{photos_dir}/#{photo.image_filename}"
FileUtils::cp current_photo_location new_photo_location
end
FileUtils::cp current_photo_location new_photo_location
end
system("tar", "cf #{user.id}.tar #{user.id}")

View file

@ -69,7 +69,6 @@ module Diaspora
self.aspects.find_all_by_post_ids( id.to_id )
end
def aspects_with_person person
contact_for(person).aspects
end
@ -84,9 +83,6 @@ module Diaspora
self.aspects.all.collect{|x| x.id}
end
def albums_by_aspect aspect
aspect == :all ? raw_visible_posts.find_all_by__type("Album") : aspect.posts.find_all_by__type("Album")
end
end
end
end

View file

@ -1,54 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe AlbumsController do
render_views
before do
@user = make_user
@aspect = @user.aspects.create(:name => "lame-os")
@album = @user.post :album, :to => @aspect.id, :name => 'things on fire'
sign_in :user, @user
end
describe '#create' do
it 'all aspects' do
params = {"album" => {"name" => "Sunsets","to" => "all"}}
post :create, params
end
it 'one aspect' do
params = {"album" => {"name" => "Sunsets","to" => @aspect.id.to_s}}
post :create, params
end
context 'with invalid params' do
it 'should render a flash error message when album name is blank' do
params = {"album" => {"name" => "", "to" => "all"}}
post :create, params
flash[:error].should == "Failed to create album."
end
it 'should redirect back to album page for that given aspect' do
params = {"album" => {"name" => "", "to" => "all"}}
post :create, params
response.should redirect_to albums_path(:aspect => "all")
end
end
end
describe "#update" do
it "should update the name of an album" do
put :update, :id => @album.id, :album => { :name => "new_name"}
@album.reload.name.should eql("new_name")
end
it "doesn't overwrite random attributes" do
new_user = make_user
params = {:name => "Bruisers", :person_id => new_user.person.id}
put('update', :id => @album.id, "album" => params)
@album.reload.person_id.should == @user.person.id
@album.name.should == 'Bruisers'
end
end
end

View file

@ -11,41 +11,26 @@ describe PhotosController do
let!(:aspect) {user.aspects.create(:name => 'winners')}
let(:aspect2) {user2.aspects.create(:name => 'winners')}
let!(:album) {user.post(:album, :to => aspect.id, :name => "room on fire")}
let!(:album2) {user2.post(:album, :to => aspect2.id, :name => "room on fire")}
let(:filename) {'button.png'}
let(:fixture_name) {File.join(File.dirname(__FILE__), '..', 'fixtures', filename)}
let(:image) {File.open(fixture_name)}
let!(:photo){ user.post(:photo, :album_id => album.id, :user_file => image, :to => aspect.id)}
let(:photo_no_album){ user.post(:photo, :user_file => image, :to => aspect.id)}
let!(:photo2){ user2.post(:photo, :album_id => album2.id, :user_file => image, :to => aspect2.id)}
let!(:photo){ user.post(:photo, :user_file => image, :to => aspect.id)}
let!(:photo2){ user2.post(:photo, :user_file => image, :to => aspect2.id)}
before do
friend_users(user, aspect, user2, aspect2)
sign_in :user, user
user.reload
aspect.reload
aspect2.reload
@controller.stub!(:current_user).and_return(user)
end
describe '#create' do
let(:foo) {{:album_id => album.id.to_s}}
before do
@controller.stub!(:file_handler).and_return(image)
end
it 'can make a photo in an album' do
pending
proc{ post :create, :photo => foo, :qqfile => fixture_name }.should change(Photo, :count).by(1)
end
it 'can make a picture without an album' do
pending
end
it 'does not let you create a photo in an album you do not own' do
it 'can make a photo' do
pending
proc{ post :create, :qqfile => fixture_name }.should change(Photo, :count).by(1)
end
end
@ -54,7 +39,6 @@ describe PhotosController do
get :index
assigns[:person].should == user.person
assigns[:photos].should == [photo]
assigns[:albums].should == [album]
end
it 'sets the person to a friend if person_id is set' do
@ -62,7 +46,6 @@ describe PhotosController do
assigns[:person].should == user2.person
assigns[:photos].should == []
assigns[:albums].should == []
end
it 'sets the aspect to photos?' do
@ -77,23 +60,17 @@ describe PhotosController do
get :show, :id => photo.id
assigns[:photo].should == photo
assigns[:album].should == album
assigns[:ownership].should == true
end
end
describe '#edit' do
it 'should let you edit a photo with an album' do
it 'should let you edit a photo' do
get :edit, :id => photo.id
response.code.should == "200"
end
it 'should let you edit a photo you own that does not have an album' do
get :edit, :id => photo_no_album.id
response.code.should == "200"
end
it 'should not let you edit a photo that is not yours' do
get :edit, :id => photo2.id
response.should redirect_to(:action => :index)

View file

@ -30,9 +30,8 @@ describe SocketsController do
end
it 'should actionhash photos' do
@album = @user.post(:album, :name => "Loser faces", :to => @aspect.id)
photo = @user.post(:photo, :album_id => @album.id, :user_file => File.open(@fixture_name))
json = @controller.action_hash(@user.id, photo, :aspect_ids => @user.aspects_with_post(@album.id).map{|g| g.id})
photo = @user.post(:photo, :album_id => nil, :to => @aspect.id, :user_file => File.open(@fixture_name))
json = @controller.action_hash(@user.id, photo, :aspect_ids => :all)
json.include?('photo').should be_true
end

View file

@ -85,6 +85,12 @@ module HelperMethods
UserFixer.fixed_user
end
def uploaded_photo
fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), 'fixtures', fixture_filename)
File.open(fixture_name)
end
class UserFixer
def self.regenerate_user_fixtures
users = {:users => build_user_fixtures}

View file

@ -1,83 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe Album do
let(:user) { make_user }
let(:person) { user.person }
let(:aspect) { user.aspects.create(:name => "Foo") }
let(:album) { user.post(:album, :name => "test collection", :to => aspect.id) }
it 'is valid' do
album.should be_valid
end
it 'validates presence of a name' do
album.name = nil
album.should_not be_valid
end
it 'has many photos' do
album.associations[:photos].type.should == :many
end
it 'should be mutable' do
post = user.post :album, :name => "hello", :to => aspect.id
post.mutable?.should == true
end
it 'has a diaspora_handle' do
album.diaspora_handle.should == user.diaspora_handle
end
context 'when an album has two attached images' do
before do
2.times do
photo = Factory.build(:photo, :person => person, :album => album)
album.photos << photo
end
end
context 'when the album is deleted' do
it 'removes all child photos' do
expect{ album.destroy }.to change(Photo, :count).from(2).to(0)
end
end
end
context 'traversing photos' do
let(:attrs) { {:person => person, :album => album} }
let!(:photo_1) { Factory(:photo, attrs.merge(:created_at => 2.days.ago)) }
let!(:photo_2) { Factory(:photo, attrs.merge(:created_at => 1.day.ago)) }
let!(:photo_3) { Factory(:photo, attrs.merge(:created_at => Time.now)) }
describe '#next_photo' do
it 'returns the next photo' do
album.next_photo(photo_1).id.should == photo_2.id
end
it 'returns the first photo when given the last photo in the album' do
album.next_photo(photo_3).id.should == photo_1.id
end
end
describe '#prev_photo' do
it 'returns the previous photo' do
album.prev_photo(photo_2).id.should == photo_1.id
end
it 'returns the last photo when given the first photo in the album' do
album.prev_photo(photo_1).id.should == photo_3.id
end
end
end
describe 'serialization' do
it 'has a diaspora_handle' do
album.to_diaspora_xml.include?(user.diaspora_handle).should be_true
end
end
end

View file

@ -8,13 +8,12 @@ describe Photo do
before do
@user = make_user
@aspect = @user.aspects.create(:name => "losers")
@album = @user.post :album, :name => "foo", :to => @aspect.id
@fixture_filename = 'button.png'
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
@photo = Photo.new(:album => @album)
@photo = Photo.new
@photo.person = @user.person
@photo.diaspora_handle = @user.person.diaspora_handle
@ -45,10 +44,9 @@ describe Photo do
it 'has a constructor' do
image = File.open(@fixture_name)
photo = Photo.instantiate(
:person => @user.person, :album => @album, :user_file => image)
photo.created_at.nil?.should be true
photo.image.read.nil?.should be false
photo.album.should == @album
:person => @user.person, :user_file => image)
photo.created_at.nil?.should be_true
photo.image.read.nil?.should be_false
end
end
@ -112,9 +110,6 @@ describe Photo do
it 'serializes the url' do
@xml.include?(@photo.image.url).should be true
end
it 'serializes the album_id' do
@xml.include?(@photo.album_id.to_s).should be true
end
it 'serializes the diaspora_handle' do
@xml.include?(@user.diaspora_handle).should be true
end

View file

@ -106,6 +106,21 @@ describe "attack vectors" do
user.reload.raw_visible_posts.count.should be 1
end
it 'should disregard retractions for a non-existant posts' do
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
id = original_message.reload.id
ret = Retraction.new
ret.post_id = original_message.id
ret.diaspora_handle = user3.person.diaspora_handle
ret.type = original_message.class.to_s
original_message.delete
StatusMessage.count.should be 0
proc{ user.receive_salmon(user3.salmon(ret).xml_for(user.person)) }.should_not raise_error
end
it 'should not receive retractions where the retractor and the salmon author do not match' do
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
user.receive_salmon(user2.salmon(original_message).xml_for(user.person))
@ -148,16 +163,16 @@ describe "attack vectors" do
end
it 'does not let me update other persons post' do
original_message = user2.post :album, :name => 'store this!', :to => aspect2.id
pending "this needs to be a photo"
original_message = user2.post(:photo, :user_file => uploaded_photo, :caption => "store this!", :to => aspect2.id)
user.receive_salmon(user2.salmon(original_message).xml_for(user.person))
original_message.diaspora_handle = user3.diaspora_handle
original_message.name = "bad bad bad"
original_message.caption = "bad bad bad"
xml = user3.salmon(original_message).xml_for(user.person)
user.receive_salmon(xml)
original_message.reload.name.should == "store this!"
original_message.reload.caption.should == "store this!"
end
end
end

View file

@ -42,10 +42,11 @@ describe User do
post.persisted?.should be_false
end
it 'does not save an album' do
post = user.build_post(:album, :name => "hey", :to => aspect.id)
it 'does not save a photo' do
post = user.build_post(:photo, :user_file => uploaded_photo, :to => aspect.id)
post.persisted?.should be_false
end
end
describe '#dispatch_post' do
@ -55,15 +56,6 @@ describe User do
aspect.posts.should include post
end
it 'should put an album in the aspect post array' do
album = user.post :album, :name => "Georges", :to => aspect.id
aspect.reload
aspect.posts.should include album
end
it "should add the post to that user's visible posts" do
status_message = user.post :status_message, :message => "hi", :to => aspect.id
user.reload
@ -95,10 +87,11 @@ describe User do
describe '#update_post' do
it 'should update fields' do
album = user.post(:album, :name => "Profile Photos", :to => aspect.id)
update_hash = {:name => "Other Photos"}
user.update_post(album, update_hash)
album.name.should == "Other Photos"
photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Old caption", :to => aspect.id)
update_hash = {:caption => "New caption"}
user.update_post(photo, update_hash)
photo.caption.should match(/New/)
end
end

View file

@ -14,7 +14,6 @@ describe User do
let(:person_three) { Factory.create :person }
context 'with two posts' do
let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id }
let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id }
@ -174,23 +173,4 @@ describe User do
end
end
describe '#albums_by_aspect' do
let!(:first_aspect) {user2.aspects.create(:name => 'bruisers')}
let!(:second_aspect) {user2.aspects.create(:name => 'losers')}
before do
user2.post :album, :name => "Georges", :to => first_aspect.id
user2.post :album, :name => "Borges", :to => first_aspect.id
user2.post :album, :name => "Luises", :to => second_aspect.id
user2.reload
end
it 'should find all albums if passed :all' do
user2.albums_by_aspect(:all).should have(3).albums
end
it 'should return the right number of albums' do
user2.albums_by_aspect(first_aspect.reload).should have(2).albums
user2.albums_by_aspect(second_aspect.reload).should have(1).album
end
end
end

View file

@ -15,7 +15,8 @@ describe User do
let(:user3) { make_user }
let(:aspect3) { user3.aspects.create(:name => 'heroes') }
let(:status) {user.post(:status_message, :message => "Original", :to => aspect.id)}
let(:album) {user.post(:album, :name => "Original", :to => aspect.id)}
let(:photo) {user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)}
before do
friend_users(user, aspect, user2, aspect2)
@ -74,15 +75,15 @@ describe User do
end
it 'updates posts marked as mutable' do
user2.receive_salmon(user.salmon(album).xml_for(user2.person))
album.name = 'foo'
xml = user.salmon(album).xml_for(user2.person)
user2.receive_salmon(user.salmon(photo).xml_for(user2.person))
photo.caption = 'foo'
xml = user.salmon(photo).xml_for(user2.person)
album.reload.name.should == 'Original'
photo.reload.caption.should match(/Original/)
user2.receive_salmon(xml)
album.reload.name.should == 'foo'
photo.reload.caption.should match(/foo/)
end
end

View file

@ -246,11 +246,11 @@ describe User do
end
describe '#update_post' do
it 'sends a notification to aspects' do
user.should_receive(:push_to_aspects).twice
album = user.post(:album, :name => "cat", :to => aspect.id)
user.update_post(album, :name => 'bat')
photo = user.post(:photo, :user_file => uploaded_photo, :caption => "hello", :to => aspect.id)
user.update_post(photo, :caption => 'hellp')
end
end