Skip to content

Commit

Permalink
Add posting with limited visibility test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 25, 2023
1 parent a9b2288 commit 385ac0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
21 changes: 21 additions & 0 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 385ac0c

Please sign in to comment.