🐛 Fix AuthorsUsersSeparationUpdater
It was creating authors for users without mods.master
parent
59124660b5
commit
4fd57f33fe
|
@ -1,13 +1,16 @@
|
|||
class AuthorsUsersSeparationUpdater
|
||||
def run
|
||||
User.all.each do |user|
|
||||
author = Author.create! name: user.name, forum_name: user.name
|
||||
AuthorsMod.where(author_id: user.id).update_all(author_id: author.id)
|
||||
if user.autogenerated?
|
||||
user.destroy!
|
||||
elsif author.mods.where(owner: user).count > 0
|
||||
author.user = user
|
||||
author.save!
|
||||
authors_mods = AuthorsMod.where(author_id: user.id)
|
||||
unless authors_mods.empty?
|
||||
author = Author.create! name: user.name, forum_name: user.name
|
||||
authors_mods.update_all(author_id: author.id)
|
||||
if user.autogenerated?
|
||||
user.destroy!
|
||||
elsif author.mods.where(owner: user).count > 0
|
||||
author.user = user
|
||||
author.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -102,6 +102,12 @@ describe AuthorsUsersSeparationUpdater do
|
|||
expect(User.find_by_id u2.id).to eq u2
|
||||
end
|
||||
|
||||
it "should not create an author for a user that doesn't have any associated mod" do
|
||||
create :user, name: 'Potato'
|
||||
updater.run
|
||||
expect(Author.all).to be_empty
|
||||
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'
|
||||
|
|
Loading…
Reference in New Issue