cloudfoundry/cloud_controller_ng — pull request #40 by youngm (2013-04-23 19:18:49+00:00)
Title: Convert route.host to support nil value.

This patch is part of my work to support Oracle in the Cloud Controller.

While doing the conversion work I discovered another annoying Oracle feature where an empty varchar is equal to null. If you insert an empty string into oracle it will insert null into the column and fail any not null constraints you may have associated with the column.

I scanned through all of the CC code and pretty much all not null var chars are also validated as "validates_presence", which should be compatible with this Oracle behavior, except for Route.host.

From what I could gather by looking at the code, Route.Host is not null but default "". It seems that the purpose of this behavior is to assign "" the value of no host to ensure that a "validate_unique" against host and domain_id will always work.

In oracle this functionality is duplicated by using a null value since null == "". But in other databases you need to be sure that only "" or null is put in the database.

So in this patch I've actually changed the behavior of the Route model to allow for nil as a host value. Then I use a "before_save" hook to always switch nil with "". And provide a function to only present host as an "" regardless of if it is nil or empty.

I then updated the subsequent tests to make host nilable and added a few more test to ensure that when a route is queried a nil value will be an empty string.