Merge remote branch 'upstream/master'

This commit is contained in:
Alec Leamas 2010-10-21 05:37:25 +02:00
commit a0fc7c9a54
33 changed files with 535 additions and 447 deletions

View file

@ -97,6 +97,7 @@ GEM
activesupport (= 3.0.1)
activesupport (3.0.1)
addressable (2.2.2)
archive-tar-minitar (0.5.2)
arel (1.0.1)
activesupport (~> 3.0.0)
aws (2.3.22)
@ -163,7 +164,8 @@ GEM
i18n (0.4.1)
json (1.4.6)
json_pure (1.4.6)
linecache (0.43)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
mail (2.2.7)
activesupport (>= 2.3.6)
mime-types
@ -225,11 +227,16 @@ GEM
rspec-expectations (~> 2.0.1)
rspec-rails (2.0.1)
rspec (~> 2.0.0)
ruby-debug (0.10.3)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
ruby-debug-base (0.10.3)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.4)
selenium-webdriver (0.0.29)
childprocess (>= 0.0.7)
@ -287,7 +294,7 @@ DEPENDENCIES
roxml!
rspec (>= 2.0.0)
rspec-rails (>= 2.0.0)
ruby-debug
ruby-debug19
sprinkle!
thin
webmock

View file

@ -46,6 +46,7 @@ class AspectsController < ApplicationController
def show
@aspect = current_user.aspect_by_id params[:id]
@friends_not_in_aspect = current_user.friends_not_in_aspect(@aspect)
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@ -78,20 +79,6 @@ class AspectsController < ApplicationController
respond_with @aspect
end
def move_friends
params[:moves].each{ |move|
move = move[1]
unless current_user.move_friend(move)
flash[:error] = I18n.t 'aspects.move_friends.failure', :real_name => Person.find_by_id( move[:friend_id] ).real_name
redirect_to aspects_manage_path
return
end
}
flash[:notice] = I18n.t 'aspects.move_friends.success'
redirect_to aspects_manage_path
end
def move_friend
unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to])
flash[:error] = I18n.t 'aspects.move_friend.error',:inspect => params.inspect
@ -105,11 +92,29 @@ class AspectsController < ApplicationController
end
end
def add_to_aspect
if current_user.add_person_to_aspect( params[:friend_id], params[:aspect_id])
flash[:notice] = I18n.t 'aspects.add_to_aspect.success'
else
flash[:error] = I18n.t 'aspects.add_to_aspect.failure'
end
redirect_to aspect_path(params[:aspect_id])
end
def remove_from_aspect
if current_user.delete_person_from_aspect( params[:friend_id], params[:aspect_id])
flash[:notice] = I18n.t 'aspects.remove_from_aspect.success'
else
flash[:error] = I18n.t 'aspects.remove_from_aspect.failure'
end
redirect_to aspects_manage_path
end
private
def clean_hash(params)
return {
:name => params[:name]
}
end
end

View file

@ -130,7 +130,7 @@ class User
def delete_person_from_aspect(person_id, aspect_id, opts = {})
raise "Can not delete a person from an aspect you do not own" unless aspect = self.aspects.find_by_id(aspect_id)
aspect.person_ids.delete(person_id)
aspect.person_ids.delete(person_id.to_id)
opts[:posts] ||= aspect.posts.all(:person_id => person_id)
aspect.posts -= opts[:posts]
aspect.save

View file

@ -9,27 +9,35 @@
});
});
.span-4.append-1.last
= render "shared/aspect_friends"
%h2
= @aspect
.friend_pictures.horizontal
= owner_image_link
- for friend in @friends
= person_image_link(friend)
.span-19.last
%h3
= link_to "#{@aspect} Albums", albums_path(:aspect => @aspect)
%h3
= link_to "#{@aspect} Albums", albums_path(:aspect => @aspect)
.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
="#{t('.updated')} #{how_long_ago(@album)}"
.right
-if current_user.owns? @album
=render 'photos/new_photo'
= link_to t('.edit_album'), edit_album_path(@album), :class => 'button'
-if current_user.owns? @album
=render 'photos/new_photo'
= link_to t('.edit_album'), edit_album_path(@album), :class => 'button'
.album_id{:id => @album.id, :style => "display:hidden;"}
-unless current_user.owns? @album
%h4= "#{t('.by')} #{@album.person.real_name}"
#thumbnails
- for photo in @album_photos
.image_thumb
= link_to (image_tag photo.url(:thumb_medium)), object_path(photo)

View file

@ -25,8 +25,13 @@
= person_image_tag(request.person)
.name
= request.person.real_name
%h3=t('.ignore_remove')
%h3 Remove from Aspect
.aspect_remove
%ul.dropzone
%li.grey Drag to remove person from aspect
%h3=t('.ignore_remove')
.remove
%ul.dropzone
%li.grey Drag to ignore/remove
@ -55,7 +60,7 @@
-else
-for person in aspect.people
%li.person{:id => person.id, :from_aspect_id => aspect.id}
%li.person{:id => person.id, :class => person.id, :from_aspect_id => aspect.id}
= person_image_tag(person)
.name
= link_to person.real_name, person

View file

