Custom finders should return persisted instances #32

Merged
merged 2 commits into from Feb 15, 2012

3 participants

@staugaard

The custom finders (like Chargify::Product.find_by_handle) did not return instances marked as persisted.

This prevented you from looking up an instance, modifying it and saving it, as ActiveResource would send POST requests.

@shayfrendt

These changes look good to me. I'll try to get this pulled in shortly. Thanks for adding good specs too!

@moklett
Chargify member

@staugaard Looks like the persisted flag is not available on ActiveResource in the 2.x line. Do you know if there's a good hack to trick AR for this?

@staugaard

Hmm doesn't look like it

@moklett moklett commented on an outdated diff Feb 14, 2012
lib/chargify_api_ares/resources/customer.rb
@@ -1,7 +1,7 @@
module Chargify
class Customer < Base
def self.find_by_reference(reference)
- Customer.new get(:lookup, :reference => reference)
+ Customer.new(get(:lookup, :reference => reference), true)
@moklett
Chargify member
moklett added a line comment Feb 14, 2012

I think this gets us what we really want:

Customer.find(:one, :from => :lookup, :params => {:reference => reference})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staugaard

Yes that looks good. I've updated the pull request.

@shayfrendt

@staugaard Thanks for the update! Merging and closing.

@shayfrendt shayfrendt merged commit 125ac28 into chargify:master Feb 15, 2012
@shayfrendt

FYI: I just released version 0.5.1. to rubygems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment