pandastream/panda_gem — pull request #14 by fullbridge-batkins (2013-02-06 00:44:15+00:00)
Title: Make :has_one method pull :cloud_id from object attributes when necessary

Currently, invoking a relationship setup using the `has_one` method on `Panda::Assocations::ClassMethods` throws this error if `Panda.connection.cloud_id` is set to `nil`:

Panda::APIError: RecordNotFound: Couldn't find Cloud with ID=

This can be observed by setting up the gem and invoking `Panda.configure` without passing in a `cloud_id`, then calling `Panda::Cloud.find('your_cloud_id').encodings.first.video`. It seemed odd to me that I could invoke `Panda::Cloud.find('your_cloud_id').videos.find('video_id')` without an error, but attempting to perform `Panda::Cloud.find('your_cloud_id').encodings.first.video` raised the aforementioned error, seeing as how the `Panda::Encoding` object had the `cloud_id` as one of it's attributes.

I have several applications where we do not pass a `cloud_id` into our `Panda.configure` block because I wish to have access to multiple encoding clouds.

This implementation makes it so the logic to find an associated object attempts to derive the `cloud_id` from the object's attributes if it is set to `nil` on `Panda.connection`. This works because both `Panda::Video` and `Panda::Encoding` objects have a `cloud_id` in their attributes, and those are the only two classes which invoke the `has_one` method from `Panda::Assocations::ClassMethods`.

I tested it with my actual panda credentials and the method seemed to work, and no errors were getting thrown in instances where they were previously. I attempted to write a test to cover this implementation, and was able to successfully, but I'm guessing the test could be improved (or others could be added) for better coverage, as I haven't worked with [WebMock](https://github.com/bblimke/webmock) before. Also, I am obviously not that well versed in the inner workings of the gem, so I figure you may be able to come up with some better tests for this, but the implementation seems to work.