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

This commit is contained in:
ilya 2010-10-20 18:30:36 -07:00
commit 84e19f833a
18 changed files with 355 additions and 402 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

@ -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

@ -37,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

@ -54,33 +54,26 @@
});//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
-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
@ -91,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

@ -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,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

@ -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

@ -22,25 +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" ))
)
: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")))
: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,7 @@ 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"}}
)
:image_url => "http://tom.joindiaspora.com/images/user/tom.jpg"}})
user.save!
user.seed_aspects
user.person.save!
@ -39,7 +38,6 @@ user2 = User.build( :email => "korth@tom.joindiaspora.com",
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,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

@ -544,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
@ -995,7 +1000,7 @@ ul#settings_nav
:color transparent
#friend_pictures
.friend_pictures
:margin
:top 12px
:line-height 1em
@ -1004,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
@ -1105,7 +1120,9 @@ header
:color rgba(51,51,51,0.9)
:padding 10px
:position absolute
:right 0
:right 10px
:margin
:top 10px
a
:font
@ -1119,3 +1136,4 @@ header
&:hover
.controls
:display inline

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,7 +72,7 @@ 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
describe '#aspects_with_person' do
@ -85,10 +81,7 @@ describe Aspect do
user.reload
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
aspects.first.should == aspect
end
it 'returns multiple aspects if the person is there' do
@ -99,7 +92,6 @@ describe Aspect do
aspects.each{ |asp| asp.people.include?(friend) }
aspects.should_not include aspect_without_friend
end
end
end
@ -150,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

@ -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

@ -5,115 +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
describe '#friends_not_in_aspect' do
it 'finds the people who are not in the given aspect' do
friend_users(user, first_aspect, user4, user4.aspects.first)
people = user.friends_not_in_aspect(first_aspect)
people.should == [user3.person]
people2 = user.friends_not_in_aspect(second_aspect)
people2.count.should == 2
people2.include?(user2.person).should be true
people2.include?(user4.person).should be true
end
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