From 385ac0c1a2dad447e9f6e225dfa5d87d2170c51c Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 25 Sep 2023 18:32:11 +0900 Subject: [PATCH] Add posting with limited visibility test --- app/services/post_status_service.rb | 1 + spec/services/post_status_service_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index a549ab1c78a893..f48555245ef20d 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -94,6 +94,7 @@ def preprocess_attributes! end def load_circle + raise ArgumentError if @options[:visibility] == 'limited' && @options[:circle_id].nil? return unless @options[:visibility] == 'circle' || (@options[:visibility] == 'limited' && @options[:circle_id].present?) @circle = @options[:circle_id].present? && Circle.find(@options[:circle_id]) diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index 3b953b9fc1fb65..a2cf6fbfb07348 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -206,6 +206,27 @@ expect(status.mentioned_accounts.first.id).to eq circle_account.id end + it 'circle post with limited visibility' do + account = Fabricate(:account) + circle_account = Fabricate(:account) + circle = Fabricate(:circle, account: account) + text = 'This is an English text.' + + circle_account.follow!(account) + circle.accounts << circle_account + status = subject.call(account, text: text, visibility: 'limited', circle_id: circle.id) + + expect(status.visibility).to eq 'limited' + expect(status.limited_scope).to eq 'circle' + end + + it 'limited visibility and empty circle' do + account = Fabricate(:account) + text = 'This is an English text.' + + expect { subject.call(account, text: text, visibility: 'limited') }.to raise_exception ActiveRecord::RecordInvalid + end + it 'safeguards mentions' do account = Fabricate(:account) mentioned_account = Fabricate(:account, username: 'alice')