about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/account_spec.rb6
-rw-r--r--spec/models/account_warning_preset_spec.rb17
-rw-r--r--spec/models/appeal_spec.rb35
-rw-r--r--spec/models/block_spec.rb5
-rw-r--r--spec/models/custom_emoji_category_spec.rb11
-rw-r--r--spec/models/domain_allow_spec.rb15
-rw-r--r--spec/models/domain_block_spec.rb5
-rw-r--r--spec/models/email_domain_block_spec.rb7
-rw-r--r--spec/models/extended_description_spec.rb29
-rw-r--r--spec/models/follow_spec.rb5
-rw-r--r--spec/models/import_spec.rb5
-rw-r--r--spec/models/ip_block_spec.rb12
-rw-r--r--spec/models/marker_spec.rb13
-rw-r--r--spec/models/mention_spec.rb5
-rw-r--r--spec/models/one_time_key_spec.rb19
-rw-r--r--spec/models/poll_spec.rb29
-rw-r--r--spec/models/preview_card_provider_spec.rb42
-rw-r--r--spec/models/privacy_policy_spec.rb28
-rw-r--r--spec/models/report_spec.rb6
-rw-r--r--spec/models/rule_spec.rb16
-rw-r--r--spec/models/status_edit_spec.rb10
-rw-r--r--spec/models/status_spec.rb79
-rw-r--r--spec/models/trends/tags_spec.rb4
23 files changed, 346 insertions, 57 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 1e5a80963..ae4e5ee32 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -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?
diff --git a/spec/models/account_warning_preset_spec.rb b/spec/models/account_warning_preset_spec.rb
new file mode 100644
index 000000000..f171df7c9
--- /dev/null
+++ b/spec/models/account_warning_preset_spec.rb
@@ -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
diff --git a/spec/models/appeal_spec.rb b/spec/models/appeal_spec.rb
index 6aa013aba..12373a949 100644
--- a/spec/models/appeal_spec.rb
+++ b/spec/models/appeal_spec.rb
@@ -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
diff --git a/spec/models/block_spec.rb b/spec/models/block_spec.rb
index 64c39fce6..6e31786d0 100644
--- a/spec/models/block_spec.rb
+++ b/spec/models/block_spec.rb
@@ -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?
diff --git a/spec/models/custom_emoji_category_spec.rb b/spec/models/custom_emoji_category_spec.rb
index 74881b26c..30de07bd8 100644
--- a/spec/models/custom_emoji_category_spec.rb
+++ b/spec/models/custom_emoji_category_spec.rb
@@ -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
diff --git a/spec/models/domain_allow_spec.rb b/spec/models/domain_allow_spec.rb
index 18cf5fe4c..49e16376e 100644
--- a/spec/models/domain_allow_spec.rb
+++ b/spec/models/domain_allow_spec.rb
@@ -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
diff --git a/spec/models/domain_block_spec.rb b/spec/models/domain_block_spec.rb
index 6a5925b89..9839ee9d4 100644
--- a/spec/models/domain_block_spec.rb
+++ b/spec/models/domain_block_spec.rb
@@ -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?
diff --git a/spec/models/email_domain_block_spec.rb b/spec/models/email_domain_block_spec.rb
index 01a7a0f0e..3321ffc81 100644
--- a/spec/models/email_domain_block_spec.rb
+++ b/spec/models/email_domain_block_spec.rb
@@ -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 }
 
diff --git a/spec/models/extended_description_spec.rb b/spec/models/extended_description_spec.rb
new file mode 100644
index 000000000..ecc27c0f6
--- /dev/null
+++ b/spec/models/extended_description_spec.rb
@@ -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
diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb
index f49d58532..a9a9af88a 100644
--- a/spec/models/follow_spec.rb
+++ b/spec/models/follow_spec.rb
@@ -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?
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index 81c75a964..1c8474413 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -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)
diff --git a/spec/models/ip_block_spec.rb b/spec/models/ip_block_spec.rb
index 4c4028576..ed5882667 100644
--- a/spec/models/ip_block_spec.rb
+++ b/spec/models/ip_block_spec.rb
@@ -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
diff --git a/spec/models/marker_spec.rb b/spec/models/marker_spec.rb
index e8561c4c6..51dd58438 100644
--- a/spec/models/marker_spec.rb
+++ b/spec/models/marker_spec.rb
@@ -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
diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb
index 3de2b4a07..044bb80cf 100644
--- a/spec/models/mention_spec.rb
+++ b/spec/models/mention_spec.rb
@@ -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?
diff --git a/spec/models/one_time_key_spec.rb b/spec/models/one_time_key_spec.rb
index 2a5fe8a9d..6ff7ffc5c 100644
--- a/spec/models/one_time_key_spec.rb
+++ b/spec/models/one_time_key_spec.rb
@@ -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
diff --git a/spec/models/poll_spec.rb b/spec/models/poll_spec.rb
index 474399bf6..8ae04ca41 100644
--- a/spec/models/poll_spec.rb
+++ b/spec/models/poll_spec.rb
@@ -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
diff --git a/spec/models/preview_card_provider_spec.rb b/spec/models/preview_card_provider_spec.rb
new file mode 100644
index 000000000..7425b9394
--- /dev/null
+++ b/spec/models/preview_card_provider_spec.rb
@@ -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
diff --git a/spec/models/privacy_policy_spec.rb b/spec/models/privacy_policy_spec.rb
new file mode 100644
index 000000000..0d7471375
--- /dev/null
+++ b/spec/models/privacy_policy_spec.rb
@@ -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
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index d5d40a34f..20a048c33 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -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?
diff --git a/spec/models/rule_spec.rb b/spec/models/rule_spec.rb
index d5ec13ddf..c9b9c5502 100644
--- a/spec/models/rule_spec.rb
+++ b/spec/models/rule_spec.rb
@@ -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
diff --git a/spec/models/status_edit_spec.rb b/spec/models/status_edit_spec.rb
index 0b9fa7087..2d3351452 100644
--- a/spec/models/status_edit_spec.rb
+++ b/spec/models/status_edit_spec.rb
@@ -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
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb
index 7022c5f00..d1caf267c 100644
--- a/spec/models/status_spec.rb
+++ b/spec/models/status_spec.rb
@@ -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
diff --git a/spec/models/trends/tags_spec.rb b/spec/models/trends/tags_spec.rb
index a9473e15c..09ac918d0 100644
--- a/spec/models/trends/tags_spec.rb
+++ b/spec/models/trends/tags_spec.rb
@@ -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