From 7d7844a47fdfb8862847f025dc4c1b1bc5fdafe5 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 10 Sep 2017 09:58:38 +0200 Subject: Default follows for new users (#4871) When a new user confirms their e-mail, bootstrap their home timeline by automatically following a set of accounts. By default, all local admin accounts (that are unlocked). Can be customized by new admin setting (comma-separated usernames, local and unlocked only) --- .../auth/confirmations_controller_spec.rb | 18 +++++++++++ spec/services/bootstrap_timeline_service_spec.rb | 37 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 spec/services/bootstrap_timeline_service_spec.rb (limited to 'spec') diff --git a/spec/controllers/auth/confirmations_controller_spec.rb b/spec/controllers/auth/confirmations_controller_spec.rb index cf7f91e52..2ec36c060 100644 --- a/spec/controllers/auth/confirmations_controller_spec.rb +++ b/spec/controllers/auth/confirmations_controller_spec.rb @@ -10,4 +10,22 @@ describe Auth::ConfirmationsController, type: :controller do expect(response).to have_http_status(:success) end end + + describe 'GET #show' do + let!(:user) { Fabricate(:user, confirmation_token: 'foobar', confirmed_at: nil) } + + before do + allow(BootstrapTimelineWorker).to receive(:perform_async) + @request.env['devise.mapping'] = Devise.mappings[:user] + get :show, params: { confirmation_token: 'foobar' } + end + + it 'redirects to login' do + expect(response).to redirect_to(new_user_session_path) + end + + it 'queues up bootstrapping of home timeline' do + expect(BootstrapTimelineWorker).to have_received(:perform_async).with(user.account_id) + end + end end diff --git a/spec/services/bootstrap_timeline_service_spec.rb b/spec/services/bootstrap_timeline_service_spec.rb new file mode 100644 index 000000000..5189b1de8 --- /dev/null +++ b/spec/services/bootstrap_timeline_service_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +RSpec.describe BootstrapTimelineService do + subject { described_class.new } + + describe '#call' do + let(:source_account) { Fabricate(:account) } + + context 'when setting is empty' do + let!(:admin) { Fabricate(:user, admin: true) } + + before do + Setting.bootstrap_timeline_accounts = nil + subject.call(source_account) + end + + it 'follows admin accounts from account' do + expect(source_account.following?(admin.account)).to be true + end + end + + context 'when setting is set' do + let!(:alice) { Fabricate(:account, username: 'alice') } + let!(:bob) { Fabricate(:account, username: 'bob') } + + before do + Setting.bootstrap_timeline_accounts = 'alice, bob' + subject.call(source_account) + end + + it 'follows found accounts from account' do + expect(source_account.following?(alice)).to be true + expect(source_account.following?(bob)).to be true + end + end + end +end -- cgit From c450ddb6134602ecc2917c493240e55e8773520b Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 10 Sep 2017 15:09:06 +0200 Subject: Fix POST /api/v1/follows error when already following (#4878) --- app/controllers/api/v1/follows_controller.rb | 6 ++++++ spec/controllers/api/v1/follows_controller_spec.rb | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'spec') diff --git a/app/controllers/api/v1/follows_controller.rb b/app/controllers/api/v1/follows_controller.rb index e01ae5c01..5a2b2f32f 100644 --- a/app/controllers/api/v1/follows_controller.rb +++ b/app/controllers/api/v1/follows_controller.rb @@ -10,6 +10,12 @@ class Api::V1::FollowsController < Api::BaseController raise ActiveRecord::RecordNotFound if follow_params[:uri].blank? @account = FollowService.new.call(current_user.account, target_uri).try(:target_account) + + if @account.nil? + username, domain = target_uri.split('@') + @account = Account.find_remote!(username, domain) + end + render json: @account, serializer: REST::AccountSerializer end diff --git a/spec/controllers/api/v1/follows_controller_spec.rb b/spec/controllers/api/v1/follows_controller_spec.rb index b5e1d16dd..ea9e76d68 100644 --- a/spec/controllers/api/v1/follows_controller_spec.rb +++ b/spec/controllers/api/v1/follows_controller_spec.rb @@ -42,5 +42,10 @@ RSpec.describe Api::V1::FollowsController, type: :controller do it 'subscribes to remote hub' do expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made end + + it 'returns http success if already following, too' do + post :create, params: { uri: 'gargron@quitter.no' } + expect(response).to have_http_status(:success) + end end end -- cgit