AlexDenisov/iActiveRecord — pull request #77 by valerius (2014-03-29 10:55:38+00:00)
Title: Feature/fix date serialization bug

Date serialization doesn't work as expected. The objects returned from deserialization is a NSNumber, which is deserialized using [value doubleValue] ; while the values of unpersisted assignments are NSDates thus causing the getter to raise an selector not found exception as the same function is processing different types. Example test fails without change:

```objective-c
describe(@"NSDate", ^{
it(@"Should be saved successfully and return the same date", ^{
User *alex = [User newRecord];
alex.name = @"Alex";
alex.birthDate = [NSDate dateWithTimeIntervalSince1970:0];
BOOL result = [alex save];

User *fetchedUser = [[User allRecords] objectAtIndex:0];
fetchedUser should_not be_nil;
alex.birthDate should equal(fetchedUser.birthDate);
});
});
```
result would be:
```
[0;40;31mEXCEPTION NSDate NSDate Should be saved successfully into database
-[__NSDate doubleValue]: unrecognized selector sent to instance 0x8ba0eb0
(null)[0m

```

Solution is to:

```objective-c
NSDate *__strong NSDateColumn::toColumnType(id value) const
{
if([value isKindOfClass:[NSDate class]])
return [NSDate dateWithTimeIntervalSince1970: [value timeIntervalSince1970]];
else if([value isKindOfClass:[NSNumber class]])
return [NSDate dateWithTimeIntervalSince1970: [value doubleValue]];
return nil;
}
```

Instead of just:

```objective-c
NSDate *__strong NSDateColumn::toColumnType(id value) const
{
return [NSDate dateWithTimeIntervalSince1970: [value doubleValue]];
}
```