From 34b21e75439b76b5cb01ec8c944c6504161e82b4 Mon Sep 17 00:00:00 2001 From: maelsoucaze Date: Sat, 16 Oct 2010 17:19:19 +0200 Subject: [PATCH 01/28] French localization updates. --- config/locales/diaspora/fr-informal.yml | 12 ++++++++---- config/locales/diaspora/fr.yml | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config/locales/diaspora/fr-informal.yml b/config/locales/diaspora/fr-informal.yml index d8944f81e..f5c4d53bf 100644 --- a/config/locales/diaspora/fr-informal.yml +++ b/config/locales/diaspora/fr-informal.yml @@ -38,6 +38,7 @@ fr-informal: share: "Partager" aspect_friends: add_friends: "ajouter des amis" + photos: "photos" albums: album: you: "toi" @@ -69,10 +70,13 @@ fr-informal: friends_albums: "Albums d’amis" your_albums: "Tes albums" aspects: - index: - photos: "photos" - show: - photos: "photos" + empty_messages: + start_talking: "Personne n’a encore rien dit. Commence dès à présent la conversation !" + nobody: "Tu as forcément des amis, n’hésite pas à les ramener sur Diaspora !" + nobody_in_aspect: "Ton aspect '%{aspect_name}' est vide." + add_friend: "Ajouter un ami" + add_friend_to: "Ajouter quelqu’un à %{aspect_name}" + invite: "Inviter quelqu’un à rejoindre Diaspora !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" diff --git a/config/locales/diaspora/fr.yml b/config/locales/diaspora/fr.yml index c372ee57e..d4bc903c1 100644 --- a/config/locales/diaspora/fr.yml +++ b/config/locales/diaspora/fr.yml @@ -38,6 +38,7 @@ fr: share: "Partager" aspect_friends: add_friends: "ajouter des amis" + photos: "photos" albums: album: you: "vous" @@ -69,10 +70,13 @@ fr: friends_albums: "Albums d’amis" your_albums: "Vos albums" aspects: - index: - photos: "photos" - show: - photos: "photos" + empty_messages: + start_talking: "Personne n’a encore rien dit. Commencez dès à présent la conversation !" + nobody: "Vous avez forcément des amis, n’hésitez pas à les ramener sur Diaspora !" + nobody_in_aspect: "Votre aspect '%{aspect_name}' est vide." + add_friend: "Ajouter un ami" + add_friend_to: "Ajouter quelqu’un à %{aspect_name}" + invite: "Inviter quelqu’un à rejoindre Diaspora !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" From 7083d2aa03a78dd4726c1e6c769fa7c3835145c0 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 16:16:39 -0700 Subject: [PATCH 02/28] Moving friendships into a 'Contact' proxy object. --- app/models/aspect.rb | 3 +- app/models/contact.rb | 16 ++++++ app/models/user.rb | 37 +++++++------ lib/diaspora/user/friending.rb | 29 +++++++---- lib/diaspora/user/querying.rb | 15 ++---- lib/diaspora/user/receiving.rb | 35 ++++++------- spec/lib/diaspora/parser_spec.rb | 5 +- spec/misc_spec.rb | 14 ++--- spec/models/album_spec.rb | 2 +- spec/models/aspect_spec.rb | 44 +++++++++------- spec/models/contact_spec.rb | 31 +++++++++++ spec/models/user/receive_spec.rb | 3 +- spec/models/user/user_friending_spec.rb | 69 +++++++++++++++++++------ spec/models/user/visible_posts_spec.rb | 11 ---- 14 files changed, 199 insertions(+), 115 deletions(-) create mode 100644 app/models/contact.rb create mode 100644 spec/models/contact_spec.rb diff --git a/app/models/aspect.rb b/app/models/aspect.rb index 0fceedead..782e9ea7c 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -6,11 +6,10 @@ class Aspect include MongoMapper::Document key :name, String - key :person_ids, Array key :request_ids, Array key :post_ids, Array - many :people, :in => :person_ids, :class_name => 'Person' + many :people, :foreign_key => 'aspect_ids', :class_name => 'Contact' many :requests, :in => :request_ids, :class_name => 'Request' many :posts, :in => :post_ids, :class_name => 'Post' diff --git a/app/models/contact.rb b/app/models/contact.rb new file mode 100644 index 000000000..1b5a4b050 --- /dev/null +++ b/app/models/contact.rb @@ -0,0 +1,16 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class Contact + include MongoMapper::Document + belongs_to :user + validates_presence_of :user + + belongs_to :person + validates_presence_of :person + + key :aspect_ids, Array, :typecast => 'ObjectId' + many :aspects, :in => :aspect_ids, :class_name => 'Aspect' + validates_presence_of :aspects +end diff --git a/app/models/user.rb b/app/models/user.rb index 343cc2d76..697c38263 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -55,7 +55,7 @@ class User end many :inviters, :in => :inviter_ids, :class_name => 'User' - many :friends, :in => :friend_ids, :class_name => 'Person' + many :friends, :in => :friend_ids, :class_name => 'Contact' many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' @@ -119,22 +119,27 @@ class User end def add_person_to_aspect(person_id, aspect_id, opts = {}) - raise "Can not add person to an aspect you do not own" unless aspect = self.aspects.find_by_id(aspect_id) - raise "Can not add person you are not friends with" unless person = self.find_friend_by_id(person_id) - raise 'Can not add person who is already in the aspect' if aspect.person_ids.include?(person_id) - aspect.people << person + contact = contact_for(Person.find(person_id)) + raise "Can not add person to an aspect you do not own" unless aspect = self.aspects.find_by_id(aspect_id) + raise "Can not add person you are not friends with" unless contact + raise 'Can not add person who is already in the aspect' if aspect.people.include?(contact) + contact.aspects << aspect opts[:posts] ||= self.raw_visible_posts.all(:person_id => person_id) aspect.posts += opts[:posts] + contact.save aspect.save end 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.to_id) + aspect = Aspect.find(aspect_id) + raise "Can not delete a person from an aspect you do not own" unless aspect.user == self + contact = contact_for Person.find(person_id) + contact.aspects.delete aspect opts[:posts] ||= aspect.posts.all(:person_id => person_id) aspect.posts -= opts[:posts] aspect.save + contact.save end ######## Posting ######## @@ -211,17 +216,17 @@ class User aspects = self.aspects.find_all_by_id(aspect_ids) end #send to the aspects - target_people = [] + target_contacts = [] aspects.each { |aspect| aspect.posts << post aspect.save - target_people = target_people | aspect.people + target_contacts = target_contacts | aspect.people } push_to_hub(post) if post.respond_to?(:public) && post.public - push_to_people(post, target_people) + push_to_people(post, target_contacts.map{|c|c.person}) end def push_to_people(post, people) @@ -274,7 +279,7 @@ class User if owns? comment.post comment.post_creator_signature = comment.sign_with_key(encryption_key) comment.save - push_to_people comment, people_in_aspects(aspects_with_post(comment.post.id)) + push_to_people comment, contacts_in_aspects(aspects_with_post(comment.post.id)).map{|c|c.person} elsif owns? comment comment.save push_to_people comment, [comment.post.person] @@ -288,7 +293,7 @@ class User post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) - push_to_people retraction, people_in_aspects(aspects_with_post(post.id)) + push_to_people retraction, contacts_in_aspects(aspects_with_post(post.id)).map{|c| c.person} retraction end @@ -439,11 +444,11 @@ class User end def unfriend_everyone - friends.each { |friend| - if friend.owner? - friend.owner.unfriended_by self.person + friends.each { |contact| + if contact.person.owner? + contact.person.owner.unfriended_by self.person else - self.unfriend friend + self.unfriend contact end } end diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 4a19ffd68..0eef9beba 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -11,7 +11,7 @@ module Diaspora raise "You have already sent a friend request to that person!" if self.pending_requests.detect{ |x| x.destination_url == desired_friend.receive_url } raise "You are already friends with that person!" if self.friends.detect{ - |x| x.receive_url == desired_friend.receive_url} + |x| x.person.receive_url == desired_friend.receive_url} request = Request.instantiate( :to => desired_friend.receive_url, :from => self.person, @@ -91,13 +91,15 @@ module Diaspora end def remove_friend(bad_friend) - raise "Friend not deleted" unless self.friend_ids.delete( bad_friend.id ) - aspects.each{|aspect| - if aspect.person_ids.delete( bad_friend.id ) - aspect.posts.delete_if { |post| - post.person_id == bad_friend.id} - end} - self.save + contact = contact_for(bad_friend) + raise "Friend not deleted" unless self.friend_ids.delete(contact.id) + contact.aspects.each{|aspect| + contact.aspects.delete(aspect) + aspect.posts.delete_if { |post| + post.person_id == bad_friend.id + } + aspect.save + } self.raw_visible_posts.find_all_by_person_id( bad_friend.id ).each{|post| self.visible_post_ids.delete( post.id ) @@ -105,7 +107,7 @@ module Diaspora (post.user_refs > 0 || post.person.owner.nil? == false) ? post.save : post.destroy } self.save - + contact.destroy bad_friend.save end @@ -115,12 +117,17 @@ module Diaspora end def activate_friend(person, aspect) - aspect.people << person - friends << person + new_contact = Contact.create(:user => self, :person => person, :aspects => [aspect]) + new_contact.aspects << aspect + friends << new_contact save aspect.save end + def contact_for(person) + friends.first(:person_id => person.id) + end + def request_from_me?(request) (pending_request_ids.include?(request.id.to_id)) && (request.callback_url == person.receive_url) end diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index b22c8b73e..f1fbc7704 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -24,7 +24,7 @@ module Diaspora def visible_person_by_id( id ) id = id.to_id return self.person if id == self.person.id - result = friends.detect{|x| x.id == id } + result = friends.first(:person_id => id).person result = visible_people.detect{|x| x.id == id } unless result result end @@ -38,22 +38,17 @@ module Diaspora aspects.detect{|x| x.id == id } end - def find_friend_by_id(id) - id = id.to_id - friends.detect{|x| x.id == id } - end - def aspects_with_post( id ) self.aspects.find_all_by_post_ids( id.to_id ) end def aspects_with_person person - aspects.all(:person_ids => person.id) + contact_for(person).aspects end - def people_in_aspects aspects - aspects.inject([]) do |found_people,aspect| - found_people | aspect.people + def contacts_in_aspects aspects + aspects.inject([]) do |contacts,aspect| + contacts | aspect.people end end diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index f459862ba..985346703 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -16,27 +16,24 @@ module Diaspora sender_in_xml = sender(object, xml) - if (salmon_author == sender_in_xml) - - if object.is_a? Request - receive_request object, sender_in_xml - elsif self.friend_ids.include? salmon_author.id - if object.is_a? Retraction - receive_retraction object, xml - elsif object.is_a? Profile - receive_profile object, xml - elsif object.is_a?(Comment) - receive_comment object, xml - else - receive_post object, xml - end - else - raise "Not friends with that person" - end - - else + if (salmon_author != sender_in_xml) raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} " end + + if object.is_a? Request + return receive_request object, sender_in_xml + end + raise "Not friends with that person" unless self.contact_for(salmon_author) + + if object.is_a? Retraction + receive_retraction object, xml + elsif object.is_a? Profile + receive_profile object, xml + elsif object.is_a?(Comment) + receive_comment object, xml + else + receive_post object, xml + end end def sender(object, xml) diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index f97a514c3..ea71f1621 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -98,8 +98,9 @@ describe Diaspora::Parser do user.reload aspect.reload - aspect.people.include?(new_person).should be true - user.friends.include?(new_person).should be true + new_contact = user.contact_for(new_person) + aspect.people.include?(new_contact).should be true + user.friends.include?(new_contact).should be true end it 'should process retraction for a person' do diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 12f7837c1..75580af7b 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -18,18 +18,20 @@ describe 'making sure the spec runner works' do @user2 = Factory.create(:user) @aspect2 = @user2.aspect(:name => "bruisers") friend_users(@user1, @aspect1, @user2, @aspect2) - @user1.reload - @aspect1.reload - @user2.reload - @aspect2.reload end it 'makes the first user friends with the second' do - @aspect1.people.include?(@user2.person).should be_true + contact = @user1.contact_for @user2.person + @user1.friends.should include contact + @aspect1.people.should include contact + contact.aspects.include?( @aspect1 ).should be true end it 'makes the second user friends with the first' do - @aspect2.people.include?(@user1.person).should be_true + contact = @user2.contact_for @user1.person + @user2.friends.should include contact + @aspect2.people.should include contact + contact.aspects.include?( @aspect2 ).should be true end end end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index a47c6026d..e5b93593a 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -20,7 +20,7 @@ describe Album do end it 'has many photos' do - album.associations[:photos].type == :many + album.associations[:photos].type.should == :many end context 'when an album has two attached images' do diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index 336d22cb3..e99856df2 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -29,15 +29,17 @@ describe Aspect do end it 'should be able to have other users' do - aspect.people << user2.person - aspect.people.include?(user.person).should be false - aspect.people.include?(user2.person).should be true + Contact.create(:user => user, :person => user2.person, :aspects => [aspect]) + aspect.people.first(:person_id => user.person.id).should be_nil + aspect.people.first(:person_id => user2.person.id).should_not be_nil aspect.people.size.should == 1 end it 'should be able to have users and people' do - aspect.people << user2.person - aspect.people << friend_2 + contact1 = Contact.create(:user => user, :person => user2.person, :aspects => [aspect]) + contact2 = Contact.create(:user => user, :person => friend_2, :aspects => [aspect]) + aspect.people.include?(contact1).should be_true + aspect.people.include?(contact2).should be_true aspect.save.should be_true end end @@ -69,7 +71,7 @@ describe Aspect do end it 'should have people' do - aspect.people.all.include?(friend).should be true + aspect.people.first(:person_id => friend.id).should be_true aspect.people.size.should == 1 end @@ -87,8 +89,9 @@ describe Aspect do 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 + contact = user.contact_for(friend) + aspects.each{ |asp| asp.people.include?(contact).should be_true } + aspects.include?(aspect_without_friend).should be_false end end end @@ -140,6 +143,7 @@ describe Aspect do end context "aspect management" do + let(:contact){user.contact_for(user2.person)} before do friend_users(user, aspect, user2, aspect2) aspect.reload @@ -149,10 +153,10 @@ describe Aspect do describe "#add_person_to_aspect" do it 'adds the user to the aspect' do - aspect1.people.should_not include user2.person + aspect1.people.should_not include contact user.add_person_to_aspect(user2.person.id, aspect1.id) aspect1.reload - aspect1.people.should include user2.person + aspect1.people.should include contact end it 'raises if its an aspect that the user does not own'do @@ -172,10 +176,10 @@ describe Aspect do it 'deletes a user from the aspect' do user.add_person_to_aspect(user2.person.id, aspect1.id) user.reload - user.aspects.find_by_id(aspect1.id).people.include?(user2.person).should be true + aspect1.reload.people.include?(contact).should be true user.delete_person_from_aspect(user2.person.id, aspect1.id) user.reload - user.aspects.find_by_id(aspect1.id).people.include?(user2.person).should be false + aspect1.reload.people.include?(contact).should be false end it 'should check to make sure you have the aspect ' do @@ -189,9 +193,7 @@ describe Aspect do let(:message2){user3.post(:status_message, :message => "other post", :to => aspect3.id)} before do - friend_users(user, aspect, user3, aspect3) user.receive message.to_diaspora_xml, user2.person - user.receive message2.to_diaspora_xml, user3.person aspect.reload @post_count = aspect.posts.count @post_count1 = aspect1.posts.count @@ -213,6 +215,8 @@ describe Aspect do end it 'should not delete other peoples posts' do + friend_users(user, aspect, user3, aspect3) + user.receive message2.to_diaspora_xml, user3.person user.delete_person_from_aspect(user2.person.id, aspect.id) aspect.reload aspect.posts.should == [message2] @@ -224,24 +228,24 @@ describe Aspect do aspect.reload aspect1.reload - aspect.person_ids.include?(user2.person.id).should be false - aspect1.people.include?(user2.person).should be true + aspect.people.include?(contact).should be false + aspect1.people.include?(contact).should be true end it "should not move a person who is not a friend" do proc{ user.move_friend(:friend_id => friend.id, :from => aspect.id, :to => aspect1.id) }.should raise_error /Can not add person you are not friends with/ aspect.reload aspect1.reload - aspect.people.include?(friend).should be false - aspect1.people.include?(friend).should be false + aspect.people.first(:person_id => friend.id).should be_nil + aspect1.people.first(:person_id => friend.id).should be_nil end it "should not move a person to a aspect that's not his" do proc {user.move_friend(:friend_id => user2.person.id, :from => aspect.id, :to => aspect2.id )}.should raise_error /Can not add person to an aspect you do not own/ aspect.reload aspect2.reload - aspect.people.include?(user2.person).should be true - aspect2.people.include?(user2.person).should be false + aspect.people.include?(contact).should be true + aspect2.people.include?(contact).should be false end it 'should move all posts by that user to the new aspect' do diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb new file mode 100644 index 000000000..5bc480289 --- /dev/null +++ b/spec/models/contact_spec.rb @@ -0,0 +1,31 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe Contact do + describe 'validations' do + let(:contact){Contact.new} + + it 'requires a user' do + contact.valid? + contact.errors.full_messages.should include "User can't be blank" + end + + it 'requires a person' do + contact.valid? + contact.errors.full_messages.should include "Person can't be blank" + end + + it 'has many aspects' do + contact.associations[:aspects].type.should == :many + end + + it 'has at least one aspect' do + contact.valid? + contact.errors.full_messages.should include "Aspects can't be blank" + end + + end +end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index ab83b8c5d..e339c56fc 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -23,10 +23,9 @@ describe User do status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id xml = status_message.to_diaspora_xml - user2.destroy + user2.delete status_message.destroy - user lambda {user.receive xml , user2.person}.should change(Post,:count).by(1) end diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 63a472031..cda6104e1 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -13,6 +13,7 @@ describe Diaspora::UserModules::Friending do let(:person_one) { Factory.create :person } let(:person_two) { Factory.create :person } + let(:person_three) { Factory.create :person } let(:user2) { Factory.create :user } let(:aspect2) { user2.aspect(:name => "aspect two") } @@ -24,6 +25,41 @@ describe Diaspora::UserModules::Friending do Notifier.stub!(:request_accepted).and_return(deliverable) end + + describe '#contact_for' do + + it 'returns a contact' do + contact = Contact.create(:user => user, :person => person_one, :aspects => [aspect]) + user.friends << contact + user.contact_for(person_one).should be_true + end + + it 'returns the correct contact' do + contact = Contact.create(:user => user, :person => person_one, :aspects => [aspect]) + user.friends << contact + + contact2 = Contact.create(:user => user, :person => person_two, :aspects => [aspect]) + user.friends << contact2 + + contact3 = Contact.create(:user => user, :person => person_three, :aspects => [aspect]) + user.friends << contact3 + + user.contact_for(person_two).person.should == person_two + end + + it 'returns nil for a non-contact' do + user.contact_for(person_one).should be_nil + end + + it 'returns nil when someone else has contact with the target' do + contact = Contact.create(:user => user, :person => person_one, :aspects => [aspect]) + user.friends << contact + user2.contact_for(person_one).should be_nil + end + + end + + context 'friend requesting' do it "should assign a request to a aspect" do aspect.requests.size.should == 0 @@ -52,10 +88,9 @@ describe Diaspora::UserModules::Friending do end it 'should not be able to friend request an existing friend' do - user.friends << friend - user.save + friend_users(user, aspect, user2, aspect2) - proc { user.send_friend_request_to(friend, aspect) }.should raise_error + proc { user.send_friend_request_to(user2.person, aspect1) }.should raise_error end it 'should not be able to friend request yourself' do @@ -99,14 +134,14 @@ describe Diaspora::UserModules::Friending do proc { user2.accept_friend_request @request_three.id, aspect2.id }.should_not change(Person, :count) - user2.friends.include?(user.person).should be true + user2.contact_for(user.person).should_not be_nil end it 'should not delete the ignored user on the same pod' do proc { user2.ignore_friend_request @request_three.id }.should_not change(Person, :count) - user2.friends.include?(user.person).should be false + user2.contact_for(user.person).should be_nil end it 'sends an email to the receiving user' do @@ -118,6 +153,7 @@ describe Diaspora::UserModules::Friending do end + context 'Two users receiving requests from one person' do before do user.receive @req_xml, person_one @@ -127,28 +163,28 @@ describe Diaspora::UserModules::Friending do describe '#accept_friend_request' do it 'should both users should befriend the same person' do user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + user.contact_for(person_one).should_not be_nil user2.accept_friend_request @request_two.id, aspect2.id - user2.friends.include?(person_one).should be true + user2.contact_for(person_one).should_not be_nil end it 'should keep the person around if one of the users rejects him' do user.accept_friend_request @request.id, aspect.id - user.friends.include?(person_one).should be true + user.contact_for(person_one).should_not be_nil user2.ignore_friend_request @request_two.id - user2.friends.include?(person_one).should be false + user2.contact_for(person_one).should be_nil end end it 'should keep the person around if the users ignores them' do user.ignore_friend_request user.pending_requests.first.id - user.friends.include?(person_one).should be false + user.contact_for(person_one).should be_nil user2.ignore_friend_request user2.pending_requests.first.id #@request_two.id - user2.friends.include?(person_one).should be false + user2.contact_for(person_one).should be_nil end end @@ -178,12 +214,12 @@ describe Diaspora::UserModules::Friending do user.accept_friend_request @request.id, aspect.id user.pending_requests.size.should be 1 user.friends.size.should be 1 - user.friends.include?(person_one).should be true + user.contact_for(person_one).should_not be_nil 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 + user.contact_for(person_two).should be_nil end end @@ -193,8 +229,9 @@ describe Diaspora::UserModules::Friending do end it 'should unfriend the other user on the same seed' do - lambda { user2.unfriend user.person }.should change { - user2.friends.count }.by(-1) + lambda { + user2.unfriend user.person }.should change { + user2.reload.friends.count }.by(-1) aspect2.reload.people.count.should == 0 end @@ -206,6 +243,8 @@ describe Diaspora::UserModules::Friending do it 'should remove the friend from all aspects they are in' do user.add_person_to_aspect(user2.person.id, aspect1.id) + aspect.reload.people.count.should == 1 + aspect1.reload.people.count.should == 1 lambda { user.unfriended_by user2.person }.should change { user.friends.count }.by(-1) aspect.reload.people.count.should == 0 diff --git a/spec/models/user/visible_posts_spec.rb b/spec/models/user/visible_posts_spec.rb index c14927a4b..77490681a 100644 --- a/spec/models/user/visible_posts_spec.rb +++ b/spec/models/user/visible_posts_spec.rb @@ -73,17 +73,6 @@ describe User do end end - describe '#find_friend_by_id' do - 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 - end - - it 'should not find a non-friend' do - user = Factory :user - user.find_friend_by_id(user2.person.id).should be nil - end - end end describe '#albums_by_aspect' do let!(:first_aspect) {user2.aspect(:name => 'bruisers')} From c27f05ed425189462c531c60debc48af74c63867 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 22 Oct 2010 18:09:57 -0700 Subject: [PATCH 03/28] Initial refactor done, need to stop mapping user.friends to people so much --- app/controllers/application_controller.rb | 2 +- app/controllers/aspects_controller.rb | 2 +- app/controllers/people_controller.rb | 3 ++- app/models/user.rb | 14 +++++++------- app/views/aspects/manage.html.haml | 3 ++- app/views/people/show.html.haml | 2 +- lib/diaspora/user/querying.rb | 15 +++++++++------ spec/controllers/aspects_controller_spec.rb | 11 ++++++----- spec/misc_spec.rb | 8 ++++---- spec/models/aspect_spec.rb | 8 ++++---- spec/models/user/invite_spec.rb | 4 ++-- 11 files changed, 39 insertions(+), 33 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 137705df4..7a68afdf2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -31,7 +31,7 @@ class ApplicationController < ActionController::Base @aspects = current_user.aspects @aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]} - @friends = current_user.friends + @friends = current_user.friends.map{|c| c.person} end end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index ddde8a725..439be4461 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -50,7 +50,7 @@ class AspectsController < ApplicationController unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else - @friends = @aspect.people + @friends = @aspect.people.map{|c| c.person} @posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC' respond_with @aspect end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 352a39c92..e59977586 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -21,7 +21,8 @@ class PeopleController < ApplicationController render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @profile = @person.profile - @aspects_with_person = current_user.aspects_with_person(@person) + @contact = current_user.contact_for(@person) + @aspects_with_person = @contact.aspects if @contact @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last @post_count = @posts.count diff --git a/app/models/user.rb b/app/models/user.rb index 697c38263..39c2baef2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,11 +32,11 @@ class User key :invites, Integer, :default => 5 key :invitation_token, String key :invitation_sent_at, DateTime - key :inviter_ids, Array - key :friend_ids, Array - key :pending_request_ids, Array - key :visible_post_ids, Array - key :visible_person_ids, Array + key :inviter_ids, Array, :typecast => 'ObjectId' + key :friend_ids, Array, :typecast => 'ObjectId' + key :pending_request_ids, Array, :typecast => 'ObjectId' + key :visible_post_ids, Array, :typecast => 'ObjectId' + key :visible_person_ids, Array, :typecast => 'ObjectId' key :invite_messages, Hash @@ -135,11 +135,11 @@ class User aspect = Aspect.find(aspect_id) raise "Can not delete a person from an aspect you do not own" unless aspect.user == self contact = contact_for Person.find(person_id) - contact.aspects.delete aspect + contact.aspect_ids.delete aspect.id opts[:posts] ||= aspect.posts.all(:person_id => person_id) aspect.posts -= opts[:posts] - aspect.save contact.save + aspect.save end ######## Posting ######## diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index 8ac04b893..a49030d34 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -48,7 +48,8 @@ %li!= remove_link(aspect) %ul.dropzone{:data=>{:aspect_id=>aspect.id}} - -for person in aspect.people + -for contact in aspect.people + -person = contact.person %li.person{:data=>{:guid=>person.id, :aspect_id=>aspect.id}} .delete .x diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index a20026e4f..931c23104 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -17,7 +17,7 @@ %li %i= t(".last_seen",:how_long_ago => how_long_ago(@posts.first)) - - if @person != current_user.person && current_user.friends.include?(@person) + - if @person != current_user.person && @contact %li %i= t(".friends_since",:how_long_ago => how_long_ago(@person)) %li diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index f1fbc7704..f0097a172 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -23,14 +23,17 @@ module Diaspora def visible_person_by_id( id ) id = id.to_id - return self.person if id == self.person.id - result = friends.first(:person_id => id).person - result = visible_people.detect{|x| x.id == id } unless result - result + if id == self.person.id + self.person + elsif friend = friends.first(:person_id => id) + friend.person + else + visible_people.detect{|x| x.id == id } + end end - def friends_not_in_aspect( aspect ) - Person.all(:id.in => self.friend_ids, :id.nin => aspect.person_ids) + def friends_not_in_aspect( aspect ) + Contact.all(:user_id => self.id, :aspect_ids.ne => aspect._id).map{|c| c.person} end def aspect_by_id( id ) diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 425d3de4b..e1695eb3f 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -14,6 +14,7 @@ describe AspectsController do @user2 = Factory.create(:user) @aspect2 = @user2.aspect(:name => "party people") friend_users(@user,@aspect, @user2, @aspect2) + @contact = @user.contact_for(@user2.person) sign_in :user, @user end @@ -21,7 +22,7 @@ describe AspectsController do it "assigns @friends to all the user's friends" do Factory.create :person get :index - assigns[:friends].should == @user.friends + assigns[:friends].should == @user.friends.map{|c| c.person} end end @@ -75,20 +76,20 @@ describe AspectsController do describe "#add_to_aspect" do it 'adds the users to the aspect' do @aspect1.reload - @aspect1.people.include?(@user2.person).should be false + @aspect1.people.include?(@contact).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 + @aspect1.people.include?(@contact).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 + @aspect.people.include?(@contact).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 + @aspect1.people.include?(@contact).should be false end end end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 75580af7b..fcad1a5e3 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -22,15 +22,15 @@ describe 'making sure the spec runner works' do it 'makes the first user friends with the second' do contact = @user1.contact_for @user2.person - @user1.friends.should include contact - @aspect1.people.should include contact + @user1.friends.include?(contact).should be_true + @aspect1.people.include?(contact).should be_true contact.aspects.include?( @aspect1 ).should be true end it 'makes the second user friends with the first' do contact = @user2.contact_for @user1.person - @user2.friends.should include contact - @aspect2.people.should include contact + @user2.friends.include?(contact).should be_true + @aspect2.people.include?(contact).should be_true contact.aspects.include?( @aspect2 ).should be true end end diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index e99856df2..7d6cde6c9 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -153,10 +153,10 @@ describe Aspect do describe "#add_person_to_aspect" do it 'adds the user to the aspect' do - aspect1.people.should_not include contact + aspect1.people.include?(contact).should be_false user.add_person_to_aspect(user2.person.id, aspect1.id) aspect1.reload - aspect1.people.should include contact + aspect1.people.include?(contact).should be_true end it 'raises if its an aspect that the user does not own'do @@ -228,8 +228,8 @@ describe Aspect do aspect.reload aspect1.reload - aspect.people.include?(contact).should be false - aspect1.people.include?(contact).should be true + aspect.people.include?(contact).should be_false + aspect1.people.include?(contact).should be_true end it "should not move a person who is not a friend" do diff --git a/spec/models/user/invite_spec.rb b/spec/models/user/invite_spec.rb index 67b5f35bf..21f4670a7 100644 --- a/spec/models/user/invite_spec.rb +++ b/spec/models/user/invite_spec.rb @@ -68,7 +68,7 @@ describe User do it 'throws if you try to add someone you"re friends with' do friend_users(inviter, aspect, another_user, wrong_aspect) inviter.reload - proc{inviter.invite_user(:email => another_user.email, :aspect_id => aspect.id)}.should raise_error /You are already friends with this person/ + proc{inviter.invite_user(:email => another_user.email, :aspect_id => aspect.id)}.should raise_error /You are already friends with that person/ end it 'sends a friend request to a user with that email into the aspect' do @@ -126,7 +126,7 @@ describe User do u.reload inviter inviter.receive_salmon(u.salmon(u.accept_friend_request(request.id, aspect2.id)).xml_for(inviter.person)) - inviter.friends.include?(u.person).should be true + inviter.contact_for(u.person).should_not be_nil end end end From 14ac908c3d26ea44713f3abb6814948ca10d21bf Mon Sep 17 00:00:00 2001 From: maelsoucaze Date: Mon, 25 Oct 2010 00:06:05 +0200 Subject: [PATCH 04/28] French localizations updates. --- config/locales/diaspora/fr-informal.yml | 31 +++++++++++++++++++------ config/locales/diaspora/fr.yml | 31 +++++++++++++++++++------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/config/locales/diaspora/fr-informal.yml b/config/locales/diaspora/fr-informal.yml index f5c4d53bf..42267d796 100644 --- a/config/locales/diaspora/fr-informal.yml +++ b/config/locales/diaspora/fr-informal.yml @@ -6,6 +6,15 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. fr-informal: + activemodel: + errors: + models: + user: + attributes: + username: + taken: "est déjà pris" + email: + taken: "est déjà pris" hello: "Bonjour tout le monde" application: helper: @@ -70,13 +79,14 @@ fr-informal: friends_albums: "Albums d’amis" your_albums: "Tes albums" aspects: - empty_messages: - start_talking: "Personne n’a encore rien dit. Commence dès à présent la conversation !" + no_friends_message: nobody: "Tu as forcément des amis, n’hésite pas à les ramener sur Diaspora !" nobody_in_aspect: "Ton aspect '%{aspect_name}' est vide." add_friend: "Ajouter un ami" add_friend_to: "Ajouter quelqu’un à %{aspect_name}" invite: "Inviter quelqu’un à rejoindre Diaspora !" + no_posts_message: + start_talking: "Personne n’a encore rien dit. Commence dès à présent la conversation !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" @@ -94,12 +104,12 @@ fr-informal: success: "%{name} a été supprimé avec succès." update: success: "Ton aspect, %{name}, a été édité avec succès." - move_friends: - failure: "L’édition de l’aspect concernant ton ami %{real_name} a échoué." - success: "Les aspects ont été édités avec succès." move_friend: failure: "ne fonctionne pas %{inspect}" - success: "Tu montres à présent à ton ami un aspect différent au tiens." + success: "Personne déplacée vers le nouvel aspect" + add_to_aspect: + failure: "L’ajout de l’ami vers l’aspect a échoué." + success: "Tu as ajouté l’ami à l’aspect avec succès." helper: remove: "supprimer" aspect_not_empty: "L’aspect n’est pas vide" @@ -140,6 +150,8 @@ fr-informal: photo: show_comments: "afficher les commentaires" posted_a_new_photo_to: "a publié une nouvelle photo dans" + delete: "Supprimer" + are_you_sure: "Es-tu sûr(e) ?" new: new_photo: "Nouvelle photo" back_to_list: "Retourner à la liste" @@ -163,6 +175,7 @@ fr-informal: sent: 'Ton invitation a été envoyée.' no_more: 'Tu n’as plus d’invitation.' already_sent: 'Tu as déjà invité cette personne.' + already_friends: 'Tu es déjà ami avec cette personne' invitation_token_invalid: 'Le jeton d’invitation fourni n’est pas valide !' updated: 'Ton mot de passe a été réglé avec succès. Tu es à présent connecté.' @@ -204,6 +217,7 @@ fr-informal: save: "sauver" are_you_sure: "Es-tu sûr(e) ?" remove_friend: "supprimer de mes amis" + no_posts: "aucun message à afficher !" requests: new_request: add_a_new_friend_to: "Ajouter un nouvel ami à" @@ -216,6 +230,9 @@ fr-informal: ignore: "Requête d’ami ignorée." create: error: "Aucun résultat Diaspora n’a été trouvé avec cette adresse e-mail !" - already_friends: "Vous êtes déjà amis avec %{destination_url}!" + invalid_identity: "Cette identité n’est pas proprement formatée" + error_server: "Un problème est survenu avec l’autre serveur. Il n’existe peut-être pas ?" + yourself: "Tu ne peux pas être ami avec toi-même !" + already_friends: "Tu es déjà ami avec %{destination_url}!" success: "Une requête d’ami a été envoyée à %{destination_url}." horribly_wrong: "Quelque chose d’horrible s’est produit." diff --git a/config/locales/diaspora/fr.yml b/config/locales/diaspora/fr.yml index d4bc903c1..baf9d1b82 100644 --- a/config/locales/diaspora/fr.yml +++ b/config/locales/diaspora/fr.yml @@ -6,6 +6,15 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. fr: + activemodel: + errors: + models: + user: + attributes: + username: + taken: "est déjà pris" + email: + taken: "est déjà pris" hello: "Bonjour tout le monde" application: helper: @@ -70,13 +79,14 @@ fr: friends_albums: "Albums d’amis" your_albums: "Vos albums" aspects: - empty_messages: - start_talking: "Personne n’a encore rien dit. Commencez dès à présent la conversation !" + no_friends_message: nobody: "Vous avez forcément des amis, n’hésitez pas à les ramener sur Diaspora !" nobody_in_aspect: "Votre aspect '%{aspect_name}' est vide." add_friend: "Ajouter un ami" add_friend_to: "Ajouter quelqu’un à %{aspect_name}" invite: "Inviter quelqu’un à rejoindre Diaspora !" + no_posts_message: + start_talking: "Personne n’a encore rien dit. Commencez dès à présent la conversation !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" @@ -94,12 +104,12 @@ fr: success: "%{name} a été supprimé avec succès." update: success: "Votre aspect, %{name}, a été édité avec succès." - move_friends: - failure: "L’édition de l’aspect concernant votre ami %{real_name} a échoué." - success: "Les aspects ont été édités avec succès." move_friend: failure: "ne fonctionne pas %{inspect}" - success: "Vous montrez à présent à votre ami un aspect différent au vôtre." + success: "Personne déplacée vers le nouvel aspect" + add_to_aspect: + failure: "L’ajout de l’ami vers l’aspect a échoué." + success: "Vous avez ajouté l’ami vers l’aspect avec succès." helper: remove: "supprimer" aspect_not_empty: "L’aspect n’est pas vide" @@ -140,6 +150,8 @@ fr: photo: show_comments: "afficher les commentaires" posted_a_new_photo_to: "a publié une nouvelle photo dans" + delete: "Supprimer" + are_you_sure: "Êtes-vous sûr(e) ?" new: new_photo: "Nouvelle photo" back_to_list: "Retourner à la liste" @@ -163,6 +175,7 @@ fr: sent: 'Votre invitation a été envoyée.' no_more: 'Vous n’avez plus d’invitation.' already_sent: 'Vous avez déjà invité cette personne.' + already_friends: 'Vous êtes déjà ami avec cette personne' invitation_token_invalid: 'Le jeton d’invitation fourni n’est pas valide !' updated: 'Votre mot de passe a été réglé avec succès. Vous êtes à présent connecté.' @@ -204,6 +217,7 @@ fr: save: "sauver" are_you_sure: "Êtes-vous sûr(e) ?" remove_friend: "supprimer de mes amis" + no_posts: "aucun message à afficher !" requests: new_request: add_a_new_friend_to: "Ajouter un nouvel ami à" @@ -216,6 +230,9 @@ fr: ignore: "Requête d’ami ignorée." create: error: "Aucun résultat Diaspora n’a été trouvé avec cette adresse e-mail !" - already_friends: "Vous êtes déjà amis avec %{destination_url}!" + invalid_identity: "Cette identité n’est pas proprement formatée" + error_server: "Un problème est survenu avec l’autre serveur. Il n’existe peut-être pas ?" + yourself: "Vous ne pouvez pas être ami avec vous-même !" + already_friends: "Vous êtes déjà ami avec %{destination_url}!" success: "Une requête d’ami a été envoyée à %{destination_url}." horribly_wrong: "Quelque chose d’horrible s’est produit." From d61739210828505459ecfd44ce8c53944059cec1 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Mon, 25 Oct 2010 21:31:40 +0200 Subject: [PATCH 05/28] Added/complemented swedish translation --- config/locales/devise/devise.sv.yml | 8 +- config/locales/diaspora/sv.yml | 233 +++++++++++++++++++++++++++- 2 files changed, 237 insertions(+), 4 deletions(-) diff --git a/config/locales/devise/devise.sv.yml b/config/locales/devise/devise.sv.yml index dab52d609..39d09b158 100644 --- a/config/locales/devise/devise.sv.yml +++ b/config/locales/devise/devise.sv.yml @@ -31,9 +31,13 @@ sv: updated: 'Ditt konto har uppdateras.' destroyed: 'Ditt konto är avslutat. Välkommen åter!' unlocks: - send_instructions: 'Du kommer att få ett ebrev med instruktioner för att låsa upp ditt konto inom några minuter.' + send_instructions: 'Du kommer att få ett mail med instruktioner för att låsa upp ditt konto inom några minuter.' unlocked: 'Ditt konto har är nu upplåst och du är inloggad' + invitations: + send_instructions: 'Din inbjudan är nu skickad.' + invitation_token_invalid: 'Denna inbjudan är ej giltig!' + updated: 'Ditt lösenord är nu inställt och du är inloggad.' mailer: confirmation_instructions: 'Instruktioner för att verifiera ditt konto.' - reset_password_instructions: 'Instruktioner för att terställa ditt lösenord.' + reset_password_instructions: 'Instruktioner för att återställa ditt lösenord.' unlock_instructions: 'Instruktioner för att låsa upp ditt konto.' diff --git a/config/locales/diaspora/sv.yml b/config/locales/diaspora/sv.yml index b7d89d019..cd3aa9c83 100644 --- a/config/locales/diaspora/sv.yml +++ b/config/locales/diaspora/sv.yml @@ -2,8 +2,237 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -# Swedish localization file. +# Sample localization file for English. Add more files in this directory for other locales. # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. sv: - hello: "Hej" + activemodel: + errors: + models: + user: + attributes: + username: + taken: "är redan taget" + email: + taken: "är redan taget" + hello: "Hej världen!" + application: + helper: + unknown_person: "okänd person" + new_requests: "nya förfrågningar" + dashboards: + helper: + home: "hem" + error_messages: + helper: + invalid_fields: "Ogiltiga fält" + correct_the_following_errors_and_try_again: "Rätta följande fel och försök igen." + people: + helper: + results_for: " resultat för %{params}" + people_on_pod_are_aware_of: " personer på denna pod är medveten om att" + layouts: + application: + edit_profile: "ändra profil" + logout: "logga ut" + shared: + aspect_nav: + all_aspects: "Alla Aspekter" + manage: "Hantera" + manage_your_aspects: "Hantera dina Aspekter" + sub_header: + all_aspects: "Alla Aspekter" + manage_aspects: "Hantera Aspekter" + publisher: + share: "Dela" + aspect_friends: + add_friends: "lägg till vänner" + photos: "foton" + albums: + album: + you: "du" + new_album: + create: "skapa" + add_a_new_album: "Lägg till ett nytt Album" + show: + edit_album: "Ändra Album" + albums: "album" + updated: "updated" + by: "av" + edit: + editing: "Ändrar" + updated: "uppdaterad" + are_you_sure: "Är du säker?" + delete_album: "Ta bort album" + cancel: "Avbryt" + index: + home: "hem" + new_album: "NyttAlbum" + create: + success: "Du har nu skapat albumet %{name}." + update: + success: "Albumet %{name} ändrades." + failure: "Ändringarna av albumet %{name} misslyckades." + destroy: + success: "Albumet %{name} är nu borttaget." + helper: + friends_albums: "Vänners Album" + your_albums: "Dina Album" + aspects: + no_friends_message: + nobody: "Vi vet att du har vänner, bjud in dem till Diaspora!" + nobody_in_aspect: "Aspekten '%{aspect_name}' är tom." + add_friend: "Lägg till en vän" + add_friend_to: "Lägg till en vän i %{aspect_name}" + invite: "Bjud in en vän till Diaspora!" + no_posts_message: + start_talking: "Ingen har sagt något än. Bli först!" + manage: + add_a_new_aspect: "Lägg till en ny aspekt" + add_a_new_friend: "Lägg till en ny vän" + show: "Visa" + update_aspects: "Uppdatera Aspekter" + requests: "Förfrågningar" + ignore_remove: "Ignorera/Ta bort" + new_aspect: + add_a_new_aspect: "Lägg till ny aspekt" + create: "Skapa" + create: + success: "Klicka på plustecknet till höger för att välja vilka som kan se din nya aspekt." + failure: "Aspekten kunde inte skapas." + destroy: + success: "%{name} är nu borttagen." + update: + success: "Din aspekt, %{name}, är nu ändrad." + move_friend: + failure: "fungerade inte %{inspect}" + success: "Personen flyttades till den nya aspekten" + add_to_aspect: + failure: "Misslyckades med att lägga personen i den nya aspekten." + success: "Personen tillagt i aspekten." + helper: + remove: "ta bort" + aspect_not_empty: "Aspekten är inte tom" + users: + edit: + editing_profile: "Ändrar profil" + profile: + cancel: "Avbryt" + update_profile: "Uppdatera Profil" + home: "Hem" + diaspora_username: "DIASPORA-ID:" + info: "Info" + picture: "Profilbild" + editing_profile: "Ändrar profil" + albums: "Album" + you_dont_have_any_photos: "Do har inga foton! Gå till" + page_to_upload_some: "sidan för att ladda upp några." + or: "eller" + destroy: "Ditt konto är nu stängt." + comments: + comment: + ago: "sedan" + new_comment: + comment: "Kommentar" + photos: + show: + prev: "föregående" + full_size: "full storlek" + next: "nästa" + edit_photo: "Ändra Foto" + delete_photo: "Ta bort Foto" + are_you_sure: "Är du säker?" + comments: "kommentarer" + edit: + editing: "Ändrar" + are_you_sure: "Är du säker?" + delete_photo: "Ta bort Foto" + photo: + show_comments: "visa kommentarer" + posted_a_new_photo_to: "laddade upp ett nytt foto till" + delete: "Ta bort" + are_you_sure: "Är du säker?" + new: + new_photo: "Nytt Foto" + back_to_list: "Tillbaka till listan" + post_it: "skicka!" + create: + runtime_error: "Fotot kunde inte laddas upp." + integrity_error: "Fotot kunde inte laddas upp. Är du säker på att den där filen var en bild?" + type_error: "Fotot kunde inte laddas upp. Är du säker på att det var en bild du försökte ladda upp?" + update: + notice: "Fotot är nu uppdaterat." + error: "Misslyckades med att ändra fotot." + destroy: + notice: "Fotot borttaget." + registrations: + new: + sign_up: "Registrera dig" + create: + success: "Du har nu gått med i Diaspora!" + invitations: + create: + sent: 'Din inbjudan är nu skickad.' + no_more: 'Du har inga fler inbjudningar.' + already_sent: 'Du har redan bjudit in denna person.' + already_friends: 'Du är redan vän med den här personen' + invitation_token_invalid: 'Din inbjudningskod är inte giltig!' + updated: 'Ditt lösenord är nu ändrats, och du har loggats in.' + + status_messages: + new_status_message: + tell_me_something_good: "berätta något intressant" + oh_yeah: "oh yeah!" + status_message: + show_comments: "visa kommentarer" + delete: "Ta bort" + are_you_sure: "Är du säker?" + show: + status_message: "Statusmeddelande" + comments: "kommentarer" + are_you_sure: "Är du säker?" + destroy: "Ta bort" + view_all: "Visa alla" + message: "Meddelande" + owner: "Ägare" + helper: + no_message_to_display: "Inget meddelande att visa." + people: + person: + add_friend: "lägg till vän" + pending_request: "väntande förfrågan" + index: + add_friend: "lägg till vän" + real_name: "verkligt namn" + diaspora_handle: "diaspora-id" + thats_you: "det är du!" + friend_request_pending: "förfrågan är skickad" + you_have_a_friend_request_from_this_person: "du har en väntande förfrågan från den här personen" + new: + new_person: "Ny Person" + back_to_list: "Tillbaka till listan" + show: + last_seen: "senast sedd: %{how_long_ago}" + friends_since: "vänner sedan: %{how_long_ago}" + save: "spara" + are_you_sure: "Är du säker?" + remove_friend: "ta bort vän" + no_posts: "ingenting att visa!" + requests: + new_request: + add_a_new_friend_to: "Lägg till en vän till" + enter_a_diaspora_username: "Ange ett Diaspora-id:" + your_diaspora_username_is: "Ditt Diaspora-id är: %{diaspora_handle}" + friends_username: "Vännens Diaspora-id" + destroy: + success: "Ni är nu vänner." + error: "Var god välj en aspekt!" + ignore: "Ignorerade förfrågan." + create: + error: "Ingen diaspora seed med detta id hittades!" + invalid_identity: "Detta id har ett ogiltigt format" + error_server: "Problem att kontaka den andra servern. Är det möjligt att den inte finns?" + yourself: "Du kan inte fråga dig själv!" + already_friends: "Du är redan vän med %{destination_url}!" + success: "En förfrågan har skickats till %{destination_url}." + horribly_wrong: "Nu gick något rejält fel här." From 1382bd9d081285d112c9cc5b87910ab5b3757879 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Mon, 25 Oct 2010 21:45:43 +0200 Subject: [PATCH 06/28] Fixed header in swedish translation --- config/locales/diaspora/sv.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/locales/diaspora/sv.yml b/config/locales/diaspora/sv.yml index cd3aa9c83..764734e55 100644 --- a/config/locales/diaspora/sv.yml +++ b/config/locales/diaspora/sv.yml @@ -2,8 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -# Sample localization file for English. Add more files in this directory for other locales. -# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. +# Localization file for Swedish sv: activemodel: From 917d1838dee44667252c23d362452b312e3df415 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Mon, 25 Oct 2010 18:55:51 -0700 Subject: [PATCH 07/28] MS IZ specs are green --- app/controllers/users_controller.rb | 5 +- app/models/contact.rb | 2 + lib/diaspora/exporter.rb | 38 ++++++++--- lib/diaspora/importer.rb | 73 ++++++++++++++++---- spec/lib/diaspora/exporter_spec.rb | 102 +++++++++++++++++++--------- spec/lib/diaspora/importer_spec.rb | 46 ++++++++----- spec/lib/verify_spec.rb | 17 +++++ 7 files changed, 207 insertions(+), 76 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aacff8504..9b923395f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -86,16 +86,13 @@ class UsersController < ApplicationController def import xml = params[:upload][:file].read - params[:user][:diaspora_handle] = 'asodij@asodij.asd' - - begin importer = Diaspora::Importer.new(Diaspora::Parsers::XML) importer.execute(xml, params[:user]) flash[:notice] = "hang on a sec, try logging in!" rescue Exception => e - flash[:error] = "Derp, something went wrong: #{e.message}" + flash[:error] = "Something went wrong: #{e.message}" end redirect_to new_user_registration_path diff --git a/app/models/contact.rb b/app/models/contact.rb index 1b5a4b050..b11b591cb 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -4,6 +4,8 @@ class Contact include MongoMapper::Document + attr_accessor :aspect_names #this is only used in the importer + belongs_to :user validates_presence_of :user diff --git a/lib/diaspora/exporter.rb b/lib/diaspora/exporter.rb index 5f40322fb..c435749e3 100644 --- a/lib/diaspora/exporter.rb +++ b/lib/diaspora/exporter.rb @@ -22,16 +22,19 @@ module Diaspora xml.parent << user.person.to_xml } + + + xml.aspects { user.aspects.each do |aspect| xml.aspect { xml.name aspect.name - xml.person_ids { - aspect.person_ids.each do |id| - xml.person_id id - end - } +# xml.person_ids { + #aspect.person_ids.each do |id| + #xml.person_id id + #end + #} xml.post_ids { aspect.posts.find_all_by_person_id(user_person_id).each do |post| @@ -42,16 +45,25 @@ module Diaspora end } - xml.people { + xml.contacts { user.friends.each do |friend| - xml.parent << friend.to_xml + xml.contact { + xml.user_id friend.user_id + xml.person_id friend.person_id + + xml.aspects { + friend.aspects.each do |aspect| + xml.aspect { + xml.name aspect.name + } + end + } + } end } xml.posts { user.raw_visible_posts.find_all_by_person_id(user_person_id).each do |post| - #post_doc = post.to_xml - #post.comments.each do |comment| # post_doc << comment.to_xml #end @@ -59,6 +71,14 @@ module Diaspora xml.parent << post.to_xml end } + + xml.people { + user.friends.each do |friend| + person = friend.person + xml.parent << person.to_xml + + end + } } end diff --git a/lib/diaspora/importer.rb b/lib/diaspora/importer.rb index e1e8ad97f..57dd11ae9 100644 --- a/lib/diaspora/importer.rb +++ b/lib/diaspora/importer.rb @@ -9,8 +9,9 @@ module Diaspora self.class.send(:include, strategy) end - def commit(user, person, aspects, people, posts, opts = {}) - filter = verify_and_clean(user, person, people, aspects, posts) + def commit(user, person, aspects, people, posts, contacts, opts = {}) + filter = verify_and_clean(user, person, people, aspects, posts, contacts) + #assume data is good # to go @@ -27,11 +28,9 @@ module Diaspora user.visible_post_ids = filter[:whitelist].keys - user.friend_ids = people.collect{ |x| x.id } - user.visible_person_ids = user.friend_ids + #user.friend_ids = + user.visible_person_ids = people.collect{ |x| x.id } - user.save! - user.person.save! posts.each do |post| post.save! if filter[:unknown].include? post.id @@ -43,27 +42,59 @@ module Diaspora user.aspects << aspect end - - people.each do |p| p.save! if filter[:people].include? p.id.to_s end + + contacts.each do |contact| + contact.user = user + + user.friends << contact + contact.save! + end + + + puts user.persisted? + + puts user.inspect + user.save(:validate => false) + + + end + + def assign_aspect_ids(contacts, aspects) + a_hash = {} + aspects.each{|x| a_hash[x.name]=x.id} + + contacts.each do |contact| + contact.aspect_names.each do |x| + contact.aspect_ids << a_hash[x] + end + contact.aspect_names = nil + end + + end ### verification (to be module) ################ - def verify_and_clean(user, person, people, aspects, posts) + def verify_and_clean(user, person, people, aspects, posts, contacts) verify_user(user) verify_person_for_user(user, person) filters = filter_posts(posts, person) - - clean_aspects(aspects, filters[:whitelist]) + filters[:all_person_ids] = people.collect{ |x| x.id.to_id } - + raise "incorrect number of contacts" unless verify_contacts(contacts, filters[:all_person_ids]) + assign_aspect_ids(contacts, aspects) filters[:people] = filter_people(people) filters end + + def verify_contacts(contacts, person_ids) + return false if contacts.count != person_ids.count + contacts.all?{|x| person_ids.include?(x.person_id)} + end def verify_user(user) User.find_by_id(user.id).nil? ? true : raise("User already exists!") @@ -126,11 +157,12 @@ module Diaspora user, person = parse_user_and_person(doc) aspects = parse_aspects(doc) + contacts = parse_contacts(doc) people = parse_people(doc) posts = parse_posts(doc) - + user - commit(user, person, aspects, people, posts, opts) + commit(user, person, aspects, people, posts, contacts, opts) end def parse_user_and_person(doc) @@ -152,7 +184,6 @@ module Diaspora aspect = Aspect.new aspect.name = a.xpath('/aspect/name').text aspect.post_ids = a.xpath('/aspect/post_ids/post_id').collect{ |x| x.text.to_id } - aspect.person_ids = a.xpath('/aspect/person_ids/person_id').collect{ |x| x.text.to_id } aspects << aspect end aspects @@ -165,6 +196,18 @@ module Diaspora end end + def parse_contacts(doc) + contacts = [] + contact_doc = doc.xpath('/export/contacts/contact') + + contact_doc.each do |x| + contact = Contact.new + contact.person_id = x.xpath("person_id").text.to_id + contact.aspect_names = x.xpath('aspects/aspect/name').collect{ |x| x.text} + contacts << contact + end + contacts + end def parse_posts(doc) post_doc = doc.xpath('/export/posts/status_message') diff --git a/spec/lib/diaspora/exporter_spec.rb b/spec/lib/diaspora/exporter_spec.rb index 88369dacf..e2db3b5eb 100644 --- a/spec/lib/diaspora/exporter_spec.rb +++ b/spec/lib/diaspora/exporter_spec.rb @@ -11,6 +11,7 @@ describe Diaspora::Exporter do let!(:user2) { Factory(:user) } let!(:user3) { Factory(:user) } + let!(:aspect) { user1.aspect(:name => "Old Work") } let(:aspect1) { user1.aspect(:name => "Work") } let(:aspect2) { user2.aspect(:name => "Family") } let(:aspect3) { user3.aspect(:name => "Pivots") } @@ -19,47 +20,84 @@ describe Diaspora::Exporter do let!(:status_message2) { user1.post(:status_message, :message => "Two", :public => true, :to => aspect1.id) } let!(:status_message3) { user2.post(:status_message, :message => "Three", :public => false, :to => aspect2.id) } - let(:exported) { Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1) } + let(:exported) { Nokogiri::XML(Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1)) } - it 'should include a users posts' do - exported.should include status_message1.message - exported.should include status_message2.message - exported.should_not include status_message3.message + context '' do + let(:user_xml) {exported.xpath('//user').to_s} + it 'should include a users private key' do + user_xml.to_s.should include user1.serialized_private_key + end end - it 'should include a users private key' do - exported.should include user1.serialized_private_key + context '' do + let(:aspects_xml) {exported.xpath('//aspects').to_s} + it 'should include the aspect name' do + + end + + it 'should include the post_ids' do + aspects_xml.should include status_message1.id.to_s + aspects_xml.should include status_message2.id.to_s + end end - it 'should include post_ids' do - doc = Nokogiri::XML::parse(exported) - doc.xpath('//aspects').to_s.should include status_message1.id.to_s + context '' do - doc.xpath('//aspects').to_s.should include status_message2.id.to_s - doc.xpath('//posts').to_s.should include status_message1.id.to_s + before do + friend_users(user1, aspect1, user3, aspect3) + user1.add_person_to_aspect(user3.person.id, aspect.id) + user1.reload + end + + let(:contacts_xml) {exported.xpath('//contacts').to_s} + it 'should include a person id' do + contacts_xml.should include user3.person.id.to_s + end + + it 'should include an aspects names of all aspects they are in' do + #contact specific xml needs to be tested + user1.friends.find_by_person_id(user3.person.id).aspects.count.should > 0 + user1.friends.find_by_person_id(user3.person.id).aspects.each { |aspect| + contacts_xml.should include aspect.name + } + end end - it 'should include post created at time' do - doc = Nokogiri::XML::parse(exported) - Time.parse(doc.xpath('//posts/status_message/created_at').first.text).should == status_message1.created_at + context '' do + let(:people_xml) {exported.xpath('//people').to_s} + before do + friend_users(user1, aspect1, user3, aspect3) + user1.reload + end + it 'should include persons id' do + people_xml.should include user3.person.id.to_s + end + + it 'should include their profile' do + people_xml.should include user3.person.profile.first_name + people_xml.should include user3.person.profile.last_name + end + + it 'should include their public key' do + people_xml.should include user3.person.exported_key + end + + it 'should include their diaspora handle' do + people_xml.should include user3.person.diaspora_handle + end end - it 'should include a list of users posts' do - doc = Nokogiri::XML::parse(exported) - posts = doc.xpath('//posts').to_s - posts.should include(status_message1.message) - end - - it 'should serialize a users friends' do - friend_users(user1, aspect1, user3, aspect3) - doc = Nokogiri::XML::parse(exported) - doc.xpath('/export/people').to_s.should include user3.person.id.to_s - end - - it 'should serialize only a users posts within his aspects' do - message = Factory(:status_message, :message => "Shouldn't be here", :person => user3.person) - aspect1.posts << message - doc = Nokogiri::XML::parse(exported) - doc.xpath('/export/aspects').to_s.should_not include message.message + context '' do + let(:posts_xml) {exported.xpath('//posts').to_s} + it 'should include many posts xml' do + posts_xml.should include status_message1.message + posts_xml.should include status_message2.message + posts_xml.should_not include status_message3.message + end + + it 'should include post created at time' do + doc = Nokogiri::XML::parse(posts_xml) + Time.parse(doc.xpath('//posts/status_message/created_at').first.text).should == status_message1.created_at + end end end diff --git a/spec/lib/diaspora/importer_spec.rb b/spec/lib/diaspora/importer_spec.rb index 268b0f5e1..9d3197698 100644 --- a/spec/lib/diaspora/importer_spec.rb +++ b/spec/lib/diaspora/importer_spec.rb @@ -73,14 +73,14 @@ describe Diaspora::Importer do @user1.friends.count.should be 4 - @user1.friends.should include @user2.person - @user1.friends.should include @user3.person - @user1.friends.should include @user4.person - @user1.friends.should include @user5.person + @user1.contact_for(@user2.person).should_not be_nil + @user1.contact_for(@user3.person).should_not be_nil + @user1.contact_for(@user4.person).should_not be_nil + @user1.contact_for(@user5.person).should_not be_nil # User is generated with two pre-populated aspects @user1.aspects.count.should be 6 - @user1.aspects.find_by_name("Dudes").people.should include @user2.person + @user1.aspects.find_by_name("Dudes").people.find_by_person_id(@user2.person.id).should_not be_nil @user1.aspects.find_by_name("Dudes").posts.should include @status_message5 @user1.raw_visible_posts.count.should be 6 @@ -137,9 +137,21 @@ describe Diaspora::Importer do it 'should should have post ids' do aspects.any?{|x| x.post_ids.count > 0}.should be true end + end - it 'should have person ids' do - aspects.any?{|x| x.person_ids.count > 0}.should be true + describe '#parse_contacts' do + let(:contacts) { @importer.parse_contacts(@doc) } + + it 'should return an array' do + contacts.count.should == 4 + end + + it 'should should have post ids' do + contacts.all?{|x| x.aspect_names.count > 0}.should be true + end + + it 'should should have a person id' do + contacts.all?{|x| x.person_id.nil? || x.person_id == ""}.should be false end end @@ -172,9 +184,10 @@ describe Diaspora::Importer do # Generate exported XML for user1 exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) @xml = exporter.execute(@user1) - + @username =@user1.username # Remove user1 from the server @user1.aspects.each( &:delete ) + @user1.friends.each( &:delete ) @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).each( &:delete ) @user1.delete @@ -182,12 +195,15 @@ describe Diaspora::Importer do end it 'should import' do - pending "there is some weirdness with diaspora handle we need to look into... and this test is terrible" + pending "there is some weirdness with diaspora handle we need to look into... and this test needs love + the test passes when the validations are set to false when saving the user in the importer" + User.delete_all Person.delete_all Post.delete_all StatusMessage.delete_all Aspect.delete_all + Contact.delete_all User.count.should == 0 Person.count.should == 0 @@ -196,15 +212,18 @@ describe Diaspora::Importer do :email => "bob@bob.com", :password => "bobbybob", :password => "bobbybob", - :diaspora_handle => "bob@diaspora.com") + :diaspora_handle => "#{@username}@#{APP_CONFIG[:terse_pod_url]}") User.count.should == 1 n = User.first Post.count.should == 4 n.aspects.count.should == 6 Person.count.should be == 5 + Contact.count.should be == 4 - User.first.person.diaspora_handle.should == User.first.diaspora_handle + # need to check this + #User.first.person.diaspora_handle.should == User.first.diaspora_handle + User.first.diaspora_handle.should == "#{@username}@#{APP_CONFIG[:terse_pod_url]}" Person.find_by_id( @user1.person.id ).nil?.should == false @@ -223,12 +242,7 @@ describe Diaspora::Importer do n.friends.count.should be 4 end - - - end - end - end diff --git a/spec/lib/verify_spec.rb b/spec/lib/verify_spec.rb index b0b8a0de6..03df9d026 100644 --- a/spec/lib/verify_spec.rb +++ b/spec/lib/verify_spec.rb @@ -51,6 +51,23 @@ describe Diaspora::Importer do end end + describe 'verify contacts' do + let(:contact1) {Contact.new(:user => user1, :person => user2.person, :aspects => [aspect1])} + let(:contact2) {Contact.new(:user => user1, :person => user3.person, :aspects => [aspect2])} + let(:contact3) {Contact.new(:user => user1, :person => user3.person, :aspects => [aspect3])} + let(:less_contacts) {[contact1]} + let(:same_contacts) {[contact1, contact2]} + let(:more_contacts) {[contact1, contact2, contact3]} + + let(:person_ids) {[user2.person.id, user3.person.id]} + + + it 'should be false if the number of the number of contacts is not equal to the number of imported people' do + importer.verify_contacts(less_contacts, person_ids).should be false + importer.verify_contacts(same_contacts, person_ids).should be true + importer.verify_contacts(more_contacts, person_ids).should be false + end + end describe '#filter_posts' do it 'should make sure all found posts are owned by the user' do From c0c8c6253c456efaaa8bfde94b9e8fa00d4a4c14 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 15:13:16 -0700 Subject: [PATCH 08/28] added a logging line for debugging --- config/deploy_config.yml | 2 +- lib/diaspora/user/receiving.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/deploy_config.yml b/config/deploy_config.yml index 06a6747e1..c787e9257 100644 --- a/config/deploy_config.yml +++ b/config/deploy_config.yml @@ -6,7 +6,7 @@ cross_server: deploy_to: '/usr/local/app/diaspora' user: 'root' repo: 'git://github.com/diaspora/diaspora.git' - branch: 'master' + branch: 'contact-refactor' default_env: 'development' servers: tom: diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index 985346703..bcf8897f1 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -69,6 +69,7 @@ module Diaspora request.person = person request.person.save old_request = Request.first(:id => request.id) + Rails.logger.info("I got a reqest_id #{request.id} with old request #{old_request.inspect}") request.aspect_id = old_request.aspect_id if old_request request.save receive_friend_request(request) From acdbbe4dfcd34141f0a7ad6640738124fd049c3c Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 15:34:02 -0700 Subject: [PATCH 09/28] no mail for debugging for now --- lib/diaspora/user/friending.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 653097042..ba76f4bde 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -71,14 +71,14 @@ module Diaspora Rails.logger.info("#{self.real_name}'s friend request has been accepted") friend_request.destroy - Notifier.request_accepted(self, friend_request.person, aspect).deliver + #Notifier.request_accepted(self, friend_request.person, aspect).deliver #this is a new friend request else self.pending_requests << friend_request self.save Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save - Notifier.new_request(self, friend_request.person).deliver + #Notifier.new_request(self, friend_request.person).deliver end end From fa484e95e450c3d33b659e7a8221cf3b36a322eb Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 17:05:38 -0700 Subject: [PATCH 10/28] MS IZ refactored querying --- app/controllers/application_controller.rb | 2 +- app/controllers/aspects_controller.rb | 2 +- app/models/aspect.rb | 5 +++ app/models/contact.rb | 1 + app/models/user.rb | 7 ++-- lib/diaspora/user/querying.rb | 14 +++++++- spec/controllers/aspects_controller_spec.rb | 2 +- ...visible_posts_spec.rb => querying_spec.rb} | 36 ++++++++++++++++--- 8 files changed, 58 insertions(+), 11 deletions(-) rename spec/models/user/{visible_posts_spec.rb => querying_spec.rb} (79%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5b15d3ae2..42abc665c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -30,7 +30,7 @@ class ApplicationController < ActionController::Base @aspects = current_user.aspects @aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]} - @friends = current_user.friends.map{|c| c.person} + @friends = current_user.person_objects end end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 1d6038b42..47e04e62d 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -47,7 +47,7 @@ class AspectsController < ApplicationController unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else - @friends = @aspect.people.map{|c| c.person} + @friends = @aspect.person_objects @posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC' respond_with @aspect end diff --git a/app/models/aspect.rb b/app/models/aspect.rb index 782e9ea7c..56210f0db 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -30,6 +30,11 @@ class Aspect posts.detect{|x| x.person.id == id } end + def person_objects + person_ids = people.map{|x| x.person_id} + Person.all(:id.in => person_ids) + end + def as_json(opts = {}) { :aspect => { diff --git a/app/models/contact.rb b/app/models/contact.rb index b11b591cb..9ae223579 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -15,4 +15,5 @@ class Contact key :aspect_ids, Array, :typecast => 'ObjectId' many :aspects, :in => :aspect_ids, :class_name => 'Aspect' validates_presence_of :aspects + end diff --git a/app/models/user.rb b/app/models/user.rb index f71d7e2ca..82d103034 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -236,7 +236,7 @@ class User push_to_hub(post) if post.respond_to?(:public) && post.public - push_to_people(post, target_contacts.map{|c|c.person}) + push_to_people(post, self.person_objects(target_contacts)) end def push_to_people(post, people) @@ -289,7 +289,8 @@ class User if owns? comment.post comment.post_creator_signature = comment.sign_with_key(encryption_key) comment.save - push_to_people comment, contacts_in_aspects(aspects_with_post(comment.post.id)).map{|c|c.person} + aspects = aspects_with_post(comment.post_id) + push_to_people(comment, people_in_aspects(aspects)) elsif owns? comment comment.save push_to_people comment, [comment.post.person] @@ -303,7 +304,7 @@ class User post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) - push_to_people retraction, contacts_in_aspects(aspects_with_post(post.id)).map{|c| c.person} + push_to_people retraction, people_in_aspects(aspects_with_post(post.id)) retraction end diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index f0097a172..157470d03 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -33,7 +33,18 @@ module Diaspora end def friends_not_in_aspect( aspect ) - Contact.all(:user_id => self.id, :aspect_ids.ne => aspect._id).map{|c| c.person} + person_ids = Contact.all(:user_id => self.id, :aspect_ids.ne => aspect._id).collect{|x| x.person_id } + Person.all(:id.in => person_ids) + end + + def person_objects(contacts = self.friends) + person_ids = contacts.collect{|x| x.person_id} + Person.all(:id.in => person_ids) + end + + def people_in_aspects(aspects) + person_ids = contacts_in_aspects(aspects).collect{|x| x.person_id} + Person.all(:id.in => person_ids) end def aspect_by_id( id ) @@ -45,6 +56,7 @@ module Diaspora self.aspects.find_all_by_post_ids( id.to_id ) end + def aspects_with_person person contact_for(person).aspects end diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index e1695eb3f..b762a49ba 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -22,7 +22,7 @@ describe AspectsController do it "assigns @friends to all the user's friends" do Factory.create :person get :index - assigns[:friends].should == @user.friends.map{|c| c.person} + assigns[:friends].should == @user.person_objects end end diff --git a/spec/models/user/visible_posts_spec.rb b/spec/models/user/querying_spec.rb similarity index 79% rename from spec/models/user/visible_posts_spec.rb rename to spec/models/user/querying_spec.rb index 77490681a..ad18eb89d 100644 --- a/spec/models/user/visible_posts_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -61,19 +61,47 @@ describe User do let!(:user) {Factory :user} let!(:first_aspect) {user.aspect(:name => 'bruisers')} let!(:second_aspect) {user.aspect(:name => 'losers')} + let!(:user4) { Factory.create(:user_with_aspect)} + + before do + friend_users(user, first_aspect, user4, user4.aspects.first) + friend_users(user, second_aspect, user2, user2.aspects.first) + end 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 '#person_objects' do + it 'returns "person" objects for all of my friends' do + people = user.person_objects + people.size.should == 2 + [user4.person, user2.person].each{ |p| people.should include p } + end + + it 'should return people objects given a collection of contacts' do + target_contacts = [user.contact_for(user2.person)] + people = user.person_objects(target_contacts) + people.should == [user2.person] + end + + end + + describe '#people_in_aspects' do + it 'should return people objects for a users friend in each aspect' do + people = user.people_in_aspects([first_aspect]) + people.should == [user4.person] + people = user.people_in_aspects([second_aspect]) + people.should == [user2.person] + end + end end + + + describe '#albums_by_aspect' do let!(:first_aspect) {user2.aspect(:name => 'bruisers')} let!(:second_aspect) {user2.aspect(:name => 'losers')} From 0b2e00b7d6d6dd87a590100e3e19541f180b8fa1 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 17:46:19 -0700 Subject: [PATCH 11/28] MS IZ the mailer will not be setup unless turned on in the APP_CONFIG --- config/app_config.yml.example | 1 + config/environments/development.rb | 2 +- config/environments/production.rb | 12 ------------ config/initializers/mailer_config.rb | 2 +- lib/diaspora/user/friending.rb | 4 ++-- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 00dcb0b5f..a52ca2165 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -13,6 +13,7 @@ default: pubsub_server: 'https://pubsubhubbub.appspot.com/' mongo_host: 'localhost' mongo_port: 27017 + mailer_on: false smtp_address: 'smtp.example.com' smtp_port: '587' smtp_domain: 'mail.example.com' diff --git a/config/environments/development.rb b/config/environments/development.rb index 80022947e..74a062ea5 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -20,7 +20,7 @@ Diaspora::Application.configure do config.action_controller.perform_caching = false # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = true + config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :log config.middleware.use MongoMapper::ClearDevMemory #config.threadsafe! diff --git a/config/environments/production.rb b/config/environments/production.rb index eebcc420b..8c65da341 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,16 +47,4 @@ Diaspora::Application.configure do # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true config.threadsafe! - - config.action_mailer.delivery_method = :smtp - config.action_mailer.default_url_options = {:host => 'pivots.joindiaspora.com'} - config.action_mailer.smtp_settings = { - :address => 'smtp.gmail.com', - :port => 587, - :domain => 'mail.joindiaspora.com', - :authentication => 'plain', - :user_name => 'diaspora-pivots@joindiaspora.com', - :password => "xy289|]G+R*-kA", - :enable_starttls_auto => true - } end diff --git a/config/initializers/mailer_config.rb b/config/initializers/mailer_config.rb index cbc5f7330..b334cdb42 100644 --- a/config/initializers/mailer_config.rb +++ b/config/initializers/mailer_config.rb @@ -4,7 +4,7 @@ Diaspora::Application.configure do config.action_mailer.default_url_options = {:host => APP_CONFIG[:terse_pod_url]} - unless Rails.env == 'test' + unless Rails.env == 'test' || APP_CONFIG[:mailer_on] != true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => APP_CONFIG[:smtp_address], diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index ba76f4bde..653097042 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -71,14 +71,14 @@ module Diaspora Rails.logger.info("#{self.real_name}'s friend request has been accepted") friend_request.destroy - #Notifier.request_accepted(self, friend_request.person, aspect).deliver + Notifier.request_accepted(self, friend_request.person, aspect).deliver #this is a new friend request else self.pending_requests << friend_request self.save Rails.logger.info("#{self.real_name} has received a friend request") friend_request.save - #Notifier.new_request(self, friend_request.person).deliver + Notifier.new_request(self, friend_request.person).deliver end end From 8b16dd25e7d8f429f8ea591846ca30b4d712b21e Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 18:16:10 -0700 Subject: [PATCH 12/28] trying better logging --- lib/message_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 0d201a994..7a3a6970a 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -42,7 +42,7 @@ class MessageHandler http.errback { Rails.logger.info(http.response) - Rails.logger.info("Failure from #{query.destination}, retrying...") + Rails.logger.info("Failure from #{query.destination}, with #{http.inspect},retrying...") query.try_count +=1 @queue.push query unless query.try_count >= NUM_TRIES From d61ec0186fe7117326db3ab0076005d1dcf10328 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 18:21:47 -0700 Subject: [PATCH 13/28] debugging, trying increasing the timeout --- lib/message_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 7a3a6970a..0144b9815 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -5,7 +5,7 @@ class MessageHandler NUM_TRIES = 3 - TIMEOUT = 5 #seconds + TIMEOUT = 10 #seconds def initialize @queue = EM::Queue.new From 708927cc6d10ed3cb6c17f92a50eaa7e8ad0bdbe Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 18:31:06 -0700 Subject: [PATCH 14/28] more debugging on remote, back to 5 sec timeout --- lib/message_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 0144b9815..7a3a6970a 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -5,7 +5,7 @@ class MessageHandler NUM_TRIES = 3 - TIMEOUT = 10 #seconds + TIMEOUT = 5 #seconds def initialize @queue = EM::Queue.new From c4b79aebc0bd43eba8a965c2b0345cb7785fa9ba Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 18:42:53 -0700 Subject: [PATCH 15/28] mongo query profing --- config/initializers/_mongo.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/initializers/_mongo.rb b/config/initializers/_mongo.rb index 3f51d8765..339834ed0 100644 --- a/config/initializers/_mongo.rb +++ b/config/initializers/_mongo.rb @@ -14,3 +14,4 @@ if defined?(PhusionPassenger) end Magent.connection = MongoMapper.connection +MongoMapper.database.profiling_level = :all From f314ab39dfc537dcf2eef5029e5cdcc6f8f90320 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 26 Oct 2010 19:05:18 -0700 Subject: [PATCH 16/28] At some point, we should upgrade database_cleaner to 0.6.0. That point is not now. (It breaks cucumber.) --- Gemfile | 2 +- Gemfile.lock | 75 +++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index cd11c7ceb..ddff8fa21 100644 --- a/Gemfile +++ b/Gemfile @@ -58,7 +58,7 @@ group :test do gem 'rspec', '>= 2.0.0' gem 'rspec-rails', '>= 2.0.0' gem 'mocha' - gem 'database_cleaner' + gem 'database_cleaner', '0.5.2' gem 'webmock' end diff --git a/Gemfile.lock b/Gemfile.lock index 1abff88d1..dc26a8bf9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GIT remote: git://github.com/Empact/roxml.git - revision: 33034d3e632b3a14565a791af0a63c7e23ec0de4 + revision: d411519add92e0cd5a985253f376d25c26884324 specs: - roxml (3.1.5) + roxml (3.1.6) activesupport (>= 2.3.0) nokogiri (>= 1.3.3) @@ -141,10 +141,10 @@ GEM columnize (0.3.1) configuration (1.1.0) crack (0.1.8) - cucumber (0.9.2) + cucumber (0.9.3) builder (~> 2.1.2) diff-lcs (~> 1.1.2) - gherkin (~> 2.2.5) + gherkin (~> 2.2.9) json (~> 1.4.6) term-ansicolor (~> 1.0.5) cucumber-rails (0.3.2) @@ -169,9 +169,10 @@ GEM factory_girl_rails (1.0) factory_girl (~> 1.3) rails (>= 3.0.0.beta4) - faraday (0.4.6) - addressable (>= 2.1.1) - rack (>= 1.0.1) + faraday (0.5.1) + addressable (~> 2.2.2) + multipart-post (~> 1.0.1) + rack (~> 1.2.1) ffi (0.6.3) rake (>= 0.8.7) gherkin (2.2.9) @@ -183,17 +184,18 @@ GEM http_connection (1.4.0) httparty (0.6.1) crack (= 0.1.8) - i18n (0.4.1) + i18n (0.4.2) json (1.4.6) json_pure (1.4.6) launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) linecache (0.43) - mail (2.2.7) + mail (2.2.9) activesupport (>= 2.3.6) - mime-types - treetop (>= 1.4.5) + i18n (~> 0.4.1) + mime-types (~> 1.16) + treetop (~> 1.4.8) mime-types (1.16) mini_fb (1.1.3) hashie @@ -205,12 +207,13 @@ GEM mixlib-cli (1.2.0) mixlib-config (1.1.2) mixlib-log (1.2.0) - mocha (0.9.8) + mocha (0.9.9) rake moneta (0.6.0) mongo (1.1) bson (>= 1.0.5) multi_json (0.0.4) + multipart-post (1.0.1) net-ldap (0.1.1) net-scp (1.0.4) net-ssh (>= 1.99.1) @@ -220,33 +223,33 @@ GEM net-ssh-gateway (1.0.1) net-ssh (>= 1.99.1) nokogiri (1.4.3.1) - oa-basic (0.1.5) + oa-basic (0.1.6) multi_json (~> 0.0.2) nokogiri (~> 1.4.2) - oa-core (= 0.1.5) + oa-core (= 0.1.6) rest-client (~> 1.6.0) - oa-core (0.1.5) + oa-core (0.1.6) rack (~> 1.1) - oa-enterprise (0.1.5) + oa-enterprise (0.1.6) net-ldap (~> 0.1.1) nokogiri (~> 1.4.2) - oa-core (= 0.1.5) + oa-core (= 0.1.6) pyu-ruby-sasl (~> 0.0.3.1) rubyntlm (~> 0.1.1) - oa-oauth (0.1.5) + oa-oauth (0.1.6) multi_json (~> 0.0.2) nokogiri (~> 1.4.2) - oa-core (= 0.1.5) + oa-core (= 0.1.6) oauth (~> 0.4.0) - oauth2 (~> 0.0.10) - oa-openid (0.1.5) - oa-core (= 0.1.5) - rack-openid (~> 1.1.1) + oauth2 (~> 0.1.0) + oa-openid (0.1.6) + oa-core (= 0.1.6) + rack-openid (~> 1.2.0) ruby-openid-apps-discovery oauth (0.4.3) - oauth2 (0.0.13) - faraday (~> 0.4.1) - multi_json (>= 0.0.4) + oauth2 (0.1.0) + faraday (~> 0.5.0) + multi_json (~> 0.0.4) ohai (0.5.8) extlib json (>= 1.4.4, <= 1.4.6) @@ -254,12 +257,12 @@ GEM mixlib-config mixlib-log systemu - omniauth (0.1.5) - oa-basic (= 0.1.5) - oa-core (= 0.1.5) - oa-enterprise (= 0.1.5) - oa-oauth (= 0.1.5) - oa-openid (= 0.1.5) + omniauth (0.1.6) + oa-basic (= 0.1.6) + oa-core (= 0.1.6) + oa-enterprise (= 0.1.6) + oa-oauth (= 0.1.6) + oa-openid (= 0.1.6) plucky (0.3.6) mongo (~> 1.1) polyglot (0.3.1) @@ -270,9 +273,9 @@ GEM rack (1.2.1) rack-mount (0.6.13) rack (>= 1.0.0) - rack-openid (1.1.2) - rack (>= 0.4) - ruby-openid (>= 2.0.3) + rack-openid (1.2.0) + rack (>= 1.1.0) + ruby-openid (>= 2.1.8) rack-test (0.5.6) rack (>= 1.0) rails (3.0.1) @@ -356,7 +359,7 @@ DEPENDENCIES carrierwave! chef cucumber-rails (= 0.3.2) - database_cleaner + database_cleaner (= 0.5.2) devise (= 1.1.3) devise-mongo_mapper! devise_invitable (~> 0.3.4) From 49c09b9c8c7f7f6f438749bcd39cdfeedf623baf Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 26 Oct 2010 17:04:44 -0700 Subject: [PATCH 17/28] Remove unused clean_hash --- app/controllers/aspects_controller.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 985fb68a9..f92c9426b 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -97,11 +97,4 @@ class AspectsController < ApplicationController end redirect_to aspects_manage_path end - - private - def clean_hash(params) - return { - :name => params[:name] - } - end end From aa819d21135f55d89a073283de4be5cda0bd59f1 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 26 Oct 2010 19:15:41 -0700 Subject: [PATCH 18/28] Putting an index on Person#diaspora_handle --- app/models/person.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/person.rb b/app/models/person.rb index 5a1486653..58e637557 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -40,6 +40,8 @@ class Person validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix + ensure_index :diaspora_handle + def self.search(query) return Person.all if query.to_s.empty? query_tokens = query.to_s.strip.split(" ") From 21c75c08bb3a42c0ff1132bccc9179531777ae93 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 19:19:34 -0700 Subject: [PATCH 19/28] removed the http inspect --- config/initializers/_mongo.rb | 1 - lib/message_handler.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config/initializers/_mongo.rb b/config/initializers/_mongo.rb index 339834ed0..3f51d8765 100644 --- a/config/initializers/_mongo.rb +++ b/config/initializers/_mongo.rb @@ -14,4 +14,3 @@ if defined?(PhusionPassenger) end Magent.connection = MongoMapper.connection -MongoMapper.database.profiling_level = :all diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 7a3a6970a..0d201a994 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -42,7 +42,7 @@ class MessageHandler http.errback { Rails.logger.info(http.response) - Rails.logger.info("Failure from #{query.destination}, with #{http.inspect},retrying...") + Rails.logger.info("Failure from #{query.destination}, retrying...") query.try_count +=1 @queue.push query unless query.try_count >= NUM_TRIES From 039bf374d889b4ad8260398ce8b400eb487ca9b4 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 23:38:12 -0700 Subject: [PATCH 20/28] soft shadow on header --- public/stylesheets/sass/application.sass | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 739a0ffac..3c468e659 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -105,8 +105,12 @@ header :margin -2em :bottom 2em :color #000 + :background :color #333 + :background -webkit-gradient( linear, left bottom, left top, color-stop(0.01, rgb(31,31,31)), color-stop(0.12, rgb(51,51,51))) + :background -moz-linear-gradient( center bottom, rgb(31,31,31) 1%, rgb(51,51,51) 12%) + :padding 0 :top 5px :color #CCC @@ -873,7 +877,7 @@ h1.big_text :font :weight bold :background - :color rgba(252,252,252,1) + :color rgb(252,252,252) :color #444 &:hover From 0c8de9460c4bd067d127a05028777094968a710a Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Wed, 27 Oct 2010 03:21:17 -0700 Subject: [PATCH 21/28] Fix for 1.9 (no spaces between method name and parens) --- spec/models/user/user_friending_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 8a4386601..34975885a 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -67,7 +67,7 @@ describe Diaspora::UserModules::Friending do end it 'should be able to ignore a pending friend request' do - proc { user.ignore_friend_request(request_for_user.id) }.should change ( + proc { user.ignore_friend_request(request_for_user.id) }.should change( user.reload.pending_requests, :count ).by(-1) end end From 634538eff310edb8496cf1566c5ef65c1239d6c4 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Wed, 27 Oct 2010 10:13:04 -0700 Subject: [PATCH 22/28] IZ MS change back deploy config --- config/deploy_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy_config.yml b/config/deploy_config.yml index c787e9257..06a6747e1 100644 --- a/config/deploy_config.yml +++ b/config/deploy_config.yml @@ -6,7 +6,7 @@ cross_server: deploy_to: '/usr/local/app/diaspora' user: 'root' repo: 'git://github.com/diaspora/diaspora.git' - branch: 'contact-refactor' + branch: 'master' default_env: 'development' servers: tom: From 4a09eb2ece79551c06cba77fc9e3299657d06cf8 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Wed, 27 Oct 2010 10:14:24 -0700 Subject: [PATCH 23/28] IZ MS update pending aspects controller spec --- spec/controllers/aspects_controller_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index b762a49ba..7635bbfc1 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -54,7 +54,8 @@ describe AspectsController do 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" + pending "need to figure out what is the deal with remote requests" + @controller.stub!(:current_user).and_return(@user) @user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id") post :move_friend, opts end From f700eb537a2e0790fa8bfb2e5a3d5b9414e5008b Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 27 Oct 2010 10:27:10 -0700 Subject: [PATCH 24/28] Add activemodel error message for person to en and fr locales --- config/locales/diaspora/en.yml | 4 ++++ config/locales/diaspora/fr.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 91b80deab..33c3d62bd 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -15,6 +15,10 @@ en: taken: "is already taken" email: taken: "is already taken" + person: + attributes: + diaspora_handle: + taken: "is already taken" hello: "Hello world" application: helper: diff --git a/config/locales/diaspora/fr.yml b/config/locales/diaspora/fr.yml index baf9d1b82..2cf05237a 100644 --- a/config/locales/diaspora/fr.yml +++ b/config/locales/diaspora/fr.yml @@ -15,6 +15,10 @@ fr: taken: "est déjà pris" email: taken: "est déjà pris" + person: + attributes: + diaspora_handle: + taken: "est déjà pris" hello: "Bonjour tout le monde" application: helper: From a5099bb89f69ad4bbbdde7380a2834bacedfd9af Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Wed, 27 Oct 2010 10:32:09 -0700 Subject: [PATCH 25/28] IZ moved methods found in spec helper to helper methods file. now we can include them in the db scripts to keep friending behavior in sync --- db/seeds/dev.rb | 13 ++++--- db/seeds/tom.rb | 11 +++--- spec/helper_methods.rb | 85 ++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 85 +----------------------------------------- 4 files changed, 101 insertions(+), 93 deletions(-) create mode 100644 spec/helper_methods.rb diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index 324cf47bd..8fc7c499b 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -3,6 +3,8 @@ # the COPYRIGHT file. require File.join(File.dirname(__FILE__), "..", "..", "config", "environment") +require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods") + def set_app_config username current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example'))) @@ -18,7 +20,7 @@ username = "tom" set_app_config username unless File.exists?(Rails.root.join('config', 'app_config.yml')) require Rails.root.join('config', "initializers", "_load_app_config.rb") - +include HelperMethods # Create seed user user = User.build( :email => "tom@tom.joindiaspora.com", :username => "tom", @@ -44,7 +46,8 @@ user2.save user2.person.save! user2.seed_aspects # friending users -aspect = user.aspect(:name => "other dudes") -request = user.send_friend_request_to(user2, aspect) -reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id ) -user.receive reversed_request.to_diaspora_xml, user2.person +aspect = user.aspect(:name => "other dudes") +aspect2 = user2.aspect(:name => "presidents") + +friend_users(user, aspect, user2, aspect2) +user.aspect(:name => "Presidents") diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index fe45e2dd0..28f043728 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. require File.join(File.dirname(__FILE__), "..", "..", "config", "environment") +require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods") def set_app_config username current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example'))) @@ -17,6 +18,7 @@ end set_app_config "tom" unless File.exists?(Rails.root.join('config', 'app_config.yml')) require 'config/initializers/_load_app_config.rb' +include HelperMethods # Create seed user user = User.build( :email => "tom@tom.joindiaspora.com", @@ -40,9 +42,8 @@ user2.save! user2.seed_aspects user2.person.save! # friending users -aspect = user.aspect(:name => "other dudes") -request = user.send_friend_request_to(user2, aspect) -reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id ) -user.receive reversed_request.to_diaspora_xml, user2.person -user.aspect(:name => "Presidents") +aspect = user.aspect(:name => "other dudes") +aspect2 = user2.aspect(:name => "presidents") +friend_users(user, aspect, user2, aspect2) +user.aspect(:name => "Presidents") diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb new file mode 100644 index 000000000..cc8689924 --- /dev/null +++ b/spec/helper_methods.rb @@ -0,0 +1,85 @@ +module HelperMethods + def stub_sockets + Diaspora::WebSocket.stub!(:queue_to_user).and_return(true) + Diaspora::WebSocket.stub!(:subscribe).and_return(true) + Diaspora::WebSocket.stub!(:unsubscribe).and_return(true) + end + + def unstub_sockets + Diaspora::WebSocket.unstub!(:queue_to_user) + Diaspora::WebSocket.unstub!(:subscribe) + Diaspora::WebSocket.unstub!(:unsubscribe) + end + + def stub_comment_signature_verification + Comment.any_instance.stubs(:verify_signature).returns(true) + end + + def unstub_mocha_stubs + Mocha::Mockery.instance.stubba.unstub_all + end + + def get_models + models = [] + Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f| + models << File.basename( f ).gsub( /^(.+).rb/, '\1') + end + models + end + + def message_queue + User::QUEUE + end + + def friend_users(user1, aspect1, user2, aspect2) + request = user1.send_friend_request_to(user2.person, aspect1) + user2.receive_friend_request(request) + reversed_request = user2.accept_friend_request( request.id, aspect2.id) + user1.reload + user1.receive reversed_request.to_diaspora_xml, user2.person + user1.reload + aspect1.reload + user2.reload + aspect2.reload + end + + def stub_success(address = 'abc@example.com', opts = {}) + host = address.split('@')[1] + stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + if opts[:diaspora] || host.include?("diaspora") + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) + stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response) + else + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => nonseed_finger_xrd) + stub_request(:get, 'http://evan.status.net/hcard').to_return(:status => 200, :body => evan_hcard) + end + end + + def stub_failure(address = 'abc@example.com') + host = address.split('@')[1] + stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) + stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 500) + end + + def host_xrd + File.open(File.dirname(__FILE__) + '/fixtures/host_xrd').read + end + + def finger_xrd + File.open(File.dirname(__FILE__) + '/fixtures/finger_xrd').read + end + + def hcard_response + File.open(File.dirname(__FILE__) + '/fixtures/hcard_response').read + end + + def nonseed_finger_xrd + File.open(File.dirname(__FILE__) + '/fixtures/nonseed_finger_xrd').read + end + + def evan_hcard + File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 11f18d8d2..3b9392629 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,12 +7,14 @@ ENV["RAILS_ENV"] ||= 'test' require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) +require 'helper_methods' require 'rspec/rails' require 'database_cleaner' require 'webmock/rspec' include Devise::TestHelpers include WebMock::API +include HelperMethods # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. @@ -33,86 +35,3 @@ end ImageUploader.enable_processing = false - def stub_sockets - Diaspora::WebSocket.stub!(:queue_to_user).and_return(true) - Diaspora::WebSocket.stub!(:subscribe).and_return(true) - Diaspora::WebSocket.stub!(:unsubscribe).and_return(true) - end - - def unstub_sockets - Diaspora::WebSocket.unstub!(:queue_to_user) - Diaspora::WebSocket.unstub!(:subscribe) - Diaspora::WebSocket.unstub!(:unsubscribe) - end - - def stub_comment_signature_verification - Comment.any_instance.stubs(:verify_signature).returns(true) - end - - def unstub_mocha_stubs - Mocha::Mockery.instance.stubba.unstub_all - end - - def get_models - models = [] - Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f| - models << File.basename( f ).gsub( /^(.+).rb/, '\1') - end - models - end - - def message_queue - User::QUEUE - end - - def friend_users(user1, aspect1, user2, aspect2) - request = user1.send_friend_request_to(user2.person, aspect1) - user2.receive_friend_request(request) - reversed_request = user2.accept_friend_request( request.id, aspect2.id) - user1.reload - user1.receive reversed_request.to_diaspora_xml, user2.person - user1.reload - aspect1.reload - user2.reload - aspect2.reload - end - - def stub_success(address = 'abc@example.com', opts = {}) - host = address.split('@')[1] - stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) - stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) - if opts[:diaspora] || host.include?("diaspora") - stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd) - stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response) - else - stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => nonseed_finger_xrd) - stub_request(:get, 'http://evan.status.net/hcard').to_return(:status => 200, :body => evan_hcard) - end - end - - def stub_failure(address = 'abc@example.com') - host = address.split('@')[1] - stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) - stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd) - stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 500) - end - - def host_xrd - File.open(File.dirname(__FILE__) + '/fixtures/host_xrd').read - end - - def finger_xrd - File.open(File.dirname(__FILE__) + '/fixtures/finger_xrd').read - end - - def hcard_response - File.open(File.dirname(__FILE__) + '/fixtures/hcard_response').read - end - - def nonseed_finger_xrd - File.open(File.dirname(__FILE__) + '/fixtures/nonseed_finger_xrd').read - end - - def evan_hcard - File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read - end From 6c94d40bd4c8d86953ac5533d844ecd3b0ae581e Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 27 Oct 2010 11:03:57 -0700 Subject: [PATCH 26/28] Factory.build saves users --- spec/misc_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index fcad1a5e3..61b64d25b 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -11,6 +11,15 @@ describe 'making sure the spec runner works' do loaded_user.person.owner_id.should == user.id end + describe 'factories' do + describe 'build' do + it 'does not save a built user' do + pending "This problem is bizarre and needs fixing" + Factory.build(:user).persisted?.should be_false + end + end + end + describe '#friend_users' do before do @user1 = Factory.create(:user) From aa0adf47cf2d91caac6b518f977f1d1f786f628d Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Wed, 27 Oct 2010 13:15:25 -0700 Subject: [PATCH 27/28] Split ci.sh into separate versions for 1.8.7 and 1.9.2 --- ci-19.sh | 11 +++++++++++ ci.sh | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 ci-19.sh diff --git a/ci-19.sh b/ci-19.sh new file mode 100644 index 000000000..0256d3cad --- /dev/null +++ b/ci-19.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "*************************************************************************************************" && +echo "* ruby 1.9.2-p0 build *" && +echo "*************************************************************************************************" && +echo "" && +rm -f Gemfile.lock && +source /usr/local/rvm/scripts/rvm && +rvm use ruby-1.9.2-p0@diaspora && +bundle install && +bundle exec rake cruise \ No newline at end of file diff --git a/ci.sh b/ci.sh index e24ba0ec0..4468c5944 100755 --- a/ci.sh +++ b/ci.sh @@ -9,14 +9,3 @@ source /usr/local/rvm/scripts/rvm && rvm use ruby-1.8.7-p249@diaspora && bundle install && bundle exec rake cruise -# bundle exec rake cruise && -# echo "" && -# echo "*************************************************************************************************" && -# echo "* ruby 1.9.2-p0 build *" && -# echo "*************************************************************************************************" && -# echo "" && -# rm -f Gemfile.lock && -# source /usr/local/rvm/scripts/rvm && -# rvm use ruby-1.9.2-p0@diaspora && -# bundle install && -# bundle exec rake cruise From 314b5d1ef46ec733272dd95a58409a62a0080c1d Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Wed, 27 Oct 2010 14:34:57 -0700 Subject: [PATCH 28/28] ci-19.sh has proper execute perms --- ci-19.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ci-19.sh diff --git a/ci-19.sh b/ci-19.sh old mode 100644 new mode 100755