diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 2e8e7b3c..2274fcac 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -28,15 +28,18 @@ class Subscription < ApplicationRecord def notify(source, target) return nil if source.nil? || target.nil? - muted_by = Relationships::Mute.where(target: source.user).pluck(&:source_id) - # As we will need to notify for each person subscribed, # it's much faster to bulk insert than to use +Notification.notify+ - notifications = Subscription.where(answer: target) - .where.not(user: source.user) - .where.not(user_id: muted_by) - .map do |s| - { target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented, created_at: source.created_at, updated_at: source.created_at } + notifications = Subscription.for(source, target).pluck(:user_id).map do |recipient_id| + { + target_id: source.id, + target_type: Comment, + recipient_id:, + new: true, + type: Notification::Commented, + created_at: source.created_at, + updated_at: source.created_at, + } end return if notifications.empty? @@ -53,5 +56,13 @@ class Subscription < ApplicationRecord subs = Subscription.where(answer: target) Notification.where(target:, recipient: subs.map(&:user)).delete_all end + + def for(source, target) + muted_by = Relationships::Mute.where(target: source.user).pluck(&:source_id) + + Subscription.where(answer: target) + .where.not(user: source.user) + .where.not(user_id: muted_by) + end end end diff --git a/spec/controllers/ajax/comment_controller_spec.rb b/spec/controllers/ajax/comment_controller_spec.rb index a93fc126..ace88ce6 100644 --- a/spec/controllers/ajax/comment_controller_spec.rb +++ b/spec/controllers/ajax/comment_controller_spec.rb @@ -35,7 +35,6 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do expect { subject }.to change { subscribed_user.reload.notifications_updated_at }.to(DateTime.now) end end - end include_examples "returns the expected response" diff --git a/spec/helpers/bootstrap_helper_spec.rb b/spec/helpers/bootstrap_helper_spec.rb index 4cacecd7..0f31f85e 100644 --- a/spec/helpers/bootstrap_helper_spec.rb +++ b/spec/helpers/bootstrap_helper_spec.rb @@ -43,10 +43,10 @@ describe BootstrapHelper, :type => :helper do ) end - it 'should put an ID on the entry an id if given' do + it "should put an ID on the entry an id if given" do allow(self).to receive(:current_page?).and_return(false) - expect(nav_entry('Example', '/example', id: "testing")).to( - eq('') + expect(nav_entry("Example", "/example", id: "testing")).to( + eq("
  • Example
  • "), ) end end