@@ -198,11 +198,17 @@ Let's hack it in to see it work:
198
198
[source,python]
199
199
----
200
200
with self.assertRaises(ValidationError):
201
- item.save()
202
201
item.full_clean()
202
+ item.save()
203
203
----
204
204
====
205
205
//19
206
+ // CSANAD: full_clean() should be executed before save() is called. It doesn't
207
+ // make a difference here since the test DB is destroyed anyway, but
208
+ // we are actually saving an invalid item and only then calling full_clean().
209
+ // Which results in raising the correct error. But I think we should always
210
+ // show the correct order even when it doesn't matter: validation first and
211
+ // only then attempting save().
206
212
207
213
That gets the unit test to pass:
208
214
@@ -593,6 +599,19 @@ The current situation is that we have one view and URL for displaying a list,
593
599
and one view and URL for processing additions to that list. We're going to
594
600
combine them into one. So, in 'list.html', our form will have a different
595
601
target:
602
+ // CSANAD: Since we are working in a not completely working state, I would
603
+ // already mention or move the NOTE here from the end of the subsection:
604
+ // "Refactor: Transferring the new_item Functionality into view_list".
605
+ // And then just re-reference it from where it is right now.
606
+ //
607
+ // I think adding a few words on how this is not just a simple refactor but it's
608
+ // going to get us to our working state would help the reader recognise these
609
+ // situations later, independently.
610
+ // Something like pointing out how the FT is partially passing for:
611
+ // - adding one empty list item results in an error message
612
+ // - adding one valid list item is also passing
613
+ // - the error occurs when we try adding an empty list item again
614
+ // from which we conclude why we are refactoring the views first
596
615
597
616
[role="sourcecode"]
598
617
.src/lists/templates/list.html (ch11l030)
@@ -634,7 +653,10 @@ NOTE: In this section we're performing a refactor at the application level.
634
653
and things are back to working as before.
635
654
Have another look at the diagram from the end of <<chapter_04_philosophy_and_refactoring>>
636
655
if you need to get your bearings.
637
-
656
+ // CSANAD: my comment from above to say a few words on why we are refactoring
657
+ // despite the failing FT again feels justified since we are even
658
+ // mentioning the diagram too. It might feel confusing without telling the
659
+ // reader earlier what we are doing here.
638
660
639
661
640
662
==== Refactor: Transferring the new_item Functionality into view_list
0 commit comments