@ -37,7 +37,7 @@
});
function processRetraction(post_id){
$('#' + post_id ).fadeOut(500).remove();
$("*[data-guid='"+post_id+"']").fadeOut(400, function(){$(this).remove()});
if($("#stream")[0].childElementCount == 0){
$("#no_posts").fadeIn(200);
}

View file

@ -16,15 +16,16 @@
%b.small= @person.diaspora_handle
%li
%i= t(".last_seen",:how_long_ago => how_long_ago(@posts.first))
- if @person != current_user.person && current_user.friends.include?(@person)
%li
%i= t(".friends_since",:how_long_ago => how_long_ago(@person))
%li
= form_tag move_friend_path
= select :to, :to, @aspects_dropdown_array, :selected => @aspects_with_person.first.id
= hidden_field_tag :from, :from, :value => @aspects_with_person.first.id
= hidden_field_tag :friend_id, :friend_id, :value => @person.id
= submit_tag t('.save')
.person_aspects
%ul
- for aspect in @aspects_with_person
%li= link_to aspect.name, aspect
- if @person != current_user.person && current_user.friends.include?(@person)
= link_to t('.remove_friend'), @person, :confirm => t('.are_you_sure'), :method => :delete, :class => "button"
@ -36,5 +37,5 @@
= render type_partial(post), :post => post unless post.class == Album
= will_paginate @posts
- else
%h3=t('no posts to display!')
%h3= t('.no_posts')

View file

@ -2,7 +2,7 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%li.message{:id => post.id}
%li.message{:data=>{:guid=>post.id}}
= person_image_tag(post.person)
@ -20,7 +20,7 @@
- if current_user.owns?(post)
.right
= link_to t('.delete'), status_message_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete"
= link_to t('.delete'), photo_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete"
=t('.posted_a_new_photo_to')
= link_to post.album.name, object_path(post.album)

View file

@ -54,31 +54,28 @@
});//end document ready
.span-4.append-1.last
= render "shared/aspect_friends"
%h2
= @aspect
.friend_pictures.horizontal
= owner_image_link
- for friend in @friends
= person_image_link(friend)
.span-19.last
%h3
= link_to @photo.album.name, @photo.album
= @photo.image
%h3
= link_to @photo.album.name, @photo.album
= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch'
|
= link_to "#{t('.full_size')}", @photo.url
|
= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch'
-if current_user.owns? @album
= link_to t('.edit_photo'), edit_photo_path(@photo), :class => "button"
%br
%br
%div{:id => @photo.id}
.span-14.append-1.last
%div{:data=>{:guid=>@photo.id}}
#show_photo
.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"
-if current_user.owns? @photo
.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"
|
= link_to 'edit', '#', :class => "make_profile_photo"
= linked_scaled_photo @photo, @album
-else
= linked_scaled_photo @photo, @album
.caption
-if current_user.owns? @photo
@ -87,26 +84,29 @@
.description
= @photo.caption
-if current_user.owns? @photo
%div{:class => 'clear'}
-if !@photo.caption or @photo.caption == ""
= link_to 'Add a description','javascript:void(0)', :id => "add-description", :class => "edit-desc"
-if current_user.owns? @photo
%div{:class => 'clear'}
-if !@photo.caption or @photo.caption == ""
= link_to 'Add a description','javascript:void(0)', :id => "add-description", :class => "edit-desc"
%br
%br
= form_for @photo do |p|
= p.text_field :caption, :value => @photo.caption
= p.submit
%div{:class => 'clear'}
%h4{:class => "show_post_comments"}
= "#{t('.comments')} (#{@photo.comments.count})"
= render "comments/comments", :post => @photo
#content_bottom
.back
= link_to "⇧ #{@album.name}", album_path(@album)
-if current_user.owns? @album
.right
= link_to t('.delete_photo'), @photo, :confirm => t('.are_you_sure'), :method => :delete, :class => 'button'
= form_for @photo do |p|
= p.text_field :caption, :value => @photo.caption
= p.submit
%div{:class => 'clear'}
-if current_user.owns? @album
= link_to t('.delete_photo'), @photo, :confirm => t('.are_you_sure'), :method => :delete, :class => 'button'
.span-9.last
= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch'
|
= link_to "#{t('.full_size')}", @photo.url
|
= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch'
%br
%br
#stream.show
%li.message{:id => @photo.id}
= render "comments/comments", :post => @photo

View file

@ -8,6 +8,13 @@
=t('.add_a_new_friend_to')
%i= aspect.name
- if @friends_not_in_aspect
= render('shared/add_friend_dropdown', :aspect => @aspect, :friends => @friends_not_in_aspect)
= form_for Request.new do |fr_request|
= fr_request.error_messages

View file

@ -0,0 +1,5 @@
= form_tag '/aspects/add_to_aspect', :id => 'add_to_aspect' do
= select_tag :friend_id, options_from_collection_for_select(friends, "id", "real_name"), :include_blank => true
= hidden_field_tag :aspect_id, aspect.id
= submit_tag "add to #{aspect.name}"

View file

@ -5,7 +5,7 @@
#left_pane
%h2= @aspect
#friend_pictures
.friend_pictures
= owner_image_link
- for friend in @friends
= person_image_link(friend)

View file

@ -2,7 +2,7 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%li.message{:id => post.id, :class => ("mine" if current_user.owns?(post))}
%li.message{ :data=>{:guid=>post.id}, :class => ("mine" if current_user.owns?(post))}
= person_image_link(post.person)

View file

@ -2,6 +2,13 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%h2
= @aspect
.friend_pictures.horizontal
- for friend in @friends
= person_image_link(friend)
.span-14.append-1.last
#stream
%h1.show_text

View file

