spine/spine — pull request #474 by jackjennings (2013-06-21 19:53:13+00:00)
Title: Allow url and scope to be set to functions on both Spine.Model class and instance (Fixes #472)

This commit changes the Spine.Ajax module to allow both `url` and `scope` to be set at a function. So that all of the rolling work:

```coffeescript
User.scope = -> 'foo'
var user = new User id: 1
Spine.Ajax.getURL(User) is '/foo/users'
Spine.Ajax.getURL(user) is '/foo/users/1'

User.url = -> 'bar'
Spine.Ajax.getURL(User) is '/foo/bar'
Spine.Ajax.getURL(user) is '/foo/bar/1'

user.scope = -> 'baz'
Spine.Ajax.getURL(user) is '/baz/bar/1'

user.url = -> 'qux'
Spine.Ajax.getURL(user) is '/baz/qux/1'
```

The biggest issue that was preventing this from working properly before, was that the Ajax module was checking to see if `url` was set as a function in order to test if it had been changed (presumably to a string). If `url` was a function the module assumed that it should continue to the default behavior, instead of calling the function. I've introduced another function that is included on the model—`generateURL`—that mirrors the default value of `url`, so that changes to the `url` method can be checked more reliably. Not sure if this is a particularly elegant solution, but it seems to work fine.

All tests still pass without changes, so I'm pretty sure that this should be fully backwards compatible. I've added tests for the use cases that I couldn't accomplish in previous versions.