Fix partial name with namespace

Because namespace assignment was occurring after `dir = dir.dir`,
there was never a `dir.namespace`. Had to put namespace before dir
get its new value.

Also I took the liberty of adding an unit test for this bug fix.

PS: I work at Yahoo.