Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - .eslintrc.yml Removed, as upstream removed it. - app/controllers/admin/statuses_controller.rb Minor code cleanup when porting one of our features. - app/models/account.rb Note length validation has changed upstream. We now use upstream's validation (dropped legacy glitch-soc account metadata stuff) but with configurable limit. - app/services/post_status_service.rb Upstream has added support for scheduled toots, refactoring the code a bit. Adapted our changes to this refactoring. - app/views/stream_entries/_detailed_status.html.haml Not a real conflict, changes too close. - app/views/stream_entries/_simple_status.html.haml Not a real conflict, changes too close.
This commit is contained in:
@@ -7,26 +7,6 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
around do |example|
|
||||
default_per_page = DomainBlock.default_per_page
|
||||
DomainBlock.paginates_per 1
|
||||
example.run
|
||||
DomainBlock.paginates_per default_per_page
|
||||
end
|
||||
|
||||
it 'renders domain blocks' do
|
||||
2.times { Fabricate(:domain_block) }
|
||||
|
||||
get :index, params: { page: 2 }
|
||||
|
||||
assigned = assigns(:domain_blocks)
|
||||
expect(assigned.count).to eq 1
|
||||
expect(assigned.klass).to be DomainBlock
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'assigns a new domain block' do
|
||||
get :new
|
||||
@@ -53,7 +33,7 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
|
||||
|
||||
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
|
||||
expect(response).to redirect_to(admin_domain_blocks_path)
|
||||
expect(response).to redirect_to(admin_instances_path(limited: '1'))
|
||||
end
|
||||
|
||||
it 'renders new when failed to save' do
|
||||
@@ -76,7 +56,7 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
|
||||
|
||||
expect(service).to have_received(:call).with(domain_block, true)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.destroyed_msg')
|
||||
expect(response).to redirect_to(admin_domain_blocks_path)
|
||||
expect(response).to redirect_to(admin_instances_path(limited: '1'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -15,7 +15,7 @@ RSpec.describe Api::V1::ConversationsController, type: :controller do
|
||||
let(:scopes) { 'read:statuses' }
|
||||
|
||||
before do
|
||||
PostStatusService.new.call(other.account, 'Hey @alice', nil, visibility: 'direct')
|
||||
PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
|
@@ -84,19 +84,17 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') }
|
||||
end
|
||||
|
||||
xit 'returns http success' do
|
||||
it do
|
||||
# returns http success
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
xit 'creates a media attachment' do
|
||||
# creates a media attachment
|
||||
expect(MediaAttachment.first).to_not be_nil
|
||||
end
|
||||
|
||||
xit 'uploads a file' do
|
||||
# uploads a file
|
||||
expect(MediaAttachment.first).to have_attached_file(:file)
|
||||
end
|
||||
|
||||
xit 'returns media ID in JSON' do
|
||||
# returns media ID in JSON
|
||||
expect(body_as_json[:id]).to eq MediaAttachment.first.id.to_s
|
||||
end
|
||||
end
|
||||
|
@@ -50,9 +50,9 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
let(:scopes) { 'read:notifications' }
|
||||
|
||||
before do
|
||||
first_status = PostStatusService.new.call(user.account, 'Test')
|
||||
first_status = PostStatusService.new.call(user.account, text: 'Test')
|
||||
@reblog_of_first_status = ReblogService.new.call(other.account, first_status)
|
||||
mentioning_status = PostStatusService.new.call(other.account, 'Hello @alice')
|
||||
mentioning_status = PostStatusService.new.call(other.account, text: 'Hello @alice')
|
||||
@mention_from_status = mentioning_status.mentions.first
|
||||
@favourite = FavouriteService.new.call(other.account, first_status)
|
||||
@follow = FollowService.new.call(other.account, 'alice')
|
||||
|
@@ -17,7 +17,7 @@ describe Api::V1::Timelines::HomeController do
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
follow = Fabricate(:follow, account: user.account)
|
||||
PostStatusService.new.call(follow.target_account, 'New status for user home timeline.')
|
||||
PostStatusService.new.call(follow.target_account, text: 'New status for user home timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
|
@@ -19,7 +19,7 @@ describe Api::V1::Timelines::ListController do
|
||||
before do
|
||||
follow = Fabricate(:follow, account: user.account)
|
||||
list.accounts << follow.target_account
|
||||
PostStatusService.new.call(follow.target_account, 'New status for user home timeline.')
|
||||
PostStatusService.new.call(follow.target_account, text: 'New status for user home timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
|
@@ -16,7 +16,7 @@ describe Api::V1::Timelines::PublicController do
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
PostStatusService.new.call(user.account, 'New status from user for federated public timeline.')
|
||||
PostStatusService.new.call(user.account, text: 'New status from user for federated public timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
@@ -29,7 +29,7 @@ describe Api::V1::Timelines::PublicController do
|
||||
|
||||
describe 'GET #show with local only' do
|
||||
before do
|
||||
PostStatusService.new.call(user.account, 'New status from user for local public timeline.')
|
||||
PostStatusService.new.call(user.account, text: 'New status from user for local public timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
|
@@ -16,7 +16,7 @@ describe Api::V1::Timelines::TagController do
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
PostStatusService.new.call(user.account, 'It is a #test')
|
||||
PostStatusService.new.call(user.account, text: 'It is a #test')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
|
4
spec/fabricators/scheduled_status_fabricator.rb
Normal file
4
spec/fabricators/scheduled_status_fabricator.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Fabricator(:scheduled_status) do
|
||||
account
|
||||
scheduled_at { 20.hours.from_now }
|
||||
end
|
@@ -22,11 +22,35 @@ describe JsonLdHelper do
|
||||
end
|
||||
|
||||
describe '#first_of_value' do
|
||||
pending
|
||||
context 'value.is_a?(Array)' do
|
||||
it 'returns value.first' do
|
||||
value = ['a']
|
||||
expect(helper.first_of_value(value)).to be 'a'
|
||||
end
|
||||
end
|
||||
|
||||
context '!value.is_a?(Array)' do
|
||||
it 'returns value' do
|
||||
value = 'a'
|
||||
expect(helper.first_of_value(value)).to be 'a'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#supported_context?' do
|
||||
pending
|
||||
context "!json.nil? && equals_or_includes?(json['@context'], ActivityPub::TagManager::CONTEXT)" do
|
||||
it 'returns true' do
|
||||
json = { '@context' => ActivityPub::TagManager::CONTEXT }.as_json
|
||||
expect(helper.supported_context?(json)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'else' do
|
||||
it 'returns false' do
|
||||
json = nil
|
||||
expect(helper.supported_context?(json)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fetch_resource' do
|
||||
|
@@ -108,21 +108,21 @@ RSpec.describe FeedManager do
|
||||
|
||||
it 'returns false for status by followee mentioning another account' do
|
||||
bob.follow!(alice)
|
||||
status = PostStatusService.new.call(alice, 'Hey @jeff')
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false
|
||||
end
|
||||
|
||||
it 'returns true for status by followee mentioning blocked account' do
|
||||
bob.block!(jeff)
|
||||
bob.follow!(alice)
|
||||
status = PostStatusService.new.call(alice, 'Hey @jeff')
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for status by followee mentioning muted account' do
|
||||
bob.mute!(jeff)
|
||||
bob.follow!(alice)
|
||||
status = PostStatusService.new.call(alice, 'Hey @jeff')
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true
|
||||
end
|
||||
|
||||
@@ -162,7 +162,7 @@ RSpec.describe FeedManager do
|
||||
context 'for mentions feed' do
|
||||
it 'returns true for status that mentions blocked account' do
|
||||
bob.block!(jeff)
|
||||
status = PostStatusService.new.call(alice, 'Hey @jeff')
|
||||
status = PostStatusService.new.call(alice, text: 'Hey @jeff')
|
||||
expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true
|
||||
end
|
||||
|
||||
|
@@ -1,5 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountWarningPreset, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
@@ -1,5 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountWarning, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
4
spec/models/scheduled_status_spec.rb
Normal file
4
spec/models/scheduled_status_spec.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ScheduledStatus, type: :model do
|
||||
end
|
@@ -8,7 +8,7 @@ RSpec.describe InstancePolicy do
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :index?, :resubscribe? do
|
||||
permissions :index? do
|
||||
context 'admin' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Instance)
|
||||
|
@@ -8,8 +8,8 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
|
||||
let!(:jeff) { Fabricate(:user).account }
|
||||
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
|
||||
let(:status1) { PostStatusService.new.call(alice, 'Hello @bob@example.com') }
|
||||
let(:status2) { PostStatusService.new.call(alice, 'Another status') }
|
||||
let(:status1) { PostStatusService.new.call(alice, text: 'Hello @bob@example.com') }
|
||||
let(:status2) { PostStatusService.new.call(alice, text: 'Another status') }
|
||||
|
||||
before do
|
||||
allow(Redis.current).to receive_messages(publish: nil)
|
||||
|
@@ -7,7 +7,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
account = Fabricate(:account)
|
||||
text = "test status update"
|
||||
|
||||
status = subject.call(account, text)
|
||||
status = subject.call(account, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
@@ -18,20 +18,31 @@ RSpec.describe PostStatusService, type: :service do
|
||||
account = Fabricate(:account)
|
||||
text = "test status update"
|
||||
|
||||
status = subject.call(account, text, in_reply_to_status)
|
||||
status = subject.call(account, text: text, thread: in_reply_to_status)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
expect(status.thread).to eq in_reply_to_status
|
||||
end
|
||||
|
||||
it 'schedules a status' do
|
||||
account = Fabricate(:account)
|
||||
future = Time.now.utc + 2.hours
|
||||
|
||||
status = subject.call(account, text: 'Hi future!', scheduled_at: future)
|
||||
|
||||
expect(status).to be_a ScheduledStatus
|
||||
expect(status.scheduled_at).to eq future
|
||||
expect(status.params['text']).to eq 'Hi future!'
|
||||
end
|
||||
|
||||
it 'creates response to the original status of boost' do
|
||||
boosted_status = Fabricate(:status)
|
||||
in_reply_to_status = Fabricate(:status, reblog: boosted_status)
|
||||
account = Fabricate(:account)
|
||||
text = "test status update"
|
||||
|
||||
status = subject.call(account, text, in_reply_to_status)
|
||||
status = subject.call(account, text: text, thread: in_reply_to_status)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
@@ -69,7 +80,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
end
|
||||
|
||||
it 'creates a status with limited visibility for silenced users' do
|
||||
status = subject.call(Fabricate(:account, silenced: true), 'test', nil, visibility: :public)
|
||||
status = subject.call(Fabricate(:account, silenced: true), text: 'test', visibility: :public)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.visibility).to eq "unlisted"
|
||||
@@ -88,7 +99,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
account = Fabricate(:account)
|
||||
text = 'This is an English text.'
|
||||
|
||||
status = subject.call(account, text)
|
||||
status = subject.call(account, text: text)
|
||||
|
||||
expect(status.language).to eq 'en'
|
||||
end
|
||||
@@ -99,7 +110,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
allow(ProcessMentionsService).to receive(:new).and_return(mention_service)
|
||||
account = Fabricate(:account)
|
||||
|
||||
status = subject.call(account, "test status update")
|
||||
status = subject.call(account, text: "test status update")
|
||||
|
||||
expect(ProcessMentionsService).to have_received(:new)
|
||||
expect(mention_service).to have_received(:call).with(status)
|
||||
@@ -111,7 +122,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
allow(ProcessHashtagsService).to receive(:new).and_return(hashtags_service)
|
||||
account = Fabricate(:account)
|
||||
|
||||
status = subject.call(account, "test status update")
|
||||
status = subject.call(account, text: "test status update")
|
||||
|
||||
expect(ProcessHashtagsService).to have_received(:new)
|
||||
expect(hashtags_service).to have_received(:call).with(status)
|
||||
@@ -124,7 +135,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
|
||||
account = Fabricate(:account)
|
||||
|
||||
status = subject.call(account, "test status update")
|
||||
status = subject.call(account, text: "test status update")
|
||||
|
||||
expect(DistributionWorker).to have_received(:perform_async).with(status.id)
|
||||
expect(Pubsubhubbub::DistributionWorker).to have_received(:perform_async).with(status.stream_entry.id)
|
||||
@@ -135,7 +146,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
allow(LinkCrawlWorker).to receive(:perform_async)
|
||||
account = Fabricate(:account)
|
||||
|
||||
status = subject.call(account, "test status update")
|
||||
status = subject.call(account, text: "test status update")
|
||||
|
||||
expect(LinkCrawlWorker).to have_received(:perform_async).with(status.id)
|
||||
end
|
||||
@@ -146,8 +157,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
|
||||
status = subject.call(
|
||||
account,
|
||||
"test status update",
|
||||
nil,
|
||||
text: "test status update",
|
||||
media_ids: [media.id],
|
||||
)
|
||||
|
||||
@@ -160,8 +170,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
expect do
|
||||
subject.call(
|
||||
account,
|
||||
"test status update",
|
||||
nil,
|
||||
text: "test status update",
|
||||
media_ids: [
|
||||
Fabricate(:media_attachment, account: account),
|
||||
Fabricate(:media_attachment, account: account),
|
||||
@@ -182,8 +191,7 @@ RSpec.describe PostStatusService, type: :service do
|
||||
expect do
|
||||
subject.call(
|
||||
account,
|
||||
"test status update",
|
||||
nil,
|
||||
text: "test status update",
|
||||
media_ids: [
|
||||
Fabricate(:media_attachment, type: :video, account: account),
|
||||
Fabricate(:media_attachment, type: :image, account: account),
|
||||
@@ -197,12 +205,12 @@ RSpec.describe PostStatusService, type: :service do
|
||||
|
||||
it 'returns existing status when used twice with idempotency key' do
|
||||
account = Fabricate(:account)
|
||||
status1 = subject.call(account, 'test', nil, idempotency: 'meepmeep')
|
||||
status2 = subject.call(account, 'test', nil, idempotency: 'meepmeep')
|
||||
status1 = subject.call(account, text: 'test', idempotency: 'meepmeep')
|
||||
status2 = subject.call(account, text: 'test', idempotency: 'meepmeep')
|
||||
expect(status2.id).to eq status1.id
|
||||
end
|
||||
|
||||
def create_status_with_options(**options)
|
||||
subject.call(Fabricate(:account), 'test', nil, options)
|
||||
subject.call(Fabricate(:account), options.merge(text: 'test'))
|
||||
end
|
||||
end
|
||||
|
@@ -19,7 +19,7 @@ RSpec.describe RemoveStatusService, type: :service do
|
||||
jeff.follow!(alice)
|
||||
hank.follow!(alice)
|
||||
|
||||
@status = PostStatusService.new.call(alice, 'Hello @bob@example.com')
|
||||
@status = PostStatusService.new.call(alice, text: 'Hello @bob@example.com')
|
||||
Fabricate(:status, account: bill, reblog: @status, uri: 'hoge')
|
||||
subject.call(@status)
|
||||
end
|
||||
|
@@ -119,8 +119,6 @@ RSpec.describe ResolveAccountService, type: :service do
|
||||
expect(account.actor_type).to eq 'Person'
|
||||
end
|
||||
end
|
||||
|
||||
pending
|
||||
end
|
||||
|
||||
it 'processes one remote account at a time using locks' do
|
||||
|
44
spec/validators/unreserved_username_validator_spec.rb
Normal file
44
spec/validators/unreserved_username_validator_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UnreservedUsernameValidator, type: :validator do
|
||||
describe '#validate' do
|
||||
before do
|
||||
allow(validator).to receive(:reserved_username?) { reserved_username }
|
||||
validator.validate(account)
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new }
|
||||
let(:account) { double(username: username, errors: errors) }
|
||||
let(:errors ) { double(add: nil) }
|
||||
|
||||
context '@username.nil?' do
|
||||
let(:username) { nil }
|
||||
|
||||
it 'not calls errors.add' do
|
||||
expect(errors).not_to have_received(:add).with(:username, any_args)
|
||||
end
|
||||
end
|
||||
|
||||
context '!@username.nil?' do
|
||||
let(:username) { '' }
|
||||
|
||||
context 'reserved_username?' do
|
||||
let(:reserved_username) { true }
|
||||
|
||||
it 'calls erros.add' do
|
||||
expect(errors).to have_received(:add).with(:username, I18n.t('accounts.reserved_username'))
|
||||
end
|
||||
end
|
||||
|
||||
context '!reserved_username?' do
|
||||
let(:reserved_username) { false }
|
||||
|
||||
it 'not calls erros.add' do
|
||||
expect(errors).not_to have_received(:add).with(:username, any_args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
spec/validators/url_validator_spec.rb
Normal file
34
spec/validators/url_validator_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UrlValidator, type: :validator do
|
||||
describe '#validate_each' do
|
||||
before do
|
||||
allow(validator).to receive(:compliant?).with(value) { compliant }
|
||||
validator.validate_each(record, attribute, value)
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new(attributes: [attribute]) }
|
||||
let(:record) { double(errors: errors) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:value) { '' }
|
||||
let(:attribute) { :foo }
|
||||
|
||||
context 'unless compliant?' do
|
||||
let(:compliant) { false }
|
||||
|
||||
it 'calls errors.add' do
|
||||
expect(errors).to have_received(:add).with(attribute, I18n.t('applications.invalid_url'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'if compliant?' do
|
||||
let(:compliant) { true }
|
||||
|
||||
it 'not calls errors.add' do
|
||||
expect(errors).not_to have_received(:add).with(attribute, any_args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
spec/workers/publish_scheduled_status_worker_spec.rb
Normal file
23
spec/workers/publish_scheduled_status_worker_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PublishScheduledStatusWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:scheduled_status) { Fabricate(:scheduled_status, params: { text: 'Hello world, future!' }) }
|
||||
|
||||
describe 'perform' do
|
||||
before do
|
||||
subject.perform(scheduled_status.id)
|
||||
end
|
||||
|
||||
it 'creates a status' do
|
||||
expect(scheduled_status.account.statuses.first.text).to eq 'Hello world, future!'
|
||||
end
|
||||
|
||||
it 'removes the scheduled status' do
|
||||
expect(ScheduledStatus.find_by(id: scheduled_status.id)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user