@ -104,12 +104,12 @@ en:
success: "%{name} was successfully removed."
update:
success: "Your aspect, %{name}, has been successfully edited."
move_friends:
failure: "Aspect editing failed for friend %{real_name}."
success: "Aspects edited successfully."
move_friend:
failure: "didn't work %{inspect}"
success: "You are now showing your friend a different aspect of yourself."
success: "Person moved to new aspect"
add_to_aspect:
failure: "Failed to add friend to aspect."
success: "Successfully added friend to aspect."
helper:
remove: "remove"
aspect_not_empty: "Aspect not empty"
@ -217,6 +217,7 @@ en:
save: "save"
are_you_sure: "Are you sure?"
remove_friend: "remove friend"
no_posts: "no posts to display!"
requests:
new_request:
add_a_new_friend_to: "Add a new friend to"

View file

@ -20,8 +20,9 @@ Diaspora::Application.routes.draw do
match 'users/export_photos', :to => 'users#export_photos'
resources :users, :except => [:create, :new, :show]
match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends'
match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend'
match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect'
match 'aspects/remove_from_aspect',:to => 'aspects#remove_from_aspect', :as => 'remove_from_aspect'
match 'aspects/manage', :to => 'aspects#manage'
match 'aspects/public', :to => 'aspects#public'
resources :aspects, :except => [:edit]

View file

@ -2,14 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => citie
require File.join(File.dirname(__FILE__), "..", "..", "config", "environment")
def create
@ -32,7 +24,8 @@ def create
:person => Person.new(
:profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'],
:image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg")
)).save
))
user.save
user.person.save!
user.aspect(:name => "Presidents")

View file

@ -22,22 +22,25 @@ user = User.build( :email => "tom@tom.joindiaspora.com",
:username => "tom",
:password => "evankorth",
:password_confirmation => "evankorth",
:person => Person.new(
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
).save
:person => {
:profile => { :first_name => "Alexander", :last_name => "Hamiltom",
:image_url => "/images/user/tom.jpg"}})
user.save
user.person.save!
user.seed_aspects
user2 = User.build( :email => "korth@tom.joindiaspora.com",
:username => "korth",
:password => "evankorth",
:password_confirmation => "evankorth",
:person => Person.new(
:profile => Profile.new( :first_name => "Evan", :last_name => "Korth"))).save
:username => "korth",
:person => {:profile => { :first_name => "Evan", :last_name => "Korth",
:image_url => "/images/user/korth.jpg"}})
user2.save
user2.person.save!
user2.seed_aspects
# friending users
aspect = user.aspect(:name => "other dudes")
request = user.send_friend_request_to(user2, aspect)

View file

@ -24,8 +24,8 @@ user = User.build( :email => "tom@tom.joindiaspora.com",
:password_confirmation => "evankorth",
:person => {
:profile => { :first_name => "Alexander", :last_name => "Hamiltom",
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}}
).save!
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}})
user.save!
user.seed_aspects
user.person.save!
@ -35,9 +35,9 @@ user2 = User.build( :email => "korth@tom.joindiaspora.com",
:username => "korth",
:person => {:profile => { :first_name => "Evan", :last_name => "Korth",
:image_url => "http://tom.joindiaspora.com/images/user/korth.jpg"}})
user2.save!
user2.seed_aspects
user2.person.save!
# friending users
aspect = user.aspect(:name => "other dudes")
request = user.send_friend_request_to(user2, aspect)

View file

@ -29,6 +29,10 @@ module Diaspora
result
end
def friends_not_in_aspect( aspect )
Person.all(:id.in => self.friend_ids, :id.nin => aspect.person_ids)
end
def aspect_by_id( id )
id = id.to_id
aspects.detect{|x| x.id == id }
@ -44,8 +48,7 @@ module Diaspora
end
def aspects_with_person person
id = person.id.to_id
aspects.select { |g| g.person_ids.include? id}
aspects.all(:person_ids => person.id)
end
def people_in_aspects aspects

View file

@ -89,7 +89,36 @@ $(function() {
}
$(ui.draggable[0]).fadeOut('slow'); // ui.draggable.fadeOut('slow')
$(ui.draggable[0]).fadeOut('slow');
$(ui.draggable[0]).remove();
}
});
$(".aspect_remove ul").droppable({
hoverClass: 'active',
drop: function(event, ui) {
if ($( "." + ui.draggable[0].id).length == 1) {
alert("You can not remove the person from the last aspect");
} else {
if (!$(ui.draggable[0]).hasClass('requested_person')){
var aspect = ui.draggable[0].getAttribute('from_aspect_id')
var person_id = ui.draggable[0].id
$.ajax({
type: "POST",
url: "/aspects/remove_from_aspect",
data:{
'friend_id' : person_id,
'aspect_id' : aspect
}
});
}
$(ui.draggable[0]).fadeOut('slow');
$(ui.draggable[0]).remove();
}
}
});

View file

