fix: avoid warm up on update like before

it will avoid a bunch of unecessary updates
main
Washington Botelho 2018-02-09 16:49:25 -02:00
parent 6bfea476ed
commit 148f12f8f9
No known key found for this signature in database
GPG Key ID: 5DE4F42A8F073617
2 changed files with 13 additions and 3 deletions

View File

@ -44,7 +44,7 @@ module Rating
module ClassMethods
def rating(as: nil, scoping: nil)
after_save -> { rating_warm_up scoping: scoping }, unless: -> { as == :author }
after_create -> { rating_warm_up scoping: scoping }, unless: -> { as == :author }
has_many :rating_records,
as: :resource,

View File

@ -2,11 +2,11 @@
require 'rails_helper'
RSpec.describe Rating::Extension, 'after_save' do
RSpec.describe Rating::Extension, 'after_create' do
context 'when record is author' do
let!(:record) { build :author }
it 'does warm up the cache' do
it 'does not warm up the cache' do
expect(record).not_to receive(:rating_warm_up)
record.save
@ -33,5 +33,15 @@ RSpec.describe Rating::Extension, 'after_save' do
record.save
end
end
context 'when update is made' do
let!(:record) { create :comment }
it 'does not warm up the cache' do
expect(record).not_to receive(:rating_warm_up)
record.save
end
end
end
end