Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `README.md`: Upstream README has been changed, but we have a completely different one. Kept our `README.md`. - `lib/sanitize_ext/sanitize_config.rb`: Upstream added support for more incoming HTML tags (a large subset of what glitch-soc accepts). Change the code style to match upstream's but otherwise do not change our code. - `spec/lib/sanitize_config_spec.rb`: Upstream added support for more incoming HTML tags (a large subset of what glitch-soc accepts). Kept our version, since the tests are mostly glitch-soc's, except for cases which are purposefuly different.
This commit is contained in:
@@ -704,12 +704,6 @@ RSpec.describe Account, type: :model do
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
account = Fabricate.build(:account)
|
||||
account.valid?
|
||||
expect(account).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without a username' do
|
||||
account = Fabricate.build(:account, username: nil)
|
||||
account.valid?
|
||||
|
||||
17
spec/models/account_warning_preset_spec.rb
Normal file
17
spec/models/account_warning_preset_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountWarningPreset do
|
||||
describe 'alphabetical' do
|
||||
let(:first) { Fabricate(:account_warning_preset, title: 'aaa', text: 'aaa') }
|
||||
let(:second) { Fabricate(:account_warning_preset, title: 'bbb', text: 'aaa') }
|
||||
let(:third) { Fabricate(:account_warning_preset, title: 'bbb', text: 'bbb') }
|
||||
|
||||
it 'returns records in order of title and text' do
|
||||
results = described_class.alphabetic
|
||||
|
||||
expect(results).to eq([first, second, third])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,6 +2,37 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Appeal, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe Appeal do
|
||||
describe 'scopes' do
|
||||
describe 'approved' do
|
||||
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
|
||||
let(:not_approved_appeal) { Fabricate(:appeal, approved_at: nil) }
|
||||
|
||||
it 'finds the correct records' do
|
||||
results = described_class.approved
|
||||
expect(results).to eq([approved_appeal])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'rejected' do
|
||||
let(:rejected_appeal) { Fabricate(:appeal, rejected_at: 10.days.ago) }
|
||||
let(:not_rejected_appeal) { Fabricate(:appeal, rejected_at: nil) }
|
||||
|
||||
it 'finds the correct records' do
|
||||
results = described_class.rejected
|
||||
expect(results).to eq([rejected_appeal])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'pending' do
|
||||
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }
|
||||
let(:rejected_appeal) { Fabricate(:appeal, rejected_at: 10.days.ago) }
|
||||
let(:pending_appeal) { Fabricate(:appeal, rejected_at: nil, approved_at: nil) }
|
||||
|
||||
it 'finds the correct records' do
|
||||
results = described_class.pending
|
||||
expect(results).to eq([pending_appeal])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,6 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe Block, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
block = Fabricate.build(:block)
|
||||
expect(block).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without an account' do
|
||||
block = Fabricate.build(:block, account: nil)
|
||||
block.valid?
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CustomEmojiCategory, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe CustomEmojiCategory do
|
||||
describe 'validations' do
|
||||
it 'validates name presence' do
|
||||
record = described_class.new(name: nil)
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record).to model_have_error_on_field(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainAllow, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe DomainAllow do
|
||||
describe 'scopes' do
|
||||
describe 'matches_domain' do
|
||||
let(:domain) { Fabricate(:domain_allow, domain: 'example.com') }
|
||||
let(:other_domain) { Fabricate(:domain_allow, domain: 'example.biz') }
|
||||
|
||||
it 'returns the correct records' do
|
||||
results = described_class.matches_domain('example.com')
|
||||
|
||||
expect(results).to eq([domain])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,6 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainBlock, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
domain_block = Fabricate.build(:domain_block)
|
||||
expect(domain_block).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without a domain' do
|
||||
domain_block = Fabricate.build(:domain_block, domain: nil)
|
||||
domain_block.valid?
|
||||
|
||||
@@ -3,13 +3,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EmailDomainBlock, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
email_domain_block = Fabricate.build(:email_domain_block)
|
||||
expect(email_domain_block).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'block?' do
|
||||
let(:input) { nil }
|
||||
|
||||
|
||||
29
spec/models/extended_description_spec.rb
Normal file
29
spec/models/extended_description_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExtendedDescription do
|
||||
describe '.current' do
|
||||
context 'with the default values' do
|
||||
it 'makes a new instance' do
|
||||
record = described_class.current
|
||||
|
||||
expect(record.text).to be_nil
|
||||
expect(record.updated_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a custom setting value' do
|
||||
before do
|
||||
setting = instance_double(Setting, value: 'Extended text', updated_at: 10.days.ago)
|
||||
allow(Setting).to receive(:find_by).with(var: 'site_extended_description').and_return(setting)
|
||||
end
|
||||
|
||||
it 'has the privacy text' do
|
||||
record = described_class.current
|
||||
|
||||
expect(record.text).to eq('Extended text')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,11 +9,6 @@ RSpec.describe Follow, type: :model do
|
||||
describe 'validations' do
|
||||
subject { Follow.new(account: alice, target_account: bob, rate_limit: true) }
|
||||
|
||||
it 'has a valid fabricator' do
|
||||
follow = Fabricate.build(:follow)
|
||||
expect(follow).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without an account' do
|
||||
follow = Fabricate.build(:follow, account: nil)
|
||||
follow.valid?
|
||||
|
||||
@@ -23,6 +23,11 @@ RSpec.describe Import, type: :model do
|
||||
expect(import).to model_have_error_on_field(:data)
|
||||
end
|
||||
|
||||
it 'is invalid with malformed data' do
|
||||
import = Import.create(account: account, type: type, data: StringIO.new('\"test'))
|
||||
expect(import).to model_have_error_on_field(:data)
|
||||
end
|
||||
|
||||
it 'is invalid with too many rows in data' do
|
||||
import = Import.create(account: account, type: type, data: StringIO.new("foo@bar.com\n" * (ImportService::ROWS_PROCESSING_LIMIT + 10)))
|
||||
expect(import).to model_have_error_on_field(:data)
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe IpBlock, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe IpBlock do
|
||||
describe 'to_log_human_identifier' do
|
||||
let(:ip_block) { described_class.new(ip: '192.168.0.1') }
|
||||
|
||||
it 'combines the IP and prefix into a string' do
|
||||
result = ip_block.to_log_human_identifier
|
||||
|
||||
expect(result).to eq('192.168.0.1/32')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Marker, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe Marker do
|
||||
describe 'validations' do
|
||||
describe 'timeline' do
|
||||
it 'must be included in valid list' do
|
||||
record = described_class.new(timeline: 'not real timeline')
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record).to model_have_error_on_field(:timeline)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,6 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe Mention, type: :model do
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
mention = Fabricate.build(:mention)
|
||||
expect(mention).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid without an account' do
|
||||
mention = Fabricate.build(:mention, account: nil)
|
||||
mention.valid?
|
||||
|
||||
@@ -2,5 +2,22 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OneTimeKey, type: :model do
|
||||
describe OneTimeKey do
|
||||
describe 'validations' do
|
||||
context 'with an invalid signature' do
|
||||
let(:one_time_key) { Fabricate.build(:one_time_key, signature: 'wrong!') }
|
||||
|
||||
it 'is invalid' do
|
||||
expect(one_time_key).to_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid key' do
|
||||
let(:one_time_key) { Fabricate.build(:one_time_key, key: 'wrong!') }
|
||||
|
||||
it 'is invalid' do
|
||||
expect(one_time_key).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,31 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Poll, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe Poll do
|
||||
describe 'scopes' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:attached_poll) { Fabricate(:poll, status: status) }
|
||||
let(:not_attached_poll) do
|
||||
Fabricate(:poll).tap do |poll|
|
||||
poll.status = nil
|
||||
poll.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'attached' do
|
||||
it 'finds the correct records' do
|
||||
results = described_class.attached
|
||||
|
||||
expect(results).to eq([attached_poll])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unattached' do
|
||||
it 'finds the correct records' do
|
||||
results = described_class.unattached
|
||||
|
||||
expect(results).to eq([not_attached_poll])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
42
spec/models/preview_card_provider_spec.rb
Normal file
42
spec/models/preview_card_provider_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PreviewCardProvider do
|
||||
describe 'scopes' do
|
||||
let(:trendable_and_reviewed) { Fabricate(:preview_card_provider, trendable: true, reviewed_at: 5.days.ago) }
|
||||
let(:not_trendable_and_not_reviewed) { Fabricate(:preview_card_provider, trendable: false, reviewed_at: nil) }
|
||||
|
||||
describe 'trendable' do
|
||||
it 'returns the relevant records' do
|
||||
results = described_class.trendable
|
||||
|
||||
expect(results).to eq([trendable_and_reviewed])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'not_trendable' do
|
||||
it 'returns the relevant records' do
|
||||
results = described_class.not_trendable
|
||||
|
||||
expect(results).to eq([not_trendable_and_not_reviewed])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'reviewed' do
|
||||
it 'returns the relevant records' do
|
||||
results = described_class.reviewed
|
||||
|
||||
expect(results).to eq([trendable_and_reviewed])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'pending_review' do
|
||||
it 'returns the relevant records' do
|
||||
results = described_class.pending_review
|
||||
|
||||
expect(results).to eq([not_trendable_and_not_reviewed])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
28
spec/models/privacy_policy_spec.rb
Normal file
28
spec/models/privacy_policy_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PrivacyPolicy do
|
||||
describe '.current' do
|
||||
context 'with the default values' do
|
||||
it 'has the privacy text' do
|
||||
policy = described_class.current
|
||||
|
||||
expect(policy.text).to eq(PrivacyPolicy::DEFAULT_PRIVACY_POLICY)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a custom setting value' do
|
||||
before do
|
||||
terms_setting = instance_double(Setting, value: 'Terms text', updated_at: 10.days.ago)
|
||||
allow(Setting).to receive(:find_by).with(var: 'site_terms').and_return(terms_setting)
|
||||
end
|
||||
|
||||
it 'has the privacy text' do
|
||||
policy = described_class.current
|
||||
|
||||
expect(policy.text).to eq('Terms text')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -121,12 +121,6 @@ describe Report do
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'has a valid fabricator' do
|
||||
report = Fabricate(:report)
|
||||
report.valid?
|
||||
expect(report).to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid if comment is longer than 1000 characters' do
|
||||
report = Fabricate.build(:report, comment: Faker::Lorem.characters(number: 1001))
|
||||
report.valid?
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Rule, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe Rule do
|
||||
describe 'scopes' do
|
||||
describe 'ordered' do
|
||||
let(:deleted_rule) { Fabricate(:rule, deleted_at: 10.days.ago) }
|
||||
let(:first_rule) { Fabricate(:rule, deleted_at: nil, priority: 1) }
|
||||
let(:last_rule) { Fabricate(:rule, deleted_at: nil, priority: 10) }
|
||||
|
||||
it 'finds the correct records' do
|
||||
results = described_class.ordered
|
||||
|
||||
expect(results).to eq([first_rule, last_rule])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe StatusEdit, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe StatusEdit do
|
||||
describe '#reblog?' do
|
||||
it 'returns false' do
|
||||
record = described_class.new
|
||||
|
||||
expect(record).to_not be_a_reblog
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,6 +114,85 @@ RSpec.describe Status, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#translatable?' do
|
||||
before do
|
||||
allow(TranslationService).to receive(:configured?).and_return(true)
|
||||
allow(TranslationService).to receive(:configured).and_return(TranslationService.new)
|
||||
allow(TranslationService.configured).to receive(:supported?).with('es', 'en').and_return(true)
|
||||
|
||||
subject.language = 'es'
|
||||
subject.visibility = :public
|
||||
end
|
||||
|
||||
context 'all conditions are satisfied' do
|
||||
it 'returns true' do
|
||||
expect(subject.translatable?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'translation service is not configured' do
|
||||
it 'returns false' do
|
||||
allow(TranslationService).to receive(:configured?).and_return(false)
|
||||
allow(TranslationService).to receive(:configured).and_raise(TranslationService::NotConfiguredError)
|
||||
expect(subject.translatable?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'status language is nil' do
|
||||
it 'returns true' do
|
||||
subject.language = nil
|
||||
allow(TranslationService.configured).to receive(:supported?).with(nil, 'en').and_return(true)
|
||||
expect(subject.translatable?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'status language is same as default locale' do
|
||||
it 'returns false' do
|
||||
subject.language = I18n.locale
|
||||
expect(subject.translatable?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'status language is unsupported' do
|
||||
it 'returns false' do
|
||||
subject.language = 'af'
|
||||
allow(TranslationService.configured).to receive(:supported?).with('af', 'en').and_return(false)
|
||||
expect(subject.translatable?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'default locale is unsupported' do
|
||||
it 'returns false' do
|
||||
allow(TranslationService.configured).to receive(:supported?).with('es', 'af').and_return(false)
|
||||
I18n.with_locale('af') do
|
||||
expect(subject.translatable?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'default locale has region' do
|
||||
it 'returns true' do
|
||||
I18n.with_locale('en-GB') do
|
||||
expect(subject.translatable?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'status text is blank' do
|
||||
it 'returns false' do
|
||||
subject.text = ' '
|
||||
expect(subject.translatable?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'status visiblity is hidden' do
|
||||
it 'returns false' do
|
||||
subject.visibility = 'limited'
|
||||
expect(subject.translatable?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#content' do
|
||||
it 'returns the text of the status if it is not a reblog' do
|
||||
expect(subject.content).to eql subject.text
|
||||
|
||||
@@ -24,7 +24,9 @@ RSpec.describe Trends::Tags do
|
||||
end
|
||||
|
||||
describe '#query' do
|
||||
pending
|
||||
it 'returns a composable query scope' do
|
||||
expect(subject.query).to be_a Trends::Query
|
||||
end
|
||||
end
|
||||
|
||||
describe '#refresh' do
|
||||
|
||||
Reference in New Issue
Block a user