mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Adds test and fixes logic errors
This commit is contained in:
parent
eee4e30e25
commit
8b88de624d
2 changed files with 14 additions and 4 deletions
|
@ -393,10 +393,10 @@ class Edition(Book):
|
|||
existing_match = model.find_existing(data)
|
||||
|
||||
# assign this edition to the parent of the duplicate edition
|
||||
if existing_match and existing_match.parent_work:
|
||||
new_work = existing_match.parent_work
|
||||
# if not, create a new work for it
|
||||
if not new_work:
|
||||
new_work = models.Work.objects.create(title=self.title)
|
||||
else:
|
||||
new_work = Work.objects.create(title=self.title)
|
||||
|
||||
self.parent_work = new_work
|
||||
self.save(update_fields=["parent_work"], broadcast=False)
|
||||
|
|
|
@ -143,3 +143,13 @@ class Book(TestCase):
|
|||
for article in articles
|
||||
)
|
||||
self.assertTrue(all(book.sort_title == "test edition" for book in books))
|
||||
|
||||
def test_repair_edition(self):
|
||||
"""Fix editions with no works"""
|
||||
edition = models.Edition.objects.create(title="test")
|
||||
self.assertIsNone(edition.parent_work)
|
||||
|
||||
edition.repair()
|
||||
edition.refresh_from_db()
|
||||
|
||||
self.assertEqual(edition.parent_work.title, "test")
|
||||
|
|
Loading…
Reference in a new issue