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.rb8
-rw-r--r--spec/models/backup_spec.rb5
-rw-r--r--spec/models/glitch/keyword_mute_helper_spec.rb50
-rw-r--r--spec/models/identity_spec.rb5
-rw-r--r--spec/models/media_attachment_spec.rb1
-rw-r--r--spec/models/setting_spec.rb15
6 files changed, 73 insertions, 11 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 7501c498c..3ac7208ed 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -185,8 +185,8 @@ RSpec.describe Account, type: :model do
         expect(account.refresh!).to be_nil
       end
 
-      it 'calls not ResolveRemoteAccountService#call' do
-        expect_any_instance_of(ResolveRemoteAccountService).not_to receive(:call).with(acct)
+      it 'calls not ResolveAccountService#call' do
+        expect_any_instance_of(ResolveAccountService).not_to receive(:call).with(acct)
         account.refresh!
       end
     end
@@ -194,8 +194,8 @@ RSpec.describe Account, type: :model do
     context 'domain is present' do
       let(:domain) { 'example.com' }
 
-      it 'calls ResolveRemoteAccountService#call' do
-        expect_any_instance_of(ResolveRemoteAccountService).to receive(:call).with(acct).once
+      it 'calls ResolveAccountService#call' do
+        expect_any_instance_of(ResolveAccountService).to receive(:call).with(acct).once
         account.refresh!
       end
     end
diff --git a/spec/models/backup_spec.rb b/spec/models/backup_spec.rb
new file mode 100644
index 000000000..fabcdc845
--- /dev/null
+++ b/spec/models/backup_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Backup, type: :model do
+
+end
diff --git a/spec/models/glitch/keyword_mute_helper_spec.rb b/spec/models/glitch/keyword_mute_helper_spec.rb
new file mode 100644
index 000000000..b3f991d5b
--- /dev/null
+++ b/spec/models/glitch/keyword_mute_helper_spec.rb
@@ -0,0 +1,50 @@
+require 'rails_helper'
+
+RSpec.describe Glitch::KeywordMuteHelper do
+  describe '#matches?' do
+    let(:alice) { Fabricate(:account, username: 'alice').tap(&:save!) }
+    let(:helper) { Glitch::KeywordMuteHelper.new(alice) }
+
+    it 'ignores names of HTML tags in status text' do
+      status = Fabricate(:status, text: '<addr>uh example</addr>')
+      Glitch::KeywordMute.create!(account: alice, keyword: 'addr')
+
+      expect(helper.matches?(status)).to be false
+    end
+
+    it 'ignores properties of HTML tags in status text' do
+      status = Fabricate(:status, text: '<a href="https://www.example.org">uh example</a>')
+      Glitch::KeywordMute.create!(account: alice, keyword: 'href')
+
+      expect(helper.matches?(status)).to be false
+    end
+
+    it 'matches text inside HTML tags' do
+      status = Fabricate(:status, text: '<p>HEY THIS IS SOMETHING ANNOYING</p>')
+      Glitch::KeywordMute.create!(account: alice, keyword: 'annoying')
+
+      expect(helper.matches?(status)).to be true
+    end
+
+    it 'matches < in HTML-stripped text' do
+      status = Fabricate(:status, text: '<p>I <3 oats</p>')
+      Glitch::KeywordMute.create!(account: alice, keyword: '<3')
+
+      expect(helper.matches?(status)).to be true
+    end
+
+    it 'matches &lt; in HTML text' do
+      status = Fabricate(:status, text: '<p>I &lt;3 oats</p>')
+      Glitch::KeywordMute.create!(account: alice, keyword: '<3')
+
+      expect(helper.matches?(status)).to be true
+    end
+
+    it 'matches link hrefs in HTML text' do
+      status = Fabricate(:status, text: '<p><a href="https://example.com/it-was-milk">yep</a></p>')
+      Glitch::KeywordMute.create!(account: alice, keyword: 'milk')
+
+      expect(helper.matches?(status)).to be true
+    end
+  end
+end
diff --git a/spec/models/identity_spec.rb b/spec/models/identity_spec.rb
new file mode 100644
index 000000000..53f355410
--- /dev/null
+++ b/spec/models/identity_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Identity, type: :model do
+  pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb
index b40a641f7..d2230b6d0 100644
--- a/spec/models/media_attachment_spec.rb
+++ b/spec/models/media_attachment_spec.rb
@@ -92,7 +92,6 @@ RSpec.describe MediaAttachment, type: :model do
     it 'sets meta' do
       expect(media.file.meta["original"]["width"]).to eq 128
       expect(media.file.meta["original"]["height"]).to eq 128
-      expect(media.file.meta["original"]["aspect"]).to eq 1.0
     end
   end
 
diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb
index e99dfc0d7..1cc528674 100644
--- a/spec/models/setting_spec.rb
+++ b/spec/models/setting_spec.rb
@@ -42,17 +42,12 @@ RSpec.describe Setting, type: :model do
         described_class[key]
       end
 
-      it 'calls Rails.cache.fetch' do
-        expect(Rails).to receive_message_chain(:cache, :fetch).with(cache_key)
-        described_class[key]
-      end
-
       context 'Rails.cache does not exists' do
         before do
           allow(RailsSettings::Settings).to receive(:object).with(key).and_return(object)
           allow(described_class).to receive(:default_settings).and_return(default_settings)
           allow_any_instance_of(Settings::ScopedSettings).to receive(:thing_scoped).and_return(records)
-          Rails.cache.clear(cache_key)
+          Rails.cache.delete(cache_key)
         end
 
         let(:object)           { nil }
@@ -103,6 +98,14 @@ RSpec.describe Setting, type: :model do
           Rails.cache.write(cache_key, cache_value)
         end
 
+        it 'does not query the database' do
+          expect do |callback|
+            ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
+              described_class[key]
+            end
+          end.not_to yield_control
+        end
+
         it 'returns the cached value' do
           expect(described_class[key]).to eq cache_value
         end