Reset mods counter on AuthorsUsersSeparationUpdater

master
Zequez 2015-08-06 11:00:36 -03:00
parent a3cb596db8
commit a8a8fa4d99
2 changed files with 13 additions and 0 deletions

View File

@ -5,6 +5,7 @@ class AuthorsUsersSeparationUpdater
unless authors_mods.empty?
author = Author.create! name: user.name, forum_name: user.name
authors_mods.update_all(author_id: author.id)
Author.reset_counters(author.id, :mods)
if user.autogenerated?
user.destroy!
elsif author.mods.where(owner: user).count > 0

View File

@ -108,6 +108,18 @@ describe AuthorsUsersSeparationUpdater do
expect(Author.all).to be_empty
end
it 'should reset the authors #mods_count' do
u1 = create :user, name: 'Potato'
m1 = create :mod, owner: u1
create :authors_mod, mod_id: m1.id, author_id: u1.id
updater.run
a = Author.first
expect(a.name).to eq 'Potato'
expect(a.mods_count).to eq 1
end
it 'should associate the user and the author if the user is owner of the mod' do
u1 = create :user, name: 'Potato'
u2 = create :user, name: 'Galaxy'