fix: avoid warm up on update like before
it will avoid a bunch of unecessary updatesmain
parent
6bfea476ed
commit
148f12f8f9
|
@ -44,7 +44,7 @@ module Rating
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def rating(as: nil, scoping: nil)
|
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,
|
has_many :rating_records,
|
||||||
as: :resource,
|
as: :resource,
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Rating::Extension, 'after_save' do
|
RSpec.describe Rating::Extension, 'after_create' do
|
||||||
context 'when record is author' do
|
context 'when record is author' do
|
||||||
let!(:record) { build :author }
|
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)
|
expect(record).not_to receive(:rating_warm_up)
|
||||||
|
|
||||||
record.save
|
record.save
|
||||||
|
@ -33,5 +33,15 @@ RSpec.describe Rating::Extension, 'after_save' do
|
||||||
record.save
|
record.save
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
Loading…
Reference in New Issue