@ -29,19 +29,6 @@ $(".show_post_comments").live('click', function(event) {
$(this).toggleClass( "visible" );
});
$(".comment_box").toggle(function(evt){
var $this = $(this);
$this.attr("rows", 2);
$this.parents("p").parents("form").children("p").children(".comment_submit").fadeIn(200);
});
$(".comment_box").live('blur', function(evt){
var $this = $(this);
if( $this.val() == '' ) {
$this.parents("p").parents("form").children("p").children(".comment_submit").fadeOut(0);
$this.attr("rows", 1);
}
});
$(".comment_submit").live('click', function(evt){
$(this).closest("form").children("p .comment_box").attr("rows", 1);

View file

@ -121,3 +121,17 @@ $(".make_profile_photo").live("click", function(){
}
});
});
$(".comment_box").live("focus",function(evt){
var $this = $(this);
$this.attr("rows", 2);
$this.parents("p").parents("form").children("p").children(".comment_submit").fadeIn(200);
});
$(".comment_box").live('blur', function(evt){
var $this = $(this);
if( $this.val() == '' ) {
$this.parents("p").parents("form").children("p").children(".comment_submit").fadeOut(0);
$this.attr("rows", 1);
}
});

View file

@ -108,6 +108,7 @@ header
:color #333
:padding 0
:top 5px
:color #CCC
a
:color #CCC
@ -125,8 +126,10 @@ header
:color #fff
ul#user_menu
a
:text-shadow 0 1px 0 #000
:overflow hidden
:white-space nowrap
:text-overflow ellipsis
:text-shadow 0 1px 0 #000
:width 100px
@ -541,10 +544,15 @@ li.message .from .right
:margin-right 1em
#show_photo
:text-align center
:min-height 200px
img
:max-width 100%
:-webkit-box-shadow 0 2px 4px #333
:border 10px solid #fff
:bottom 80px solid #fff
:-webkit-border-radius 3px
:-moz-border-radius 3px
:border-radius 3px
.caption
:margin
@ -868,7 +876,8 @@ h1.big_text
.aspect,
.requests,
.remove
.remove,
.aspect_remove
:list
:style none
@ -991,7 +1000,7 @@ ul#settings_nav
:color transparent
#friend_pictures
.friend_pictures
:margin
:top 12px
:line-height 1em
@ -1000,6 +1009,16 @@ ul#settings_nav
:width 30px
:height 30px
.friend_pictures.horizontal
:display inline
:margin
:left 20px
img
:width 20px
:height 20px
:margin-right -4px
#thumbnails
:line-height 14px
@ -1101,7 +1120,9 @@ header
:color rgba(51,51,51,0.9)
:padding 10px
:position absolute
:right 0
:right 10px
:margin
:top 10px
a
:font
@ -1115,3 +1136,4 @@ header
&:hover
.controls
:display inline

View file

@ -8,9 +8,12 @@ describe AspectsController do
render_views
before do
@user = Factory.create(:user)
@user.aspect(:name => "lame-os")
@person = Factory.create(:person)
@user = Factory.create(:user)
@aspect = @user.aspect(:name => "lame-os")
@aspect1 = @user.aspect(:name => "another aspect")
@user2 = Factory.create(:user)
@aspect2 = @user2.aspect(:name => "party people")
friend_users(@user,@aspect, @user2, @aspect2)
sign_in :user, @user
end
@ -25,9 +28,9 @@ describe AspectsController do
describe "#create" do
describe "with valid params" do
it "creates an aspect" do
@user.aspects.count.should == 1
@user.aspects.count.should == 2
post :create, "aspect" => {"name" => "new aspect"}
@user.reload.aspects.count.should == 2
@user.reload.aspects.count.should == 3
end
it "redirects to the aspect page" do
post :create, "aspect" => {"name" => "new aspect"}
@ -36,9 +39,9 @@ describe AspectsController do
end
describe "with invalid params" do
it "does not create an aspect" do
@user.aspects.count.should == 1
@user.aspects.count.should == 2
post :create, "aspect" => {"name" => ""}
@user.reload.aspects.count.should == 1
@user.reload.aspects.count.should == 2
end
it "goes back to manage aspects" do
post :create, "aspect" => {"name" => ""}
@ -47,6 +50,15 @@ describe AspectsController do
end
end
describe "#move_friend" do
let(:opts) { {:friend_id => "person_id", :from => "from_aspect_id", :to => {:to => "to_aspect_id"}}}
it 'calls the move_friend_method' do
pending "need to figure out how to stub current_user to return our test @user"
@user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id")
post :move_friend, opts
end
end
describe "#update" do
before do
@aspect = @user.aspect(:name => "Bruisers")
@ -59,4 +71,24 @@ describe AspectsController do
Aspect.find(@aspect.id).user_id.should == @user.id
end
end
describe "#add_to_aspect" do
it 'adds the users to the aspect' do
@aspect1.reload
@aspect1.people.include?(@user2.person).should be false
post 'add_to_aspect', {:friend_id => @user2.person.id, :aspect_id => @aspect1.id }
@aspect1.reload
@aspect1.people.include?(@user2.person).should be true
end
end
describe "#remove_from_aspect" do
it 'adds the users to the aspect' do
@aspect.reload
@aspect.people.include?(@user2.person).should be true
post 'remove_from_aspect', {:friend_id => @user2.person.id, :aspect_id => @aspect1.id }
@aspect1.reload
@aspect1.people.include?(@user2.person).should be false
end
end
end

View file

