]> cat aescling's git repositories - mastodon.git/commitdiff
Spec out KeywordMute interface. #164.
authorDavid Yip <yipdw@member.fsf.org>
Sat, 14 Oct 2017 07:28:20 +0000 (02:28 -0500)
committerDavid Yip <yipdw@member.fsf.org>
Sat, 21 Oct 2017 19:54:21 +0000 (14:54 -0500)
app/lib/feed_manager.rb
app/models/keyword_mute.rb
spec/models/keyword_mute_spec.rb

index ca15745cb141e9cd6d3f3f697f89ad80278e1387..baaa09e8604a0ba838e512f0b7a3a4a340d86dd2 100644 (file)
@@ -138,6 +138,8 @@ class FeedManager
   end
 
   def filter_from_home?(status, receiver_id)
+    return true if KeywordMute.where(account_id: receiver_id).matches?(status.text)
+
     return false if receiver_id == status.account_id
     return true  if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
 
index 91816eed9424af81c3d3e683900ba68db15616fb..d397a1f41fb1c47835217422a4664ec65054a976 100644 (file)
@@ -10,4 +10,6 @@
 #
 
 class KeywordMute < ApplicationRecord
+  def self.matches?(text)
+  end
 end
index cd08815656466f659676e0abfe2e549097ee4dd4..cb6e554e46128dea11a9e4ec82352eb7b6811450 100644 (file)
@@ -1,5 +1,21 @@
 require 'rails_helper'
 
 RSpec.describe KeywordMute, type: :model do
-  pending "add some examples to (or delete) #{__FILE__}"
+  describe '.matches?' do
+    let(:alice)  { Fabricate(:account, username: 'alice').tap(&:save!) }
+    let(:status) { Fabricate(:status, account: alice).tap(&:save!) }
+    let(:keyword_mute) { Fabricate(:keyword_mute, account: alice, keyword: 'take').tap(&:save!) }
+
+    it 'returns true if any keyword in the set matches the status text' do
+      status.update_attribute(:text, 'This is a hot take')
+
+      expect(KeywordMute.where(account: alice).matches?(status.text)).to be_truthy
+    end
+
+    it 'returns false if no keyword in the set matches the status text'
+
+    describe 'matching' do
+      it 'is case-insensitive'
+    end
+  end
 end
This page took 0.030178 seconds and 3 git commands to generate.