]> cat aescling's git repositories - mastodon.git/commitdiff
Move KeywordMute into Glitch namespace.
authorDavid Yip <yipdw@member.fsf.org>
Sat, 21 Oct 2017 19:47:17 +0000 (14:47 -0500)
committerDavid Yip <yipdw@member.fsf.org>
Sat, 21 Oct 2017 19:54:36 +0000 (14:54 -0500)
There are two motivations for this:

1. It looks like we're going to add other features that require
   server-side storage (e.g. user notes).

2. Namespacing glitchsoc modifications is a good idea anyway: even if we
   do not end up doing (1), if upstream introduces a keyword-mute feature
   that also uses a "KeywordMute" model, we can avoid some merge
   conflicts this way and work on the more interesting task of
   choosing which implementation to use.

app/controllers/settings/keyword_mutes_controller.rb
app/lib/feed_manager.rb
app/models/glitch.rb [new file with mode: 0644]
app/models/glitch/keyword_mute.rb [moved from app/models/keyword_mute.rb with 84% similarity]
db/migrate/20171021191900_move_keyword_mutes_into_glitch_namespace.rb [new file with mode: 0644]
db/schema.rb
spec/fabricators/glitch_keyword_mute_fabricator.rb [new file with mode: 0644]
spec/fabricators/keyword_mute_fabricator.rb [deleted file]
spec/models/glitch/keyword_mute_spec.rb [moved from spec/models/keyword_mute_spec.rb with 64% similarity]

index d9f99af090869e5f10359da681054a2b397b0354..6ae05108d9ca2542b809b6cdd871fb68382e52bf 100644 (file)
@@ -55,7 +55,7 @@ class Settings::KeywordMutesController < ApplicationController
   end
 
   def keyword_mutes_for_account
-    KeywordMute.where(account: @account)
+    Glitch::KeywordMute.where(account: @account)
   end
 
   def load_keyword_mute
index 516bd81af70d30a9a153501867b8cdd7a10671ef..1123f88bbdec7d42e50d4e1f9fdb002e34fdce11 100644 (file)
@@ -138,7 +138,7 @@ class FeedManager
   end
 
   def filter_from_home?(status, receiver_id)
-    return true if KeywordMute.matcher_for(receiver_id) =~ status.text
+    return true if Glitch::KeywordMute.matcher_for(receiver_id) =~ 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?)
diff --git a/app/models/glitch.rb b/app/models/glitch.rb
new file mode 100644 (file)
index 0000000..0e497ba
--- /dev/null
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+module Glitch
+  def self.table_name_prefix
+    'glitch_'
+  end
+end
similarity index 84%
rename from app/models/keyword_mute.rb
rename to app/models/glitch/keyword_mute.rb
index b0229923d8744528a9c7cec947dc7768837b768b..3b0b47f52f3ca2c69e2299a048bc786d638ef8cd 100644 (file)
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 # == Schema Information
 #
-# Table name: keyword_mutes
+# Table name: glitch_keyword_mutes
 #
 #  id         :integer          not null, primary key
 #  account_id :integer          not null
@@ -11,7 +11,7 @@
 #  updated_at :datetime         not null
 #
 
-class KeywordMute < ApplicationRecord
+class Glitch::KeywordMute < ApplicationRecord
   belongs_to :account, required: true
 
   validates_presence_of :keyword
@@ -33,7 +33,7 @@ class KeywordMute < ApplicationRecord
 
     def initialize(account_id)
       re = [].tap do |arr|
-        KeywordMute.where(account_id: account_id).select(:keyword, :id, :whole_word).find_each do |m|
+        Glitch::KeywordMute.where(account_id: account_id).select(:keyword, :id, :whole_word).find_each do |m|
           boundary = m.whole_word ? '\b' : ''
           arr << "#{boundary}#{Regexp.escape(m.keyword.strip)}#{boundary}"
         end
diff --git a/db/migrate/20171021191900_move_keyword_mutes_into_glitch_namespace.rb b/db/migrate/20171021191900_move_keyword_mutes_into_glitch_namespace.rb
new file mode 100644 (file)
index 0000000..269bb49
--- /dev/null
@@ -0,0 +1,7 @@
+class MoveKeywordMutesIntoGlitchNamespace < ActiveRecord::Migration[5.1]
+  def change
+    safety_assured do
+      rename_table :keyword_mutes, :glitch_keyword_mutes
+    end
+  end
+end
index c0704b13e310098c9e33c545f985c01228a644d9..c09876c4d7ebb3df0533d325996b5853ee1a8a3a 100644 (file)
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20171010025614) do
+ActiveRecord::Schema.define(version: 20171021191900) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -155,6 +155,15 @@ ActiveRecord::Schema.define(version: 20171010025614) do
     t.index ["account_id", "target_account_id"], name: "index_follows_on_account_id_and_target_account_id", unique: true
   end
 
+  create_table "glitch_keyword_mutes", force: :cascade do |t|
+    t.bigint "account_id", null: false
+    t.string "keyword", null: false
+    t.boolean "whole_word", default: true, null: false
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
+    t.index ["account_id"], name: "index_glitch_keyword_mutes_on_account_id"
+  end
+
   create_table "imports", force: :cascade do |t|
     t.integer "type", null: false
     t.boolean "approved", default: false, null: false
@@ -167,15 +176,6 @@ ActiveRecord::Schema.define(version: 20171010025614) do
     t.bigint "account_id", null: false
   end
 