@ -5,149 +5,108 @@
require 'spec_helper'
describe Diaspora::Parser do
before do
@user = Factory.create(:user)
@aspect = @user.aspect(:name => 'spies')
@user3 = Factory.create :user
@person = @user3.person
@user2 = Factory.create(:user)
@aspect2 = @user2.aspect(:name => "pandas")
friend_users(@user, @aspect, @user2, @aspect2)
end
let(:user) {Factory.create(:user)}
let(:aspect) {user.aspect(:name => 'spies')}
let(:user2) {Factory.create(:user)}
let(:aspect2){user2.aspect(:name => "pandas")}
let(:user3) {Factory.create :user}
let(:person) {user3.person}
describe "parsing compliant XML object" do
before do
@xml = Factory.build(:status_message).to_diaspora_xml
end
it 'should be able to correctly handle comments with person in db' do
person = Factory.create(:person)
post = Factory.create(:status_message, :person => @user.person)
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
post = user.post :status_message, :message => "hello", :to => aspect.id
comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!")
xml = comment.to_diaspora_xml
comment = Diaspora::Parser.from_xml(xml)
comment.text.should == "Freedom!"
comment.person.should == person
comment.person.should == @person
comment.post.should == post
end
it 'should be able to correctly handle person on a comment with person not in db' do
commenter = Factory.create(:user)
commenter_aspect = commenter.aspect :name => "bruisers"
friend_users(@user, @aspect, commenter, commenter_aspect)
post = @user.post :status_message, :message => "hello", :to => @aspect.id
comment = commenter.comment "Fool!", :on => post
friend_users(user, aspect, user2, aspect2)
post = user.post :status_message, :message => "hello", :to => aspect.id
comment = user2.comment "Fool!", :on => post
xml = comment.to_diaspora_xml
commenter.delete
commenter.person.delete
user2.delete
user2.person.delete
parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml)
parsed_person.save.should be true
parsed_person.diaspora_handle.should == commenter.person.diaspora_handle
parsed_person.diaspora_handle.should == user2.person.diaspora_handle
parsed_person.profile.should_not be_nil
end
it 'should marshal retractions' do
person = @user2.person
message = Factory.create(:status_message, :person => person)
it 'should accept retractions' do
friend_users(user, aspect, user2, aspect2)
message = Factory.create(:status_message, :person => user2.person)
retraction = Retraction.for(message)
xml = retraction.to_diaspora_xml
proc {@user.receive xml, person}.should change(StatusMessage, :count).by(-1)
proc {user.receive xml, user2.person}.should change(StatusMessage, :count).by(-1)
end
it "should create a new person upon getting a person request" do
person_count = Person.all.count
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
original_person_id = @person.id
xml = request.to_diaspora_xml
@user3.destroy
@person.destroy
Person.all.count.should == person_count -1
@user.receive xml, @person
Person.all.count.should == person_count
Person.first(:_id => original_person_id).serialized_public_key.include?("PUBLIC").should be true
url = "http://" + request.callback_url.split("/")[2] + "/"
Person.where(:url => url).first.id.should == original_person_id
user3.destroy
person.destroy
user
lambda {user.receive xml, person}.should change(Person, :count).by(1)
end
it "should not create a new person if the person is already here" do
person_count = Person.all.count
request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person)
original_person_id = @user2.person.id
request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person)
original_person_id = user2.person.id
xml = request.to_diaspora_xml
user
lambda {user.receive xml, user2.person}.should_not change(Person, :count)
Person.all.count.should be person_count
@user.receive xml, @user2.person
Person.all.count.should be person_count
@user2.reload
@user2.person.reload
@user2.serialized_private_key.include?("PRIVATE").should be true
user2.reload
user2.person.reload
user2.serialized_private_key.include?("PRIVATE").should be true
url = "http://" + request.callback_url.split("/")[2] + "/"
Person.where(:url => url).first.id.should == original_person_id
end
it "should activate the Person if I initiated a request to that url" do
request = @user.send_friend_request_to( @user3.person, @aspect)
@user.reload
request.reverse_for @user3
request = user.send_friend_request_to( user3.person, aspect)
user.reload
request.reverse_for user3
xml = request.to_diaspora_xml
@user3.person.destroy
@user3.destroy
user3.person.destroy
user3.destroy
@user.receive xml, @user3.person
new_person = Person.first(:url => @user3.person.url)
user.receive xml, user3.person
new_person = Person.first(:url => user3.person.url)
new_person.nil?.should be false
@user.reload
@aspect.reload
@aspect.people.include?(new_person).should be true
@user.friends.include?(new_person).should be true
user.reload
aspect.reload
aspect.people.include?(new_person).should be true
user.friends.include?(new_person).should be true
end
it 'should process retraction for a person' do
user4 = Factory(:user)
person_count = Person.all.count
request = @user.send_friend_request_to( user4.person, @aspect)
@user.reload
request.reverse_for user4
xml = request.to_diaspora_xml
retraction = Retraction.for(user4)
friend_users(user, aspect, user2, aspect2)
retraction = Retraction.for(user2)
retraction_xml = retraction.to_diaspora_xml
user4.person.destroy
user4.destroy
@user.receive xml, user4.person
@aspect.reload
aspect_people_count = @aspect.people.size
#They are now friends
Person.count.should == person_count
@user.receive retraction_xml, user4.person
@aspect.reload
@aspect.people.size.should == aspect_people_count -1
lambda {user.receive retraction_xml, user2.person}.should change{
aspect.reload.people.size}.by(-1)
end
it 'should marshal a profile for a person' do
friend_users(user, aspect, user2, aspect2)
#Create person
person = @user2.person
person = user2.person
id = person.id
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
person.save
@ -167,7 +126,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob'
#Marshal profile
@user.receive xml, person
user.receive xml, person
#Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id)

View file

