mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
remove rails-observers
Rails yanked out observers many many years ago, instead the functionality was yanked out to a gem that is very lightly maintained. For example: if we want to upgrade to rails 5 there is no published gem Internally the usage of observers had quite a few problem. The series of refactors renamed a bunch of classes to give us more clarity and removed some magic.
This commit is contained in:
@@ -5,7 +5,6 @@ require 'topic_subtype'
|
||||
describe PostCreator do
|
||||
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
end
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
@@ -4,7 +4,6 @@ require 'post_destroyer'
|
||||
describe PostDestroyer do
|
||||
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
UserActionCreator.enable
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ describe UserActionsController do
|
||||
end
|
||||
|
||||
it 'renders list correctly' do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
UserActionCreator.enable
|
||||
post = Fabricate(:post)
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ describe CategoryUser do
|
||||
|
||||
context 'integration' do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
NotificationEmailer.enable
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ describe DirectoryItem do
|
||||
|
||||
context 'refresh' do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
UserActionCreator.enable
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ require 'rails_helper'
|
||||
|
||||
describe Notification do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
NotificationEmailer.enable
|
||||
end
|
||||
|
||||
@@ -235,7 +234,6 @@ describe Notification do
|
||||
describe 'ensure consistency' do
|
||||
it 'deletes notifications if post is missing or deleted' do
|
||||
|
||||
ActiveRecord::Base.observers.disable :all
|
||||
NotificationEmailer.disable
|
||||
|
||||
p = Fabricate(:post)
|
||||
|
||||
@@ -220,7 +220,9 @@ describe PostAction do
|
||||
describe 'when a user likes something' do
|
||||
|
||||
it 'should generate notifications correctly' do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
|
||||
PostActionNotifier.enable
|
||||
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
expect(Notification.count).to eq(1)
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ describe PostMover do
|
||||
before do
|
||||
p1.replies << p3
|
||||
p2.replies << p4
|
||||
# add a like to a post, enable observers so we get user actions
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
UserActionCreator.enable
|
||||
@like = PostAction.act(another_user, p4, PostActionType.types[:like])
|
||||
end
|
||||
|
||||
@@ -81,8 +81,7 @@ describe PostTiming do
|
||||
# integration test
|
||||
|
||||
it 'processes timings correctly' do
|
||||
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
PostActionNotifier.enable
|
||||
|
||||
post = Fabricate(:post)
|
||||
user2 = Fabricate(:coding_horror, created_at: 1.day.ago)
|
||||
|
||||
@@ -3,9 +3,6 @@ require_dependency 'site'
|
||||
|
||||
describe Site do
|
||||
it "omits categories users can not write to from the category list" do
|
||||
|
||||
ActiveRecord::Base.observers.enable :anon_site_json_cache_observer
|
||||
|
||||
category = Fabricate(:category)
|
||||
user = Fabricate(:user)
|
||||
|
||||
|
||||
@@ -68,12 +68,7 @@ describe TagUser do
|
||||
end
|
||||
|
||||
context "integration" do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
end
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
let(:watched_tag) { Fabricate(:tag) }
|
||||
let(:muted_tag) { Fabricate(:tag) }
|
||||
let(:tracked_tag) { Fabricate(:tag) }
|
||||
|
||||
@@ -429,7 +429,6 @@ describe Topic do
|
||||
let(:actions) { topic.user.user_actions }
|
||||
|
||||
it "should set up actions correctly" do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
UserActionCreator.enable
|
||||
|
||||
expect(actions.map{|a| a.action_type}).not_to include(UserAction::NEW_TOPIC)
|
||||
|
||||
@@ -208,7 +208,6 @@ describe TopicUser do
|
||||
|
||||
context 'private messages' do
|
||||
it 'should ensure recepients and senders are watching' do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
|
||||
target_user = Fabricate(:user)
|
||||
post = create_post(archetype: Archetype.private_message, target_usernames: target_user.username);
|
||||
|
||||
@@ -3,7 +3,6 @@ require 'rails_helper'
|
||||
describe UserAction do
|
||||
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
UserActionCreator.enable
|
||||
end
|
||||
|
||||
@@ -51,6 +50,8 @@ describe UserAction do
|
||||
end
|
||||
|
||||
it 'includes the events correctly' do
|
||||
PostActionNotifier.enable
|
||||
|
||||
mystats = stats_for_user(user)
|
||||
expecting = [UserAction::NEW_TOPIC, UserAction::NEW_PRIVATE_MESSAGE, UserAction::GOT_PRIVATE_MESSAGE, UserAction::BOOKMARK].sort
|
||||
expect(mystats).to eq(expecting)
|
||||
|
||||
@@ -104,9 +104,7 @@ Spork.prefork do
|
||||
#
|
||||
# $redis = DiscourseMockRedis.new
|
||||
#
|
||||
# disable all observers, enable as needed during specs
|
||||
#
|
||||
ActiveRecord::Base.observers.disable :all
|
||||
PostActionNotifier.disable
|
||||
SearchIndexer.disable
|
||||
UserActionCreator.disable
|
||||
NotificationEmailer.disable
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
require 'rails_helper'
|
||||
require_dependency 'post_destroyer'
|
||||
|
||||
describe PostAlertObserver do
|
||||
describe PostActionNotifier do
|
||||
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :post_alert_observer
|
||||
PostActionNotifier.enable
|
||||
end
|
||||
|
||||
let!(:evil_trout) { Fabricate(:evil_trout) }
|
||||
@@ -63,8 +63,7 @@ describe PostAlerter do
|
||||
|
||||
context 'edits' do
|
||||
it 'notifies correctly on edits' do
|
||||
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
PostActionNotifier.enable
|
||||
|
||||
post = Fabricate(:post, raw: 'I love waffles')
|
||||
|
||||
@@ -89,7 +88,7 @@ describe PostAlerter do
|
||||
context 'likes' do
|
||||
|
||||
it 'notifies on likes after an undo' do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
PostActionNotifier.enable
|
||||
|
||||
post = Fabricate(:post, raw: 'I love waffles')
|
||||
|
||||
@@ -101,7 +100,7 @@ describe PostAlerter do
|
||||
end
|
||||
|
||||
it 'notifies on does not notify when never is selected' do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
PostActionNotifier.enable
|
||||
|
||||
post = Fabricate(:post, raw: 'I love waffles')
|
||||
|
||||
@@ -110,12 +109,11 @@ describe PostAlerter do
|
||||
|
||||
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
||||
|
||||
|
||||
expect(Notification.where(post_number: 1, topic_id: post.topic_id).count).to eq(0)
|
||||
end
|
||||
|
||||
it 'notifies on likes correctly' do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
PostActionNotifier.enable
|
||||
|
||||
post = Fabricate(:post, raw: 'I love waffles')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user