diff --git a/lib/rating/models/rating/extension.rb b/lib/rating/models/rating/extension.rb index c25d6aa..e4365ca 100644 --- a/lib/rating/models/rating/extension.rb +++ b/lib/rating/models/rating/extension.rb @@ -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, diff --git a/spec/models/extension/after_save_spec.rb b/spec/models/extension/after_create_spec.rb similarity index 70% rename from spec/models/extension/after_save_spec.rb rename to spec/models/extension/after_create_spec.rb index daa5a89..cf14e90 100644 --- a/spec/models/extension/after_save_spec.rb +++ b/spec/models/extension/after_create_spec.rb @@ -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