@ -6,21 +6,11 @@ require 'spec_helper'
describe Diaspora::Webhooks do
before do
@user = Factory.create(:user)
@aspect = @user.aspect(:name => "losers")
@user2 = Factory.create(:user)
@aspect2 = @user2.aspect(:name => "losers")
friend_users(@user, @aspect, @user2, @aspect2)
@user = Factory.build(:user)
@post = Factory.build(:status_message, :person => @user.person)
end
describe "body" do
before do
@post = Factory.build(:status_message, :person => @user.person)
end
it "should add the following methods to Post on inclusion" do
@post.respond_to?(:to_diaspora_xml).should be true
end
it "should add the following methods to Post on inclusion" do
@post.respond_to?(:to_diaspora_xml).should be true
end
end

View file

@ -63,10 +63,6 @@ describe Aspect do
before do
aspect
user.activate_friend(friend, aspect)
aspect2
friend_users(user, aspect, user2, aspect2)
aspect.reload
user.reload
end
it 'belong to a user' do
@ -76,16 +72,26 @@ describe Aspect do
it 'should have people' do
aspect.people.all.include?(friend).should be true
aspect.people.size.should == 2
aspect.people.size.should == 1
end
it 'should be accessible through the user' do
aspects = user.aspects_with_person(friend)
aspects.size.should == 1
aspects.first.id.should == aspect.id
aspects.first.people.size.should == 2
aspects.first.people.include?(friend).should be true
aspects.first.people.include?(user2.person).should be true
describe '#aspects_with_person' do
let!(:aspect_without_friend) {user.aspect(:name => "Another aspect")}
it 'should return the aspects with given friend' do
user.reload
aspects = user.aspects_with_person(friend)
aspects.size.should == 1
aspects.first.should == aspect
end
it 'returns multiple aspects if the person is there' do
user.reload
user.add_person_to_aspect(friend.id, aspect1.id)
aspects = user.aspects_with_person(friend)
aspects.count.should == 2
aspects.each{ |asp| asp.people.include?(friend) }
aspects.should_not include aspect_without_friend
end
end
end
@ -136,8 +142,6 @@ describe Aspect do
end
context "aspect management" do
before do
friend_users(user, aspect, user2, aspect2)
aspect.reload

View file

