sxross/MotionModel — pull request #61 by paulsturgess (2013-06-26 14:55:46+00:00)
Title: SQL Adapter tests and fixes

OK I've finished porting all the tests over now. So this pull request now includes the same basic set of tests as the Array Adapter. It also includes a bunch of minor fixes to get a few things working.

The `:date` column type was being ignored by the `SQLite3Adapter`, so I've updated that to be handled the same as the `:datetime`.

I added a case to handle assigning a datetime as an integer in `cast_to_date`. This means you can now do:

@instance.a_datetime = 1358197323
@instance.a_datetime.should.is_a?(NSDate)
=> true

A `create` method has been added to `RelationArray` that just does a `build` followed by a `save` returning the relation.

I found the sql couldn't handle inserting booleans that were assigned as `false` or `true` so I updated `_quoted_db_typed_attributes` in `SQLDBAdapter`. I'm not 100% sure this is the correct place, but it appears to work.

The `delete` method was not firing a notification, so I added `issue_notification(:action => 'delete')` to it. This feels like it could be implemented in some base class that all adapters inherit from. Not sure how many other adapters (if any) are planned though.

The state of play of the test suite is that there are 3 tests that error, these all error for the same reason. It looks like it is to do with the way models are converted for Formotion and then checked to see which keys that output from the conversion includes. I believe it is something to do with the comparison of each value with the symbol for the key.

The most incomplete test spec is for transactions. I can see that each sql query is executed in a transaction, but I'm not sure the rollback works when combining database updates in one transaction. I have left a commented out test in the `transaction_spec.rb` file that executes a transaction with an error raised to cause a rollback. I have commented this out because this breaks a whole bunch of other tests if this test is run along with the rest of the test suite. Is it something to do with the semaphore signal. I have to say that is all brand new to me so I can't offer much help there.

Anyway, hopefully this is all useful. Let me know if changed need to be made.