diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e5e2e263c..5d407e724 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,9 +1,6 @@ class UsersController < ApplicationController before_filter :authenticate_user!, :except => [:new, :create] - def index - @users = User.sort(:created_at.desc).all - end def show @user= User.first(:id => params[:id]) @user_profile = @user.person.profile diff --git a/app/models/user.rb b/app/models/user.rb index 8dbb35be3..58a33f828 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,13 +6,13 @@ class User key :friend_ids, Array key :pending_request_ids, Array - key :post_ids, Array + key :visible_post_ids, Array one :person, :class_name => 'Person', :foreign_key => :owner_id many :friends, :in => :friend_ids, :class_name => 'Person' many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' - many :posts, :in => :post_ids, :class_name => 'Post' + many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :groups, :class_name => 'Group' @@ -26,12 +26,12 @@ class User #validates_true_for :email, :logic => lambda {self.pivotal_email?} - def allowed_email? + def self.allowed_email?(email) email.include?('@pivotallabs.com') || email.include?("@joindiaspora.com") end def pivotal_or_diaspora_only - raise "pivotal only" unless allowed_email? + raise "pivotal only" unless User.allowed_email?(self.email) end ensure_index :email @@ -60,16 +60,16 @@ class User post.socket_to_uid(id) if post.respond_to?(:socket_to_uid) - self.posts << post + self.raw_visible_posts << post self.save post end - def posts_for( opts = {} ) - if opts[:group] - group = self.groups.find_by_id( opts[:group].id ) - self.posts.find_all_by_person_id( (group.person_ids + [self.person.id] ), :order => "created_at desc") + def visible_posts( opts = {} ) + if opts[:by_members_of] + group = self.groups.find_by_id( opts[:by_members_of].id ) + self.raw_visible_posts.find_all_by_person_id( (group.person_ids + [self.person.id] ), :order => "created_at desc") end end @@ -193,8 +193,8 @@ class User groups.each{|g| g.person_ids.delete( bad_friend.id )} self.save - self.posts.find_all_by_person_id( bad_friend.id ).each{|post| - self.post_ids.delete( post.id ) + self.raw_visible_posts.find_all_by_person_id( bad_friend.id ).each{|post| + self.visible_post_ids.delete( post.id ) post.user_refs -= 1 (post.user_refs > 0 || post.person.owner.nil? == false) ? post.save : post.destroy } @@ -257,21 +257,6 @@ class User person.profile = object person.save - elsif object.is_a?(Post) && object.verify_creator_signature == true - Rails.logger.debug("Saving post: #{object.inspect}") - - object.user_refs += 1 - object.save - - self.posts << object - self.save - - - group = groups.first - Rails.logger.info("pushing a message to group: #{group.name}") - object.socket_to_uid(id, :group_id => group.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) - dispatch_comment object if object.is_a?(Comment) && !owns?(object) - elsif object.is_a?(Comment) && object.verify_post_creator_signature if object.verify_creator_signature || object.person.nil? @@ -280,10 +265,14 @@ class User elsif object.verify_creator_signature == true Rails.logger.debug("Saving object: #{object}") + object.user_refs += 1 object.save + + self.raw_visible_posts << object + self.save - group = groups.find_by_person_id(object.person.id) - object.socket_to_uid(id, :group_id => group.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) + groups = groups_with_person(object.person) + object.socket_to_uid(id, :group_id => groups.first.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) end end @@ -322,6 +311,10 @@ class User def seed_groups group(:name => "Pivots") end + + def groups_with_person person + groups.select {|group| group.person_ids.include? person.id} + end protected def setup_person diff --git a/config/routes.rb b/config/routes.rb index a8602db07..237179d9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Diaspora::Application.routes.draw do |map| resources :people - resources :users, :only => [:edit, :show] + resources :users, :only => [:edit, :show, :update] resources :status_messages resources :comments resources :requests diff --git a/public/javascripts/group_nav.js b/public/javascripts/group_nav.js index f3d9600bb..5f5347c31 100644 --- a/public/javascripts/group_nav.js +++ b/public/javascripts/group_nav.js @@ -11,6 +11,4 @@ $(document).ready( function() { $("."+vars['g']).addClass('selected'); - $("#group img").load(function(){$(this).fadeIn("slow");}); - }); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 0d8edc7da..18289b738 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -67,10 +67,9 @@ header { position: relative; margin: -2em; margin-bottom: 20px; - color: #555555; - background-color: #2b2726; - background-color: black; - border-bottom: 3px solid #333333; + color: black; + background-color: #333333; + border-bottom: 3px solid black; padding: 6px 0; padding-top: 0; } header #diaspora_text { @@ -420,7 +419,7 @@ h1.big_text { display: none; } #group { - color: #333333; } + color: black; } #group ul { margin: 0; padding: 0; @@ -431,25 +430,25 @@ h1.big_text { #group ul > li.selected, #group ul > li.selected a { color: white; font-weight: bold; - font-size: 18px; } + font-size: 18px; + text-shadow: 0 2px 0px black; } #group a { - color: #333333; + color: #aaaaaa; font-weight: normal; } #group #friend_pictures .add_new { position: relative; display: inline-block; height: 40px; width: 40px; - background-color: #222222; + background-color: black; text-align: center; font-size: 40px; - line-height: 33px; - top: -9px; } + line-height: 40px; + top: -6px; } #group #friend_pictures .add_new:hover { background: #999999; color: black; } #group #friend_pictures img { - display: none; height: 40px; } #add_photo_loader { @@ -459,7 +458,7 @@ h1.big_text { top: 4px; } #user_menu { - background: #333333; + background: black; padding: 5px; margin: 0; list-style: none; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 9ef450368..0ac9dbfce 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -71,12 +71,11 @@ header :position relative :margin -2em :bottom 20px - :color #555 + :color #000 :background - :color #2B2726 - :color #000 + :color #333 :border - :bottom 3px solid #333 + :bottom 3px solid #000 :padding 6px 0 :top 0 @@ -524,7 +523,7 @@ h1.big_text :display none #group - :color #333 + :color #000 ul :margin 0 :padding 0 @@ -542,7 +541,7 @@ h1.big_text :size 18px a - :color #333 + :color #aaa :font :weight normal @@ -553,18 +552,17 @@ h1.big_text :height 40px :width 40px :background - :color #222 + :color #000 :text-align center :font-size 40px - :line-height 33px - :top -9px + :line-height 40px + :top -6px &:hover :background #999 :color #000 img - :display none :height 40px #add_photo_loader @@ -574,7 +572,7 @@ h1.big_text :top 4px #user_menu - :background #333 + :background #000 :padding 5px :margin 0 :list-style none diff --git a/spec/models/blogs_spec.rb b/spec/models/blogs_spec.rb deleted file mode 100644 index 9be9db74b..000000000 --- a/spec/models/blogs_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe Blog do - before do - @user = Factory.create(:user, :email => "bob@aol.com") - end - - it "should have a title and body" do - n = Blog.new - n.valid?.should be false - n.title = "jimmy" - n.valid?.should be false - n.body = "wales" - n.valid?.should be true - end - - - - describe "XML" do - it 'should serialize to XML' do - body = Factory.create(:blog, :title => "yessir", :body => "penguins", :person => @user.person) - body.to_xml.to_s.should include "yessir" - body.to_xml.to_s.should include "penguins" - end - - it 'should marshal serialized XML to object' do - xml = "\n yessir\n I hate WALRUSES!\n" - parsed = Blog.from_xml(xml) - parsed.body.should == "I hate WALRUSES!" - end - end -end diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb deleted file mode 100644 index ae4567bc1..000000000 --- a/spec/models/bookmark_spec.rb +++ /dev/null @@ -1,80 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe Bookmark do - it "should have a link" do - bookmark = Factory.build(:bookmark, :link => nil) - bookmark.valid?.should be false - bookmark.link = "http://angjoo.com/" - bookmark.valid?.should be true - end - - it 'should validate its link' do - bookmark = Factory.build(:bookmark) - #invalid links - bookmark.link = "zsdvzxdg" - bookmark.valid?.should == false - bookmark.link = "sdfasfa.c" - bookmark.valid?.should == false - bookmark.link = "http://.com/" - bookmark.valid?.should == false - bookmark.link = "http://www..com/" - bookmark.valid?.should == false - bookmark.link = "http:/www.asodij.com/" - bookmark.valid?.should == false - bookmark.link = "https:/www.asodij.com/" - bookmark.valid?.should == false - bookmark.link = "http:///www.asodij.com/" - bookmark.valid?.should == false - end - - it 'should clean links' do - bad_links = [ - "google.com", - "www.google.com", - "google.com/", - "www.google.com/", - "http://google.com", - "http://www.google.com" - ] - - bad_links.each{ |link| - Bookmark.clean_link(link).should satisfy{ |link| - /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix.match(link) - } - } - - end - - describe "XML" do - it 'should serialize to XML' do - u = Factory.create(:user) - message = Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com/", :person => u.person) - message.to_xml.to_s.should include "Reddit" - message.to_xml.to_s.should include "http://reddit.com/" - end - - it 'should marshal serialized XML to object' do - xml = "Reddit</message><link>http://reddit.com/</link></bookmark>" - parsed = Bookmark.from_xml(xml) - parsed.title.should == "Reddit" - parsed.link.should == "http://reddit.com/" - parsed.valid?.should be_true - end - end - - describe 'with encryption' do - before do - unstub_mocha_stubs - @user = Factory.create(:user) - end - - after do - stub_signature_verification - end - - it 'should save a signed bookmark' do - bookmark = @user.post(:bookmark, :title => "I love cryptography", :link => "http://pgp.mit.edu/") - bookmark.created_at.should_not be nil - end - end -end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 70f439e25..a571e0582 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -9,7 +9,6 @@ describe Person do @group2 = @user2.group(:name => "Abscence of Babes") end - it 'should not allow two people with the same email' do person_two = Factory.build(:person, :url => @person.email) person_two.valid?.should == false @@ -19,125 +18,129 @@ describe Person do before do @xml = @person.to_xml.to_s end + it 'should serialize to xml' do - (@xml.include? "person").should == true + @xml.include?("person").should == true end it 'should have a profile in its xml' do - (@xml.include? "first_name").should == true + @xml.include?("first_name").should == true end end it 'should know when a post belongs to it' do person_message = Factory.create(:status_message, :person => @person) - person_two = Factory.create(:person) + person_two = Factory.create(:person) - @person.owns?(person_message).should be true + @person.owns? (person_message).should be true person_two.owns?(person_message).should be false end it 'should delete all of user except comments upon user deletion' do - f = Factory.create(:person) + person = Factory.create(:person) - Factory.create(:status_message, :person => f) - Factory.create(:blog, :person => f) - Factory.create(:bookmark, :person => f) - Factory.create(:status_message, :person => f) - s = Factory.create(:status_message, :person => @person) + Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => person) + + status_message = Factory.create(:status_message, :person => @person) - Factory.create(:comment, :person_id => f.id, :text => "yes i do", :post => s) - Factory.create(:comment, :person_id => f.id, :text => "i love you", :post => s) - Factory.create(:comment, :person_id => f.id, :text => "hello", :post => s) - Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => s) + Factory.create(:comment, :person_id => person.id, :text => "yes i do", :post => status_message) + Factory.create(:comment, :person_id => person.id, :text => "i love you", :post => status_message) + Factory.create(:comment, :person_id => person.id, :text => "hello", :post => status_message) + Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => status_message) - f.destroy + person.destroy - Post.count.should == 1 + Post.count.should == 1 Comment.all.count.should == 4 - s.comments.count.should == 4 + status_message.comments.count.should == 4 end describe "unfriending" do it 'should delete an orphaned friend' do - request = @user.send_friend_request_to @person.receive_url, @group.id @user.activate_friend(@person, @group) @user.reload - Person.all.count.should == 3 + Person.all.count.should == 3 @user.friends.count.should == 1 @user.unfriend(@person) @user.reload @user.friends.count.should == 0 - Person.all.count.should == 2 + Person.all.count.should == 2 end it 'should not delete an un-orphaned friend' do request = @user.send_friend_request_to @person.receive_url, @group.id request2 = @user2.send_friend_request_to @person.receive_url, @group2.id - @user.activate_friend(@person, @group) + @user.activate_friend (@person, @group) @user2.activate_friend(@person, @group2) @user.reload @user2.reload - Person.all.count.should == 3 - @user.friends.count.should == 1 + Person.all.count.should == 3 + @user.friends.count.should == 1 @user2.friends.count.should == 1 @user.unfriend(@person) @user.reload @user2.reload - @user.friends.count.should == 0 + @user.friends.count.should == 0 @user2.friends.count.should == 1 - Person.all.count.should == 3 + Person.all.count.should == 3 end end + describe 'searching' do before do - @friend_one = Factory.create(:person) - @friend_two = Factory.create(:person) + @friend_one = Factory.create(:person) + @friend_two = Factory.create(:person) @friend_three = Factory.create(:person) - @friend_four = Factory.create(:person) + @friend_four = Factory.create(:person) @friend_one.profile.first_name = "Robert" - @friend_one.profile.last_name = "Grimm" + @friend_one.profile.last_name = "Grimm" @friend_one.profile.save @friend_two.profile.first_name = "Eugene" - @friend_two.profile.last_name = "Weinstein" + @friend_two.profile.last_name = "Weinstein" @friend_two.save @friend_three.profile.first_name = "Yevgeniy" - @friend_three.profile.last_name = "Dodis" + @friend_three.profile.last_name = "Dodis" @friend_three.save @friend_four.profile.first_name = "Casey" - @friend_four.profile.last_name = "Grippi" + @friend_four.profile.last_name = "Grippi" @friend_four.save end + it 'should yield search results on partial names' do people = Person.search("Eu") - people.include?(@friend_two).should == true - people.include?(@friend_one).should == false + people.include?(@friend_two).should == true + people.include?(@friend_one).should == false people.include?(@friend_three).should == false - people.include?(@friend_four).should == false + people.include?(@friend_four).should == false people = Person.search("Wei") - people.include?(@friend_two).should == true - people.include?(@friend_one).should == false + people.include?(@friend_two).should == true + people.include?(@friend_one).should == false people.include?(@friend_three).should == false - people.include?(@friend_four).should == false + people.include?(@friend_four).should == false people = Person.search("Gri") - people.include?(@friend_one).should == true - people.include?(@friend_four).should == true - people.include?(@friend_two).should == false + people.include?(@friend_one).should == true + people.include?(@friend_four).should == true + people.include?(@friend_two).should == false people.include?(@friend_three).should == false end + it 'should search by email exactly' do Person.by_webfinger(@friend_one.email).should == @friend_one end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 12c84ccfe..9ec8ccb19 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -10,35 +10,34 @@ describe Post do before do @person_one = Factory.create(:person, :email => "some@dudes.com") @person_two = Factory.create(:person, :email => "other@dudes.com") - (2..4).each {|n| Blog.create(:title => "title #{n}", :body => "test #{n}", :person => @person_one)} - (5..8).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @user.person)} - (9..11).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @person_two)} + (2..4).each { |n| Factory.create(:status_message, :message => "test #{n}", :person => @person_one) } + (5..8).each { |n| Factory.create(:status_message, :message => "test #{n}", :person => @user.person)} + (9..11).each { |n| Factory.create(:status_message, :message => "test #{n}", :person => @person_two) } Factory.create(:status_message, :person => @user) - Factory.create(:bookmark, :person => @user) + Factory.create(:status_message, :person => @user) end - it "should give the most recent blog title and body from owner" do - blog = Blog.newest_for(@user.person) - blog.person.email.should == @user.person.email - blog.class.should == Blog - blog.title.should == "title 8" - blog.body.should == "test 8" + it "should give the most recent status_message title and body from owner" do + status_message = StatusMessage.newest_for(@user.person) + status_message.person.email.should == @user.person.email + status_message.class.should == StatusMessage + status_message.message.should == "test 8" end end describe "stream" do before do - @owner = Factory.build(:user) + @owner = Factory.build(:user) @person_one = Factory.create(:person, :email => "some@dudes.com") @person_two = Factory.create(:person, :email => "other@dudes.com") Factory.create(:status_message, :message => "puppies", :created_at => Time.now+1, :person => @owner.person) - Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com", :created_at => Time.now+2, :person => @person_one) + Factory.create(:status_message, :message => "http://reddit.com", :created_at => Time.now+2, :person => @person_one) Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3, :person => @person_two) - Factory.create(:blog, :title => "Bears", :body => "Bear's body", :created_at => Time.now+4, :person => @owner.person) - Factory.create(:bookmark, :title => "Google", :link => "http://google.com", :created_at => Time.now+5, :person => @person_two) + Factory.create(:status_message, :message => "Bear's body", :created_at => Time.now+4, :person => @owner.person) + Factory.create(:status_message, :message => "Google", :created_at => Time.now+5, :person => @person_two) end it "should get all posts for a specified user" do @@ -52,7 +51,7 @@ describe Post do describe 'xml' do it 'should serialize to xml with its person' do message = Factory.create(:status_message, :person => @user.person) - (message.to_xml.to_s.include? @user.person.email).should == true + message.to_xml.to_s.include?(@user.person.email).should == true end end diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index c5b49cc64..66686269a 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -14,12 +14,11 @@ describe Request do end it 'should generate xml for the User as a Person' do - request = @user.send_friend_request_to "http://www.google.com/", @group.id xml = request.to_xml.to_s - xml.include?(@user.person.email).should be true + xml.include?(@user.email).should be true xml.include?(@user.url).should be true xml.include?(@user.profile.first_name).should be true xml.include?(@user.profile.last_name).should be true diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb new file mode 100644 index 000000000..7e850c490 --- /dev/null +++ b/spec/models/user/receive_spec.rb @@ -0,0 +1,122 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe User do + + before do + @user = Factory.create :user + @group = @user.group(:name => 'heroes') + + @user2 = Factory.create(:user) + @group2 = @user2.group(:name => 'losers') + #Factory.create :friend, @user + friend_users(@user, @group, @user2, @group2) + end + + it 'should be able to parse and store a status message from xml' do + status_message = @user2.post :status_message, :message => 'store this!' + person = @user2.person + + xml = status_message.to_diaspora_xml + @user2.destroy + status_message.destroy + StatusMessage.all.size.should == 0 + @user.receive( xml ) + + person.posts.first.message.should == 'store this!' + StatusMessage.all.size.should == 1 + end + + describe 'post refs' do + before do + @user3 = Factory.create(:user) + @group3 = @user3.group(:name => 'heroes') + end + + it "should add the post to that user's posts when a user posts it" do + status_message = @user.post :status_message, :message => "hi" + @user.reload + @user.raw_visible_posts.include?(status_message).should be true + end + + it 'should be removed on unfriending' do + status_message = @user2.post :status_message, :message => "hi" + @user.receive status_message.to_diaspora_xml + @user.reload + + @user.raw_visible_posts.count.should == 1 + + @user.unfriend(@user2.person) + + @user.reload + @user.raw_visible_posts.count.should == 0 + + Post.count.should be 1 + end + + it 'should be remove a post if the noone links to it' do + status_message = @user2.post :status_message, :message => "hi" + @user.receive status_message.to_diaspora_xml + @user.reload + + @user.raw_visible_posts.count.should == 1 + + person = @user2.person + @user2.destroy + @user.unfriend(person) + + @user.reload + @user.raw_visible_posts.count.should == 0 + + Post.count.should be 0 + end + + it 'should keep track of user references for one person ' do + status_message = @user2.post :status_message, :message => "hi" + @user.receive status_message.to_diaspora_xml + @user.reload + + @user.raw_visible_posts.count.should == 1 + + status_message.reload + status_message.user_refs.should == 1 + + @user.unfriend(@user2.person) + status_message.reload + + @user.reload + @user.raw_visible_posts.count.should == 0 + + status_message.reload + status_message.user_refs.should == 0 + + Post.count.should be 1 + end + + it 'should not override userrefs on receive by another person' do + @user3.activate_friend(@user2.person, @group3) + + status_message = @user2.post :status_message, :message => "hi" + @user.receive status_message.to_diaspora_xml + + @user3.receive status_message.to_diaspora_xml + @user.reload + @user3.reload + + @user.raw_visible_posts.count.should == 1 + + status_message.reload + status_message.user_refs.should == 2 + + @user.unfriend(@user2.person) + status_message.reload + + @user.reload + @user.raw_visible_posts.count.should == 0 + + status_message.reload + status_message.user_refs.should == 1 + + Post.count.should be 1 + end + end +end diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb new file mode 100644 index 000000000..2eff093bf --- /dev/null +++ b/spec/models/user/user_friending_spec.rb @@ -0,0 +1,223 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe User do + before do + @user = Factory.create(:user) + @group = @user.group(:name => 'heroes') + end + + describe 'friend requesting' do + it "should assign a request to a group" do + friend = Factory.create(:person) + group = @user.group(:name => "Dudes") + group.requests.size.should == 0 + + @user.send_friend_request_to(friend.receive_url, group.id) + + group.reload + group.requests.size.should == 1 + end + + + it "should be able to accept a pending friend request" do + friend = Factory.create(:person) + r = Request.instantiate(:to => @user.receive_url, :from => friend) + r.save + Person.all.count.should == 2 + Request.for_user(@user).all.count.should == 1 + @user.accept_friend_request(r.id, @group.id) + Request.for_user(@user).all.count.should == 0 + end + + it 'should be able to ignore a pending friend request' do + friend = Factory.create(:person) + r = Request.instantiate(:to => @user.receive_url, :from => friend) + r.save + + Person.count.should == 2 + + @user.ignore_friend_request(r.id) + + Person.count.should == 1 + Request.count.should == 0 + end + + it 'should not be able to friend request an existing friend' do friend = Factory.create(:person) + + @user.friends << friend + @user.save + + + @user.send_friend_request_to( friend.receive_url, @group.id ).should be nil + end + + + + describe 'multiple users accepting/rejecting the same person' do + before do + @person_one = Factory.create :person + @person_one.save + + @user2 = Factory.create :user + @group2 = @user2.group(:name => "group two") + + @user.pending_requests.empty?.should be true + @user.friends.empty?.should be true + @user2.pending_requests.empty?.should be true + @user2.friends.empty?.should be true + + @request = Request.instantiate(:to => @user.receive_url, :from => @person_one) + @request_two = Request.instantiate(:to => @user2.receive_url, :from => @person_one) + @request_three = Request.instantiate(:to => @user2.receive_url, :from => @user.person) + + @req_xml = @request.to_diaspora_xml + @req_two_xml = @request_two.to_diaspora_xml + @req_three_xml = @request_three.to_diaspora_xml + + @request.destroy + @request_two.destroy + @request_three.destroy + end + + it 'should befriend the user other user on the same pod' do + + @user2.receive @req_three_xml + @user2.pending_requests.size.should be 1 + @user2.accept_friend_request @request_three.id, @group2.id + @user2.friends.include?(@user.person).should be true + Person.all.count.should be 3 + end + + it 'should not delete the ignored user on the same pod' do + + @user2.receive @req_three_xml + @user2.pending_requests.size.should be 1 + @user2.ignore_friend_request @request_three.id + @user2.friends.include?(@user.person).should be false + Person.all.count.should be 3 + end + + it 'should both users should befriend the same person' do + + @user.receive @req_xml + @user.pending_requests.size.should be 1 + @user.accept_friend_request @request.id, @group.id + @user.friends.include?(@person_one).should be true + + @user2.receive @req_two_xml + @user2.pending_requests.size.should be 1 + @user2.accept_friend_request @request_two.id, @group2.id + @user2.friends.include?(@person_one).should be true + Person.all.count.should be 3 + end + + it 'should keep the person around if one of the users rejects him' do + + @user.receive @req_xml + @user.pending_requests.size.should be 1 + @user.accept_friend_request @request.id, @group.id + @user.friends.include?(@person_one).should be true + + @user2.receive @req_two_xml + @user2.pending_requests.size.should be 1 + @user2.ignore_friend_request @request_two.id + @user2.friends.include?(@person_one).should be false + Person.all.count.should be 3 + end + + it 'should not keep the person around if the users ignores them' do + @user.receive @req_xml + @user.pending_requests.size.should be 1 + @user.ignore_friend_request @user.pending_requests.first.id + @user.friends.include?(@person_one).should be false + + @user2.receive @req_two_xml + @user2.pending_requests.size.should be 1 + @user2.ignore_friend_request @user2.pending_requests.first.id#@request_two.id + @user2.friends.include?(@person_one).should be false + Person.all.count.should be 2 + end + + + end + + describe 'a user accepting rejecting multiple people' do + before do + @person_one = Factory.create :person + @person_two = Factory.create :person + + @user.pending_requests.empty?.should be true + @user.friends.empty?.should be true + + @request = Request.instantiate(:to => @user.receive_url, :from => @person_one) + @request_two = Request.instantiate(:to => @user.receive_url, :from => @person_two) + end + + after do + @user.receive_friend_request @request + + @person_two.destroy + @user.pending_requests.size.should be 1 + @user.friends.size.should be 0 + + @user.receive_friend_request @request_two + @user.pending_requests.size.should be 2 + @user.friends.size.should be 0 + + @user.accept_friend_request @request.id, @group.id + @user.pending_requests.size.should be 1 + @user.friends.size.should be 1 + @user.friends.include?(@person_one).should be true + + @user.ignore_friend_request @request_two.id + @user.pending_requests.size.should be 0 + @user.friends.size.should be 1 + @user.friends.include?(@person_two).should be false + + end + + end + + describe 'unfriending' do + before do + @user2 = Factory.create :user + @group2 = @user2.group(:name => "Gross people") + + request = @user.send_friend_request_to( @user2.receive_url, @group.id) + request.reverse_for @user2 + @user2.activate_friend(@user.person, @group2) + @user.receive request.to_diaspora_xml + end + + it 'should unfriend the other user on the same seed' do + @user.reload + @user2.reload + + @user.friends.count.should == 1 + @user2.friends.count.should == 1 + + @user.person.user_refs.should == 1 + + @user2.person.user_refs.should == 1 + + @user2.unfriend @user.person + @user2.friends.count.should be 0 + + @user.person.reload + @user.person.user_refs.should == 0 + + @user.unfriended_by @user2.person + + @user2.person.reload + @user2.person.user_refs.should == 0 + + @group.reload + @group2.reload + @group.people.count.should == 0 + @group2.people.count.should == 0 + end + end + + + end +end diff --git a/spec/models/user/visible_posts_spec.rb b/spec/models/user/visible_posts_spec.rb new file mode 100644 index 000000000..92e8c6403 --- /dev/null +++ b/spec/models/user/visible_posts_spec.rb @@ -0,0 +1,42 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe User do + before do + @user = Factory.create(:user) + @group = @user.group(:name => 'heroes') + @group2 = @user.group(:name => 'losers') + + @user2 = Factory.create :user + @user2_group = @user2.group(:name => 'dudes') + + friend_users(@user, @group, @user2, @user2_group) + + @user3 = Factory.create :user + @user3_group = @user3.group(:name => 'dudes') + friend_users(@user, @group2, @user3, @user3_group) + + @user4 = Factory.create :user + @user4_group = @user4.group(:name => 'dudes') + friend_users(@user, @group2, @user4, @user4_group) + end + + it 'should generate a valid stream for a group of people' do + status_message1 = @user2.post :status_message, :message => "hi" + status_message2 = @user3.post :status_message, :message => "heyyyy" + status_message3 = @user4.post :status_message, :message => "yooo" + + @user.receive status_message1.to_diaspora_xml + @user.receive status_message2.to_diaspora_xml + @user.receive status_message3.to_diaspora_xml + @user.reload + + @user.visible_posts(:by_members_of => @group).include?(status_message1).should be true + @user.visible_posts(:by_members_of => @group).include?(status_message2).should be false + @user.visible_posts(:by_members_of => @group).include?(status_message3).should be false + + @user.visible_posts(:by_members_of => @group2).include?(status_message1).should be false + @user.visible_posts(:by_members_of => @group2).include?(status_message2).should be true + @user.visible_posts(:by_members_of => @group2).include?(status_message3).should be true + end +end + diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 26381c311..8c3bf95b5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -6,179 +6,6 @@ describe User do @group = @user.group(:name => 'heroes') end - describe 'friend requesting' do - it "should assign a request to a group" do - friend = Factory.create(:person) - group = @user.group(:name => "Dudes") - group.requests.size.should == 0 - - @user.send_friend_request_to(friend.receive_url, group.id) - - group.reload - group.requests.size.should == 1 - end - - - it "should be able to accept a pending friend request" do - friend = Factory.create(:person) - r = Request.instantiate(:to => @user.receive_url, :from => friend) - r.save - Person.all.count.should == 2 - Request.for_user(@user).all.count.should == 1 - @user.accept_friend_request(r.id, @group.id) - Request.for_user(@user).all.count.should == 0 - end - - it 'should be able to ignore a pending friend request' do - friend = Factory.create(:person) - r = Request.instantiate(:to => @user.receive_url, :from => friend) - r.save - - Person.count.should == 2 - - @user.ignore_friend_request(r.id) - - Person.count.should == 1 - Request.count.should == 0 - end - - it 'should not be able to friend request an existing friend' do friend = Factory.create(:person) - - @user.friends << friend - @user.save - - - @user.send_friend_request_to( friend.receive_url, @group.id ).should be nil - end - - - - describe 'multiple users accepting/rejecting the same person' do - before do - @person_one = Factory.create :person - @person_one.save - - @user2 = Factory.create :user - @group2 = @user2.group(:name => "group two") - - @user.pending_requests.empty?.should be true - @user.friends.empty?.should be true - @user2.pending_requests.empty?.should be true - @user2.friends.empty?.should be true - - @request = Request.instantiate(:to => @user.receive_url, :from => @person_one) - @request_two = Request.instantiate(:to => @user2.receive_url, :from => @person_one) - @request_three = Request.instantiate(:to => @user2.receive_url, :from => @user.person) - - @req_xml = @request.to_diaspora_xml - @req_two_xml = @request_two.to_diaspora_xml - @req_three_xml = @request_three.to_diaspora_xml - - @request.destroy - @request_two.destroy - @request_three.destroy - end - - it 'should befriend the user other user on the same pod' do - - @user2.receive @req_three_xml - @user2.pending_requests.size.should be 1 - @user2.accept_friend_request @request_three.id, @group2.id - @user2.friends.include?(@user.person).should be true - Person.all.count.should be 3 - end - - it 'should not delete the ignored user on the same pod' do - - @user2.receive @req_three_xml - @user2.pending_requests.size.should be 1 - @user2.ignore_friend_request @request_three.id - @user2.friends.include?(@user.person).should be false - Person.all.count.should be 3 - end - - it 'should both users should befriend the same person' do - - @user.receive @req_xml - @user.pending_requests.size.should be 1 - @user.accept_friend_request @request.id, @group.id - @user.friends.include?(@person_one).should be true - - @user2.receive @req_two_xml - @user2.pending_requests.size.should be 1 - @user2.accept_friend_request @request_two.id, @group2.id - @user2.friends.include?(@person_one).should be true - Person.all.count.should be 3 - end - - it 'should keep the person around if one of the users rejects him' do - - @user.receive @req_xml - @user.pending_requests.size.should be 1 - @user.accept_friend_request @request.id, @group.id - @user.friends.include?(@person_one).should be true - - @user2.receive @req_two_xml - @user2.pending_requests.size.should be 1 - @user2.ignore_friend_request @request_two.id - @user2.friends.include?(@person_one).should be false - Person.all.count.should be 3 - end - - it 'should not keep the person around if the users ignores them' do - @user.receive @req_xml - @user.pending_requests.size.should be 1 - @user.ignore_friend_request @user.pending_requests.first.id - @user.friends.include?(@person_one).should be false - - @user2.receive @req_two_xml - @user2.pending_requests.size.should be 1 - @user2.ignore_friend_request @user2.pending_requests.first.id#@request_two.id - @user2.friends.include?(@person_one).should be false - Person.all.count.should be 2 - end - - - end - - describe 'a user accepting rejecting multiple people' do - before do - @person_one = Factory.create :person - @person_two = Factory.create :person - - @user.pending_requests.empty?.should be true - @user.friends.empty?.should be true - - @request = Request.instantiate(:to => @user.receive_url, :from => @person_one) - @request_two = Request.instantiate(:to => @user.receive_url, :from => @person_two) - end - - after do - @user.receive_friend_request @request - - @person_two.destroy - @user.pending_requests.size.should be 1 - @user.friends.size.should be 0 - - @user.receive_friend_request @request_two - @user.pending_requests.size.should be 2 - @user.friends.size.should be 0 - - @user.accept_friend_request @request.id, @group.id - @user.pending_requests.size.should be 1 - @user.friends.size.should be 1 - @user.friends.include?(@person_one).should be true - - @user.ignore_friend_request @request_two.id - @user.pending_requests.size.should be 0 - @user.friends.size.should be 1 - @user.friends.include?(@person_two).should be false - - end - - end - end - describe 'profiles' do it 'should be able to update their profile and send it to their friends' do Factory.create(:person) @@ -191,205 +18,4 @@ describe User do @user.profile.image_url.should == "http://clown.com" end end - - describe 'receiving' do - before do - @user2 = Factory.create(:user) - @user.friends << @user2.person - @user2.friends << @user.person - @user.person.user_refs += 1 - @user2.person.user_refs += 1 - @user.save - @user2.save - end - - it 'should be able to parse and store a status message from xml' do - status_message = @user2.post :status_message, :message => 'store this!' - person = @user2.person - - xml = status_message.to_diaspora_xml - @user2.destroy - status_message.destroy - StatusMessage.all.size.should == 0 - @user.receive( xml ) - - person.posts.first.message.should == 'store this!' - StatusMessage.all.size.should == 1 - end - end - - describe 'unfriending' do - before do - @user2 = Factory.create :user - @group2 = @user2.group(:name => "Gross people") - - request = @user.send_friend_request_to( @user2.receive_url, @group.id) - request.reverse_for @user2 - @user2.activate_friend(@user.person, @group2) - @user.receive request.to_diaspora_xml - end - - it 'should unfriend the other user on the same seed' do - @user.reload - @user2.reload - - @user.friends.count.should == 1 - @user2.friends.count.should == 1 - - @user.person.user_refs.should == 1 - - @user2.person.user_refs.should == 1 - - @user2.unfriend @user.person - @user2.friends.count.should be 0 - - @user.person.reload - @user.person.user_refs.should == 0 - - @user.unfriended_by @user2.person - - @user2.person.reload - @user2.person.user_refs.should == 0 - - @group.reload - @group2.reload - @group.people.count.should == 0 - @group2.people.count.should == 0 - end - end - - describe 'post refs' do - before do - @user2 = Factory.create(:user) - @user.activate_friend( @user2.person, @group) - - @user3 = Factory.create(:user) - @group3 = @user3.group(:name => 'heroes') - - - @user.posts.count.should == 0 - end - - it "should add the post to that user's posts when a user posts it" do - status_message = @user.post :status_message, :message => "hi" - @user.reload - @user.posts.include?(status_message).should be true - end - - it 'should be removed on unfriending' do - status_message = @user2.post :status_message, :message => "hi" - @user.receive status_message.to_diaspora_xml - @user.reload - - @user.posts.count.should == 1 - - @user.unfriend(@user2.person) - - @user.reload - @user.posts.count.should == 0 - - Post.count.should be 1 - end - - it 'should be remove a post if the noone links to it' do - status_message = @user2.post :status_message, :message => "hi" - @user.receive status_message.to_diaspora_xml - @user.reload - - @user.posts.count.should == 1 - - person = @user2.person - @user2.destroy - @user.unfriend(person) - - @user.reload - @user.posts.count.should == 0 - - Post.count.should be 0 - end - - it 'should keep track of user references for one person ' do - status_message = @user2.post :status_message, :message => "hi" - @user.receive status_message.to_diaspora_xml - @user.reload - - @user.posts.count.should == 1 - - status_message.reload - status_message.user_refs.should == 1 - - @user.unfriend(@user2.person) - status_message.reload - - @user.reload - @user.posts.count.should == 0 - - status_message.reload - status_message.user_refs.should == 0 - - Post.count.should be 1 - end - - it 'should not override userrefs on receive by another person' do - @user3 = Factory.create :user - @user3.activate_friend(@user2.person, @group3) - - status_message = @user2.post :status_message, :message => "hi" - @user.receive status_message.to_diaspora_xml - @user3.receive status_message.to_diaspora_xml - @user.reload - @user3.reload - - @user.posts.count.should == 1 - - status_message.reload - status_message.user_refs.should == 2 - - @user.unfriend(@user2.person) - status_message.reload - - @user.reload - @user.posts.count.should == 0 - - status_message.reload - status_message.user_refs.should == 1 - - Post.count.should be 1 - end - - describe 'group streams' do - before do - @group = @user.group(:name => 'heroes') - @group2 = @user.group(:name => 'stuff') - - @user2 = Factory.create :user - @user.activate_friend(@user2.person, @group) - - @user3 = Factory.create :user - @user.activate_friend(@user3.person, @group2) - - @user4 = Factory.create :user - @user.activate_friend(@user4.person, @group2) - end - - it 'should generate a valid stream for a group of people' do - status_message1 = @user2.post :status_message, :message => "hi" - status_message2 = @user3.post :status_message, :message => "heyyyy" - status_message3 = @user4.post :status_message, :message => "yooo" - - @user.receive status_message1.to_diaspora_xml - @user.receive status_message2.to_diaspora_xml - @user.receive status_message3.to_diaspora_xml - @user.reload - - @user.posts_for(:group => @group).include?(status_message1).should be true - @user.posts_for(:group => @group).include?(status_message2).should be false - @user.posts_for(:group => @group).include?(status_message3).should be false - - @user.posts_for(:group => @group2).include?(status_message1).should be false - @user.posts_for(:group => @group2).include?(status_message2).should be true - @user.posts_for(:group => @group2).include?(status_message3).should be true - end - end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cadde8dcc..1de9dca8f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,7 +26,7 @@ RSpec.configure do |config| config.before(:each) do DatabaseCleaner.start stub_sockets_controller - User.stub(:pivotal_only).and_return(:true) + User.stub!(:allowed_email?).and_return(:true) end config.after(:each) do @@ -77,3 +77,9 @@ end def message_queue Post.send(:class_variable_get, :@@queue) end + + def friend_users(user1, group1, user2, group2) + request = user1.send_friend_request_to(user2.receive_url, group1.id) + reversed_request = user2.accept_friend_request( request.id, group2.id) + user1.receive reversed_request.to_diaspora_xml + end