@ -5,140 +5,127 @@
require 'spec_helper'
describe Comment do
describe "user" do
before do
@user = Factory.create :user
@aspect = @user.aspect(:name => "Doofuses")
let(:user) {Factory.create :user}
let(:aspect) {user.aspect(:name => "Doofuses")}
@user2 = Factory.create(:user)
@aspect2 = @user2.aspect(:name => "Lame-faces")
end
let(:user2) {Factory.create(:user)}
let(:aspect2) {user2.aspect(:name => "Lame-faces")}
describe 'User#comment' do
let(:status) {user.post(:status_message, :message => "hello", :to => aspect)}
it "should be able to comment on his own status" do
status = Factory.create(:status_message, :person => @user.person)
status.comments.should == []
@user.comment "Yeah, it was great", :on => status
user.comment "Yeah, it was great", :on => status
status.reload.comments.first.text.should == "Yeah, it was great"
end
it "should be able to comment on a person's status" do
person= Factory.create :person
status = Factory.create(:status_message, :person => person)
@user.comment "sup dog", :on => status
user2.comment "sup dog", :on => status
status.reload.comments.first.text.should == "sup dog"
status.reload.comments.first.person.should == @user.person
end
end
it 'should not send out comments when we have no people' do
status = Factory.create(:status_message, :person => user.person)
User::QUEUE.should_not_receive(:add_post_request)
user.comment "sup dog", :on => status
end
describe 'comment propagation' do
before do
friend_users(user, aspect, user2, aspect2)
@person = Factory.create(:person)
user.activate_friend(@person, Aspect.first(:id => aspect.id))
@person2 = Factory.create(:person)
@person_status = Factory.build(:status_message, :person => @person)
user.reload
user_status = user.post :status_message, :message => "hi", :to => aspect.id
aspect.reload
user.reload
end
it 'should not send out comments when we have no people' do
status = Factory.create(:status_message, :person => @user.person)
it 'should receive a comment from a person not on the pod' do
user3 = Factory.create :user
aspect3 = user3.aspect(:name => "blah")
friend_users(user, aspect, user3, aspect3)
comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => user_status)
comment.creator_signature = comment.sign_with_key(user3.encryption_key)
comment.post_creator_signature = comment.sign_with_key(user.encryption_key)
xml = user.salmon(comment).xml_for(user2)
user3.person.delete
user3.delete
user_status.reload
user_status.comments.should == []
user.receive_salmon(xml)
user_status.reload
user_status.comments.include?(comment).should be true
end
it "should send a user's comment on a person's post to that person" do
User::QUEUE.should_receive(:add_post_request)
user.comment "yo", :on => @person_status
end
it 'should send a user comment on his own post to lots of people' do
User::QUEUE.should_receive(:add_post_request).twice
user.comment "yo", :on => user_status
end
it 'should send a comment a person made on your post to all people' do
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => user_status)
User::QUEUE.should_receive(:add_post_request).twice
user.receive comment.to_diaspora_xml, @person
end
it 'should send a comment a user made on your post to all people' do
comment = user2.comment( "balls", :on => user_status)
User::QUEUE.should_receive(:add_post_request).twice
user.receive comment.to_diaspora_xml, user2.person
end
it 'should not send a comment a person made on his own post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
@user.comment "sup dog", :on => status
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
user.receive comment.to_diaspora_xml, @person
end
describe 'comment propagation' do
before do
friend_users(@user, Aspect.first(:id => @aspect.id), @user2, @aspect2)
@person = Factory.create(:person)
@user.activate_friend(@person, Aspect.first(:id => @aspect.id))
@person2 = Factory.create(:person)
@person_status = Factory.build(:status_message, :person => @person)
@user.reload
@user_status = @user.post :status_message, :message => "hi", :to => @aspect.id
@aspect.reload
@user.reload
end
it 'should receive a comment from a person not on the pod' do
user3 = Factory.create :user
aspect3 = user3.aspect(:name => "blah")
friend_users(@user, @aspect, user3, aspect3)
comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => @user_status)
comment.creator_signature = comment.sign_with_key(user3.encryption_key)
comment.post_creator_signature = comment.sign_with_key(@user.encryption_key)
xml = @user.salmon(comment).xml_for(@user2)
user3.person.delete
user3.delete
@user_status.reload
@user_status.comments.should == []
@user2.receive_salmon(xml)
@user_status.reload
@user_status.comments.include?(comment).should be true
end
it 'should have the post in the aspects post list' do
aspect = Aspect.first(:id => @aspect.id)
aspect.people.size.should == 2
aspect.post_ids.include?(@user_status.id).should be true
end
it "should send a user's comment on a person's post to that person" do
User::QUEUE.should_receive(:add_post_request)
@user.comment "yo", :on => @person_status
end
it 'should send a user comment on his own post to lots of people' do
User::QUEUE.should_receive(:add_post_request).twice
@user.comment "yo", :on => @user_status
end
it 'should send a comment a person made on your post to all people' do
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
User::QUEUE.should_receive(:add_post_request).twice
@user.receive comment.to_diaspora_xml, @person
end
it 'should send a comment a user made on your post to all people' do
comment = @user2.comment( "balls", :on => @user_status)
User::QUEUE.should_receive(:add_post_request).twice
@user.receive comment.to_diaspora_xml, @user2.person
end
it 'should not send a comment a person made on his own post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
@user.receive comment.to_diaspora_xml, @person
end
it 'should not send a comment a person made on a person post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
@user.receive comment.to_diaspora_xml, @person
end
it 'should not clear the aspect post array on receiving a comment' do
@aspect.post_ids.include?(@user_status.id).should be true
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
@user.receive comment.to_diaspora_xml, @person
@aspect.reload
@aspect.post_ids.include?(@user_status.id).should be true
end
it 'should not send a comment a person made on a person post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
user.receive comment.to_diaspora_xml, @person
end
describe 'serialization' do
it 'should serialize the commenter' do
commenter = Factory.create(:user)
commenter_aspect = commenter.aspect :name => "bruisers"
friend_users(@user, @aspect, commenter, commenter_aspect)
post = @user.post :status_message, :message => "hello", :to => @aspect.id
comment = commenter.comment "Fool!", :on => post
comment.person.should_not == @user.person
comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true
end
it 'should not clear the aspect post array on receiving a comment' do
aspect.post_ids.include?(user_status.id).should be true
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => user_status)
user.receive comment.to_diaspora_xml, @person
aspect.reload
aspect.post_ids.include?(user_status.id).should be true
end
end
describe 'serialization' do
it 'should serialize the commenter' do
commenter = Factory.create(:user)
commenter_aspect = commenter.aspect :name => "bruisers"
friend_users(user, aspect, commenter, commenter_aspect)
post = user.post :status_message, :message => "hello", :to => aspect.id
comment = commenter.comment "Fool!", :on => post
comment.person.should_not == user.person
comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true
end
end
end

View file

@ -72,6 +72,8 @@ describe User do
friend_users(user, aspect, user2, aspect2)
friend_users(user, aspect, user3, aspect3)
friend_users(user, aspect1, user4, aspect4)
user.add_person_to_aspect(user2.person.id, aspect1.id)
user.reload
end
describe '#push_to_aspects' do
@ -80,7 +82,7 @@ describe User do
user.push_to_aspects(post, aspect.id)
end
it 'should push a post to all aspects' do
it 'should push a post to friends in all aspects' do
user.should_receive(:push_to_person).exactly(3).times
user.push_to_aspects(post, :all)
end
@ -92,5 +94,6 @@ describe User do
user.push_to_people(post, [user2.person, user3.person])
end
end
end
end

View file

@ -17,7 +17,6 @@ describe User do
before do
friend_users(user, aspect, user2, aspect2)
friend_users(user, aspect, user3, aspect3)
end
it 'should be able to parse and store a status message from xml' do
@ -94,6 +93,10 @@ describe User do
end
describe 'comments' do
before do
friend_users(user, aspect, user3, aspect3)
end
it 'should correctly marshal a stranger for the downstream user' do
post = user.post :status_message, :message => "hello", :to => aspect.id

View file

@ -7,6 +7,7 @@ require 'spec_helper'
describe User do
let(:user) {Factory.create :user}
let(:aspect) {user.aspect(:name => 'heroes')}
let(:aspect1) {user.aspect(:name => 'other')}
let(:friend) { Factory.create(:person) }
let(:person_one) {Factory.create :person}
@ -174,6 +175,14 @@ describe User do
aspect.reload.people.count.should == 0
end
it 'should remove the friend from all aspects they are in' do
user.add_person_to_aspect(user2.person.id, aspect1.id)
lambda {user.unfriended_by user2.person}.should change{
user.friends.count}.by(-1)
aspect.reload.people.count.should == 0
aspect1.reload.people.count.should == 0
end
context 'with a post' do
before do
@message = user.post(:status_message, :message => "hi", :to => aspect.id)

