Convert settings/privacy spec controller->system (#33894)
				
					
				
			This commit is contained in:
		@@ -1,74 +0,0 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe Settings::PrivacyController do
 | 
			
		||||
  render_views
 | 
			
		||||
 | 
			
		||||
  let!(:user) { Fabricate(:user) }
 | 
			
		||||
  let(:account) { user.account }
 | 
			
		||||
 | 
			
		||||
  before do
 | 
			
		||||
    sign_in user, scope: :user
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'GET #show' do
 | 
			
		||||
    before do
 | 
			
		||||
      get :show
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'returns http success with private cache control headers', :aggregate_failures do
 | 
			
		||||
      expect(response)
 | 
			
		||||
        .to have_http_status(200)
 | 
			
		||||
        .and have_attributes(
 | 
			
		||||
          headers: include(
 | 
			
		||||
            'Cache-Control' => 'private, no-store'
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'PUT #update' do
 | 
			
		||||
    context 'when update succeeds' do
 | 
			
		||||
      before do
 | 
			
		||||
        allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'updates the user profile' do
 | 
			
		||||
        put :update, params: { account: { discoverable: '1', settings: { indexable: '1' } } }
 | 
			
		||||
 | 
			
		||||
        expect(account.reload.discoverable)
 | 
			
		||||
          .to be(true)
 | 
			
		||||
 | 
			
		||||
        expect(response)
 | 
			
		||||
          .to redirect_to(settings_privacy_path)
 | 
			
		||||
 | 
			
		||||
        expect(ActivityPub::UpdateDistributionWorker)
 | 
			
		||||
          .to have_received(:perform_async).with(account.id)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when update fails' do
 | 
			
		||||
      before do
 | 
			
		||||
        allow(UpdateAccountService).to receive(:new).and_return(failing_update_service)
 | 
			
		||||
        allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'updates the user profile' do
 | 
			
		||||
        put :update, params: { account: { discoverable: '1', settings: { indexable: '1' } } }
 | 
			
		||||
 | 
			
		||||
        expect(response)
 | 
			
		||||
          .to render_template(:show)
 | 
			
		||||
 | 
			
		||||
        expect(ActivityPub::UpdateDistributionWorker)
 | 
			
		||||
          .to_not have_received(:perform_async)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      private
 | 
			
		||||
 | 
			
		||||
      def failing_update_service
 | 
			
		||||
        instance_double(UpdateAccountService, call: false)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										67
									
								
								spec/system/settings/privacy_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								spec/system/settings/privacy_spec.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe 'Settings Privacy' do
 | 
			
		||||
  let!(:user) { Fabricate(:user) }
 | 
			
		||||
 | 
			
		||||
  before { sign_in(user) }
 | 
			
		||||
 | 
			
		||||
  describe 'Managing privacy settings' do
 | 
			
		||||
    before { user.account.update(discoverable: false) }
 | 
			
		||||
 | 
			
		||||
    context 'with a successful update' do
 | 
			
		||||
      before { allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async) }
 | 
			
		||||
 | 
			
		||||
      it 'updates user profile information' do
 | 
			
		||||
        # View settings page
 | 
			
		||||
        visit settings_privacy_path
 | 
			
		||||
        expect(page)
 | 
			
		||||
          .to have_content(I18n.t('privacy.title'))
 | 
			
		||||
          .and have_private_cache_control
 | 
			
		||||
 | 
			
		||||
        # Fill out form and submit
 | 
			
		||||
        check 'account_discoverable'
 | 
			
		||||
        check 'account_indexable'
 | 
			
		||||
        expect { click_on submit_button }
 | 
			
		||||
          .to change { user.account.reload.discoverable }.to(true)
 | 
			
		||||
        expect(page)
 | 
			
		||||
          .to have_content(I18n.t('privacy.title'))
 | 
			
		||||
          .and have_content(I18n.t('generic.changes_saved_msg'))
 | 
			
		||||
        expect(ActivityPub::UpdateDistributionWorker)
 | 
			
		||||
          .to have_received(:perform_async).with(user.account.id)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'with a failed update' do
 | 
			
		||||
      before do
 | 
			
		||||
        allow(UpdateAccountService).to receive(:new).and_return(failing_update_service)
 | 
			
		||||
        allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'updates user profile information' do
 | 
			
		||||
        # View settings page
 | 
			
		||||
        visit settings_privacy_path
 | 
			
		||||
        expect(page)
 | 
			
		||||
          .to have_content(I18n.t('privacy.title'))
 | 
			
		||||
          .and have_private_cache_control
 | 
			
		||||
 | 
			
		||||
        # Fill out form and submit
 | 
			
		||||
        check 'account_discoverable'
 | 
			
		||||
        check 'account_indexable'
 | 
			
		||||
        expect { click_on submit_button }
 | 
			
		||||
          .to_not(change { user.account.reload.discoverable })
 | 
			
		||||
        expect(page)
 | 
			
		||||
          .to have_content(I18n.t('privacy.title'))
 | 
			
		||||
        expect(ActivityPub::UpdateDistributionWorker)
 | 
			
		||||
          .to_not have_received(:perform_async)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      private
 | 
			
		||||
 | 
			
		||||
      def failing_update_service
 | 
			
		||||
        instance_double(UpdateAccountService, call: false)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Reference in New Issue
	
	Block a user