-  create_table "keyword_mutes", force: :cascade do |t|
-    t.bigint "account_id", null: false
-    t.string "keyword", null: false
-    t.boolean "whole_word", default: true, null: false
-    t.datetime "created_at", null: false
-    t.datetime "updated_at", null: false
-    t.index ["account_id"], name: "index_keyword_mutes_on_account_id"
-  end
-
   create_table "media_attachments", force: :cascade do |t|
     t.bigint "status_id"
     t.string "file_file_name"
@@ -481,8 +481,8 @@ ActiveRecord::Schema.define(version: 20171010025614) do
   add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
   add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
   add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
+  add_foreign_key "glitch_keyword_mutes", "accounts", on_delete: :cascade
   add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
-  add_foreign_key "keyword_mutes", "accounts", on_delete: :cascade
   add_foreign_key "media_attachments", "accounts", name: "fk_96dd81e81b", on_delete: :nullify
   add_foreign_key "media_attachments", "statuses", on_delete: :nullify
   add_foreign_key "mentions", "accounts", name: "fk_970d43f9d1", on_delete: :cascade
diff --git a/spec/fabricators/glitch_keyword_mute_fabricator.rb b/spec/fabricators/glitch_keyword_mute_fabricator.rb
new file mode 100644 (file)
index 0000000..8601ed6
--- /dev/null
@@ -0,0 +1,2 @@
+Fabricator(:glitch_keyword_mute) do
+end
diff --git a/spec/fabricators/keyword_mute_fabricator.rb b/spec/fabricators/keyword_mute_fabricator.rb
deleted file mode 100644 (file)
index 82cf845..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Fabricator(:keyword_mute) do
-end
similarity index 64%
rename from spec/models/keyword_mute_spec.rb
rename to spec/models/glitch/keyword_mute_spec.rb
index c745051886124331a382f5ff671b3069127b2a9b..108cdafec6d5a0451946300fc8c9edbe15842c67 100644 (file)
@@ -1,15 +1,15 @@
 require 'rails_helper'
 
-RSpec.describe KeywordMute, type: :model do
+RSpec.describe Glitch::KeywordMute, type: :model do
   let(:alice) { Fabricate(:account, username: 'alice').tap(&:save!) }
   let(:bob) { Fabricate(:account, username: 'bob').tap(&:save!) }
 
   describe '.matcher_for' do
-    let(:matcher) { KeywordMute.matcher_for(alice) }
+    let(:matcher) { Glitch::KeywordMute.matcher_for(alice) }
 
-    describe 'with no KeywordMutes for an account' do
+    describe 'with no Glitch::KeywordMutes for an account' do
       before do
-        KeywordMute.delete_all
+        Glitch::KeywordMute.delete_all
       end
 
       it 'does not match' do
@@ -17,63 +17,63 @@ RSpec.describe KeywordMute, type: :model do
       end
     end
 
-    describe 'with KeywordMutes for an account' do
+    describe 'with Glitch::KeywordMutes for an account' do
       it 'does not match keywords set by a different account' do
-        KeywordMute.create!(account: bob, keyword: 'take')
+        Glitch::KeywordMute.create!(account: bob, keyword: 'take')
 
         expect(matcher =~ 'This is a hot take').to be_falsy
       end
 
       it 'does not match if no keywords match the status text' do
-        KeywordMute.create!(account: alice, keyword: 'cold')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'cold')
 
         expect(matcher =~ 'This is a hot take').to be_falsy
       end
 
       it 'considers word boundaries when matching' do
-        KeywordMute.create!(account: alice, keyword: 'bob', whole_word: true)
+        Glitch::KeywordMute.create!(account: alice, keyword: 'bob', whole_word: true)
 
         expect(matcher =~ 'bobcats').to be_falsy
       end
 
       it 'matches substrings if whole_word is false' do
-        KeywordMute.create!(account: alice, keyword: 'take', whole_word: false)
+        Glitch::KeywordMute.create!(account: alice, keyword: 'take', whole_word: false)
 
         expect(matcher =~ 'This is a shiitake mushroom').to be_truthy
       end
 
       it 'matches keywords at the beginning of the text' do
-        KeywordMute.create!(account: alice, keyword: 'take')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'take')
 
         expect(matcher =~ 'Take this').to be_truthy
       end
 
       it 'matches keywords at the beginning of the text' do
-        KeywordMute.create!(account: alice, keyword: 'take')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'take')
 
         expect(matcher =~ 'This is a hot take').to be_truthy
       end
 
       it 'matches if at least one keyword case-insensitively matches the text' do
-        KeywordMute.create!(account: alice, keyword: 'hot')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'hot')
 
         expect(matcher =~ 'This is a HOT take').to be_truthy
       end
 
       it 'matches keywords surrounded by non-alphanumeric ornamentation' do
-        KeywordMute.create!(account: alice, keyword: 'hot')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'hot')
 
         expect(matcher =~ 'This is a ~*HOT*~ take').to be_truthy
       end
 
       it 'uses case-folding rules appropriate for more than just English' do
-        KeywordMute.create!(account: alice, keyword: 'großeltern')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'großeltern')
 
         expect(matcher =~ 'besuch der grosseltern').to be_truthy
       end
 
       it 'matches keywords that are composed of multiple words' do
-        KeywordMute.create!(account: alice, keyword: 'a shiitake')
+        Glitch::KeywordMute.create!(account: alice, keyword: 'a shiitake')
 
         expect(matcher =~ 'This is a shiitake').to be_truthy
         expect(matcher =~ 'This is shiitake').to_not be_truthy
This page took 0.045175 seconds and 3 git commands to generate.