Skip to content

Commit

Permalink
https://github.com/danieleteti/delphimvcframework/issues/485
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Aug 15, 2021
1 parent fe5c92f commit 07805a8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ This version introduced new features in many different areas (swagger, server si
- Fix https://github.com/danieleteti/delphimvcframework/issues/461
- Fix https://github.com/danieleteti/delphimvcframework/issues/489 (thanks to [drcrck](https://github.com/drcrck) for his initial analisys)
- Fix https://github.com/danieleteti/delphimvcframework/issues/493 (thanks to [DelphiMan68](https://github.com/DelphiMan68) for his initial analisys)
- Fix https://github.com/danieleteti/delphimvcframework/issues/451
- Fix for nil objects in lists during serialization
- Uniformed behavior in `Update` and `Delete` method in `TMVCActiveRecord`. Now these methods raise an exception if the record doesn't exists anymore in the table (update or delete statements return `AffectedRows` = 0). The behavior can be altered using the new parameter in the call, which by default is `true`. WARNING! This change could raise some incompatibilities with the previous version, however this is the correct behavior. Consider the previous one a "incorrect behavior to fix".
- Fix https://github.com/danieleteti/delphimvcframework/issues/489
Expand Down
49 changes: 49 additions & 0 deletions unittests/general/Several/ActiveRecordTestsU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ TTestActiveRecordBase = class(TObject)
[Test]
procedure TestCRUD;
[Test]
procedure Test_ISSUE485;
[Test]
procedure TestDeleteIfNotFound;
[Test]
procedure TestUpdateIfNotFound;
Expand Down Expand Up @@ -816,6 +818,53 @@ procedure TTestActiveRecordBase.TestUpdateIfNotFound;
end;
end;

procedure TTestActiveRecordBase.Test_ISSUE485;
var
lCustomer: TCustomer;
lID: Integer;
begin
Assert.AreEqual(Int64(0), TMVCActiveRecord.Count<TCustomer>());
lCustomer := TCustomer.Create;
try
lCustomer.CompanyName := 'bit Time Professionals';
lCustomer.City := 'Rome, IT';
lCustomer.Note := 'note1';
lCustomer.CreationTime := Time;
lCustomer.CreationDate := Date;
lCustomer.ID := -1; { don't be fooled by the default! }
lCustomer.Insert;
lID := lCustomer.ID;
Assert.AreEqual(1, lID);
finally
lCustomer.Free;
end;

lCustomer := TMVCActiveRecord.GetByPK<TCustomer>(lID);
try
Assert.IsTrue(lCustomer.CompanyName.HasValue);
lCustomer.CompanyName.Clear;
lCustomer.Update;
finally
lCustomer.Free;
end;

lCustomer := TMVCActiveRecord.GetByPK<TCustomer>(lID);
try
Assert.IsFalse(lCustomer.CompanyName.HasValue);
lCustomer.CompanyName := 'bit Time Professionals';
lCustomer.Update;
finally
lCustomer.Free;
end;

lCustomer := TMVCActiveRecord.GetByPK<TCustomer>(lID);
try
Assert.IsTrue(lCustomer.CompanyName.HasValue);
finally
lCustomer.Free;
end;
end;

procedure TTestActiveRecordBase.InternalSetupFixture;
begin
// do nothing
Expand Down

0 comments on commit 07805a8

Please sign in to comment.