diff --git a/app/models/answer.rb b/app/models/answer.rb index 7d0e0608..f0d12326 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -8,14 +8,15 @@ class Answer < ApplicationRecord has_many :subscriptions, dependent: :destroy has_many :comment_smiles, through: :comments, source: :smiles + # rubocop:disable Rails/SkipsModelValidations after_create do Inbox.where(user: self.user, question: self.question).destroy_all Notification.notify self.question.user, self unless self.question.user == self.user or self.question.user.nil? Subscription.subscribe self.user, self Subscription.subscribe self.question.user, self unless self.question.author_is_anonymous - self.user.increment! :answered_count - self.question.increment! :answer_count + user.increment! :answered_count + question.increment! :answer_count end before_destroy do @@ -28,8 +29,8 @@ class Answer < ApplicationRecord end end - self.user&.decrement! :answered_count - self.question&.decrement! :answer_count + user&.decrement! :answered_count + question&.decrement! :answer_count self.smiles.each do |smile| Notification.denotify self.user, smile end @@ -40,6 +41,7 @@ class Answer < ApplicationRecord Notification.denotify self.question.user, self Subscription.destruct self end + # rubocop:enable Rails/SkipsModelValidations def notification_type(*_args) Notifications::QuestionAnswered diff --git a/app/models/comment.rb b/app/models/comment.rb index 04ba54b8..4c3dcc7d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -7,6 +7,7 @@ class Comment < ApplicationRecord validates :content, length: { maximum: 160 } + # rubocop:disable Rails/SkipsModelValidations after_create do Subscription.subscribe self.user, answer, false Subscription.notify self, answer @@ -24,9 +25,10 @@ class Comment < ApplicationRecord end Subscription.denotify self, answer - user&.decrement! :commented_count + user&.decrement! :commented_count answer&.decrement! :comment_count end + # rubocop:enable Rails/SkipsModelValidations def notification_type(*_args) Notifications::Commented diff --git a/app/models/question.rb b/app/models/question.rb index 70841cc6..e7742bec 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -16,7 +16,9 @@ class Question < ApplicationRecord end end - user&.decrement! :asked_count unless self.author_is_anonymous + # rubocop:disable Rails/SkipsModelValidations + user&.decrement! :asked_count unless author_is_anonymous + # rubocop:enable Rails/SkipsModelValidations end def can_be_removed?