diff --git a/app/models/user.rb b/app/models/user.rb index b6be53b8a079ad6f17d2254aa595bde7500eebe7..746db1bda6057c1b75fea2049b818db4597db735 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -345,7 +345,10 @@ class User < ActiveRecord::Base def seed_aspects 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 def self.generate_key diff --git a/lib/diaspora/user/connecting.rb b/lib/diaspora/user/connecting.rb index 668ab2709ac027b3973544c6395e2c7675b54085..3500d461d04540948d3040fd7e603c5b07d99936 100644 --- a/lib/diaspora/user/connecting.rb +++ b/lib/diaspora/user/connecting.rb @@ -22,10 +22,21 @@ module Diaspora if notification = Notification.where(:target_id => person.id).first notification.update_attributes(:unread=>false) end - + + register_post_visibilities(contact) contact 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}) posts = contact.posts.all diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 6bcb9d23c7226cc800c7aeadeab240d35ed37b01..8ac3bc76469a5347843ade004f5188ac7caf617c 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -12,6 +12,7 @@ describe InvitationsController do @aspect = @user.aspects.first request.env["devise.mapping"] = Devise.mappings[:user] + Webfinger.stub_chain(:new, :fetch).and_return(Factory(:person)) end describe "#create" do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index f6cc2deaeaab08038ffa5ddbbf419cf622ce3e44..6954f23c41f089d9674ad79817884d0644baed65 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -16,6 +16,7 @@ describe RegistrationsController do :password_confirmation => "password" } } + Webfinger.stub_chain(:new, :fetch).and_return(Factory(:person)) end describe '#check_registrations_open!' do diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 855c3db7289efc0f86711b806317097690149482..369fc8141129b337e6d9f7f6274af37650dbc574 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -76,6 +76,16 @@ describe Diaspora::UserModules::Connecting do 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 it 'finds or creates a contact' do lambda { @@ -104,6 +114,11 @@ describe Diaspora::UserModules::Connecting do }.should change(contact.aspects, :count).by(1) 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 it 'dispatches a request on initial request' do contact = alice.contacts.new(:person => eve.person) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6177a88dec05d805a3dbdac8fa265fd300a1c7f4..391eb9ee7b2caf9464ab4d395aca096acaa1c2f6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -171,6 +171,15 @@ describe User do 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 context 'with valid params' do before do