angular/angular.js — pull request #2459 by Illniyar (2013-04-20 21:01:56+00:00)
Title: Setting cookie attributes in $cookieStore

As a response to issues: 1786,950,1918,1320
This PR enables setting a cookie's path and expires attributes using the $cookieStore service.
$cookies was not changed, since it's API is too strict, I could find no way to implement it without causing breaking changes, or using some terrible hacks.
I would suggest adding a new service to the module to support more advanced features (such as Json $watch expression, which should be more useful then binding the $cookies object directly), but this would probably require a bit of research regarding use cases.

Some things to note regarding the implementation:
* urlroot (karma property) was added to all unit tests - to facilitate testing of different cookie path
* Backward incompatible change (bad fixing a bad behaviour):
delete cookie now deletes cookies set with a path other then / (or baseHref)
that is before the fix, if you had a cookie set on path /karma (if it was added by the server for instance),
you would be able to see it, but deleting it will fail silently (and will not delete)
delete cookie now deletes duplicate cookies with the same name (if they have different paths)
* Due to the fact that no browser allows inspecting the Path and Expiration date of a cookie, I chose to add a private _setCookie function inside the $browser module
which I override in unit tests. Not the most elegent solution, but the only other way to check Expiration is to mock the document object and change how document.cookie works, and that would have taken me too long for very little benefit.

Design decisions:
* to change the path and/or expiration date of a cookie, you can pass an options object as the third argument to cookies(name,value)
the options object can override Path and Expires when adding a value, all other options variables are ignored (but are allowed, I.E. no validation is made).
You can pass either path, expires,none or both.
* the path option is checked to be a string and be partial to window.location, otherwise, the default path is used. (warning is logged)
* the expires option is checked to be a Date and in the future, otherwise no expiration is set. (warning is logged)
* at the moment no support for non-Date expires is supported (for instance such as maxAge, or a number to indicate number of millesconds for cookie to last)
* you can now delete a cookie on a specific path by calling cookie(name,undefined,options), with options containing path
* only the $cookieStore service will support putting cookies with different path/expiration (as well as deleting certain paths.
this is to support backward compatability with $cookies.

Notes:
if the value passed to browser.cookies is not a String, it fails silently.

This is my first time contributing here (and on a Major open source project), I hope this can be incorporated.
I'm more than happy to make changes if something is wrong, so please let me know.