new users now autofollow diasporahq@joindiaspora.com; upon connecting to a user, you now get post visibilities for their public posts (that your pod knows about)

This commit is contained in:
Maxwell Salzberg 2011-07-29 17:20:10 -07:00
parent a320891df0
commit 73616a3e7a
6 changed files with 42 additions and 2 deletions

View file

@ -345,7 +345,10 @@ class User < ActiveRecord::Base
def seed_aspects def seed_aspects
self.aspects.create(:name => I18n.t('aspects.seed.family')) self.aspects.create(:name => I18n.t('aspects.seed.family'))
self.aspects.create(:name => I18n.t('aspects.seed.work')) work = self.aspects.create(:name => I18n.t('aspects.seed.work'))
default_account = Webfinger.new('diasporahq@joindiaspora.com').fetch
self.share_with(default_account, work)
work
end end
def self.generate_key def self.generate_key

View file

@ -22,10 +22,21 @@ module Diaspora
if notification = Notification.where(:target_id => person.id).first if notification = Notification.where(:target_id => person.id).first
notification.update_attributes(:unread=>false) notification.update_attributes(:unread=>false)
end end
register_post_visibilities(contact)
contact contact
end end
def register_post_visibilities(contact)
#should have select here, but proven hard to test
posts = Post.where(:author_id => contact.person_id, :public => true).limit(100)
posts.map! do |post|
PostVisibility.new(:contact_id => contact.id, :post_id => post.id)
end
PostVisibility.import(posts) unless posts.empty?
nil
end
def remove_contact(contact, opts={:force => false}) def remove_contact(contact, opts={:force => false})
posts = contact.posts.all posts = contact.posts.all

View file

@ -12,6 +12,7 @@ describe InvitationsController do
@aspect = @user.aspects.first @aspect = @user.aspects.first
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
Webfinger.stub_chain(:new, :fetch).and_return(Factory(:person))
end end
describe "#create" do describe "#create" do

View file

@ -16,6 +16,7 @@ describe RegistrationsController do
:password_confirmation => "password" :password_confirmation => "password"
} }
} }
Webfinger.stub_chain(:new, :fetch).and_return(Factory(:person))
end end
describe '#check_registrations_open!' do describe '#check_registrations_open!' do

View file

@ -76,6 +76,16 @@ describe Diaspora::UserModules::Connecting do
end end
end end
describe '#register_post_visibilities' do
it 'creates post visibilites for up to 100 posts' do
Post.stub_chain(:where, :limit).and_return([Factory(:status_message, :public => true)])
c = Contact.create!(:user_id => alice.id, :person_id => eve.person.id)
expect{
alice.register_post_visibilities(c)
}.to change(PostVisibility, :count).by(1)
end
end
describe '#share_with' do describe '#share_with' do
it 'finds or creates a contact' do it 'finds or creates a contact' do
lambda { lambda {
@ -104,6 +114,11 @@ describe Diaspora::UserModules::Connecting do
}.should change(contact.aspects, :count).by(1) }.should change(contact.aspects, :count).by(1)
end end
it 'calls #register_post_visibilities with a contact' do
eve.should_receive(:register_post_visibilities)
eve.share_with(alice.person, eve.aspects.first)
end
context 'dispatching' do context 'dispatching' do
it 'dispatches a request on initial request' do it 'dispatches a request on initial request' do
contact = alice.contacts.new(:person => eve.person) contact = alice.contacts.new(:person => eve.person)

View file

@ -171,6 +171,15 @@ describe User do
end end
end end
describe '#seed_aspects' do
it 'follows the default account' do
Webfinger.stub_chain(:new, :fetch).and_return(Factory(:person))
expect{
eve.seed_aspects
}.to change(eve.contacts, :count).by(1)
end
end
describe ".build" do describe ".build" do
context 'with valid params' do context 'with valid params' do
before do before do