View file

@ -5,100 +5,103 @@
require 'spec_helper'
describe User do
let!(:user) { Factory(:user_with_aspect) }
let!(:first_aspect) { user.aspects.first }
let!(:second_aspect) { user.aspect(:name => 'losers') }
let!(:user2) { Factory(:user_with_aspect) }
let!(:user3) { Factory(:user_with_aspect) }
let!(:user4) { Factory(:user_with_aspect) }
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 }
let!(:status_message3) { user2.post :status_message, :message => "va", :to => user2.aspects.first.id }
let!(:status_message4) { user2.post :status_message, :message => "da", :public => true , :to => user2.aspects.first.id }
let!(:status_message5) { user3.post :status_message, :message => "heyyyy", :to => user3.aspects.first.id}
let!(:status_message6) { user4.post :status_message, :message => "yooo", :to => user4.aspects.first.id}
before do
friend_users(user, first_aspect, user2, user2.aspects.first)
friend_users(user, second_aspect, user3, user3.aspects.first)
end
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 }
describe "#visible_posts" do
it "queries by person id" do
user2.visible_posts(:person_id => user2.person.id).include?(status_message1).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message2).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message3).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message4).should == true
end
it "queries by person id" do
query = user2.visible_posts(:person_id => user2.person.id)
query.include?(status_message1).should == true
query.include?(status_message2).should == true
end
it "selects public posts" do
user2.visible_posts(:public => true).include?(status_message2).should == true
user2.visible_posts(:public => true).include?(status_message4).should == true
end
it "selects public posts" do
query = user2.visible_posts(:public => true)
query.include?(status_message2).should == true
query.include?(status_message1).should == false
end
it "selects non public posts" do
user2.visible_posts(:public => false).include?(status_message1).should == true
user2.visible_posts(:public => false).include?(status_message3).should == true
end
it "selects non public posts" do
query = user2.visible_posts(:public => false)
query.include?(status_message1).should == true
query.include?(status_message2).should == false
end
it "selects by message contents" do
user2.visible_posts(:message => "hi").include?(status_message1).should == true
end
it "selects by message contents" do
user2.visible_posts(:message => "hi").include?(status_message1).should == true
end
it "queries by aspect" do
friend_users(user, second_aspect, user4, user4.aspects.first)
context 'with two users' do
let!(:user) {Factory :user}
let!(:first_aspect) {user.aspect(:name => 'bruisers')}
let!(:second_aspect) {user.aspect(:name => 'losers')}
user.receive status_message4.to_diaspora_xml, user2.person
user.receive status_message5.to_diaspora_xml, user3.person
user.receive status_message6.to_diaspora_xml, user4.person
it "queries by aspect" do
friend_users(user, first_aspect, user2, user2.aspects.first)
user.receive status_message1.to_diaspora_xml, user2.person
user.visible_posts(:by_members_of => first_aspect).should =~ [status_message4]
user.visible_posts(:by_members_of => second_aspect).should =~ [status_message5, status_message6]
user.visible_posts(:by_members_of => first_aspect).should =~ [status_message1]
user.visible_posts(:by_members_of => second_aspect).should =~ []
end
it '#find_visible_post_by_id' do
user2.find_visible_post_by_id(status_message1.id).should == status_message1
user.find_visible_post_by_id(status_message1.id).should == nil
end
end
end
end
context 'querying' do
describe '#find_visible_post_by_id' do
it 'should query' do
user2.find_visible_post_by_id(status_message1.id).should == status_message1
user.find_visible_post_by_id(status_message1.id).should == nil
context 'with two users' do
let!(:user) {Factory :user}
let!(:first_aspect) {user.aspect(:name => 'bruisers')}
let!(:second_aspect) {user.aspect(:name => 'losers')}
describe '#friends_not_in_aspect' do
it 'finds the people who are not in the given aspect' do
user4 = Factory.create(:user_with_aspect)
friend_users(user, first_aspect, user4, user4.aspects.first)
friend_users(user, second_aspect, user2, user2.aspects.first)
people = user.friends_not_in_aspect(first_aspect)
people.should == [user2.person]
end
end
describe '#find_friend_by_id' do
it 'should find both friends' do
user.reload
it 'should find a friend' do
friend_users(user, first_aspect, user2, user2.aspects.first)
user.find_friend_by_id(user2.person.id).should == user2.person
user.find_friend_by_id(user3.person.id).should == user3.person
end
it 'should not find a non-friend' do
user3.find_friend_by_id(user4.person.id).should be nil
user = Factory :user
user.find_friend_by_id(user2.person.id).should be nil
end
end
end
context 'albums' do
describe '#albums_by_aspect' do
let!(:first_aspect) {user2.aspect(:name => 'bruisers')}
let!(:second_aspect) {user2.aspect(:name => 'losers')}
before do
user.post :album, :name => "Georges", :to => first_aspect.id
user.post :album, :name => "Borges", :to => first_aspect.id
user.post :album, :name => "Luises", :to => second_aspect.id
user.reload
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
user.albums_by_aspect(:all).should have(3).albums
user2.albums_by_aspect(:all).should have(3).albums
end
it 'should return the right number of albums' do
user.albums_by_aspect(first_aspect.reload).should have(2).albums
user.albums_by_aspect(second_aspect.reload).should have(1).album
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