Created
October 17, 2019 11:50
-
-
Save rebelweb/844500f4ca103aac69da1a7387993f86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe UpdateCounterCachesJob, type: :job do | |
it 'updates all cache columns when they are out of sync' do sql = <<-SQL update categories SET articles_count = 5 SQL | |
category = create(:category) | |
ActiveRecord::Base.connection.execute(sql) | |
category.reload | |
expect(category.articles_count).to eq(5) | |
UpdateCounterCachesJob.perform_now | |
category.reload | |
expect(category.articles_count).to eq(0) | |
end | |
it 'updates an individual model\'s cache columns' do | |
sql = <<-SQL | |
update categories | |
SET articles_count = 5 | |
SQL | |
category = create(:category) | |
ActiveRecord::Base.connection.execute(sql) | |
category.reload | |
expect(category.articles_count).to eq(5) | |
UpdateCounterCachesJob.perform_now('category') | |
category.reload | |
expect(category.articles_count).to eq(0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment