diff --git a/app/models/user.rb b/app/models/user.rb index a5263e0c..a56bb514 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User < ApplicationRecord +class User < ApplicationRecord # rubocop:disable Metrics/ClassLength include User::Relationship include User::Relationship::Follow include User::Relationship::Block diff --git a/app/workers/question_worker.rb b/app/workers/question_worker.rb index 3936f77f..571bc609 100644 --- a/app/workers/question_worker.rb +++ b/app/workers/question_worker.rb @@ -15,7 +15,7 @@ class QuestionWorker user.followers.each do |f| next if f.inbox_locked? next if f.banned? - next if MuteRule.where(user: f).any? { |rule| rule.applies_to? question } + next if muted?(f, question) next if user.muting?(question.user) inbox = Inbox.create(user_id: f.id, question_id:, new: true) @@ -25,4 +25,10 @@ class QuestionWorker logger.info "failed to ask question: #{e.message}" Sentry.capture_exception(e) end + + private + + def muted?(user, question) + MuteRule.where(user:).any? { |rule| rule.applies_to? question } + end end diff --git a/db/migrate/20220909161542_add_rpush.rb b/db/migrate/20220909161542_add_rpush.rb index fbc0af97..9b8cba01 100644 --- a/db/migrate/20220909161542_add_rpush.rb +++ b/db/migrate/20220909161542_add_rpush.rb @@ -22,6 +22,7 @@ # many times, by many people! class AddRpush < ActiveRecord::Migration[5.0] + # rubocop:disable all def self.migrations [CreateRapnsNotifications, CreateRapnsFeedback, AddAlertIsJsonToRapnsNotifications, AddAppToRapns, @@ -41,8 +42,6 @@ class AddRpush < ActiveRecord::Migration[5.0] end end - # rubocop:disable Rails/MigrationClassName - class CreateRapnsNotifications < ActiveRecord::Migration[5.0] def self.up create_table :rapns_notifications do |t| diff --git a/db/migrate/20220909161543_rpush_2_0_0_updates.rb b/db/migrate/20220909161543_rpush_2_0_0_updates.rb index 102c1337..505b74a0 100644 --- a/db/migrate/20220909161543_rpush_2_0_0_updates.rb +++ b/db/migrate/20220909161543_rpush_2_0_0_updates.rb @@ -12,7 +12,7 @@ class Rpush200Updates < ActiveRecord::Migration[5.0] end def self.update_type(model, from, to) - model.where(type: from).update_all(type: to) + model.where(type: from).update_all(type: to) # rubocop:disable Rails/SkipsModelValidations end def self.up diff --git a/spec/controllers/ajax/web_push_controller_spec.rb b/spec/controllers/ajax/web_push_controller_spec.rb index dcac726a..ea24d960 100644 --- a/spec/controllers/ajax/web_push_controller_spec.rb +++ b/spec/controllers/ajax/web_push_controller_spec.rb @@ -153,7 +153,7 @@ describe Ajax::WebPushController, :ajax_controller, type: :controller do let(:other_user) { FactoryBot.create(:user) } let!(:subscription) do WebPushSubscription.create( - user: other_user, + user: other_user, subscription: { endpoint:, keys: {} } ) end diff --git a/spec/workers/question_worker_spec.rb b/spec/workers/question_worker_spec.rb index 584baac7..cf022124 100644 --- a/spec/workers/question_worker_spec.rb +++ b/spec/workers/question_worker_spec.rb @@ -44,7 +44,6 @@ describe QuestionWorker do it "respects inbox locks" do user.followers.first.update(privacy_lock_inbox: true) - expect { subject } .to( change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count } @@ -71,15 +70,15 @@ describe QuestionWorker do Rpush::Webpush::App.create( name: "webpush", certificate: { public_key: "AAAA", private_key: "AAAA", subject: "" }.to_json, - connections: 1, + connections: 1 ) WebPushSubscription.create!( user: receiver, subscription: { endpoint: "This will not be used", - keys: {}, - }, + keys: {} + } ) receiver.follow(user) end