Permalink
Browse files

Merge pull request #32 from staugaard/master

Custom finders should return persisted instances
  • Loading branch information...
2 parents b022731 + f48559e commit 125ac28aa53dc247611280c02152946cc73b89d6 @shayfrendt shayfrendt committed Feb 15, 2012
@@ -5,7 +5,7 @@ def self.find_all_by_product_family_id(product_family_id)
end
def self.find_by_product_family_id_and_code(product_family_id, code)
- Coupon.new get(:lookup, :product_family_id => product_family_id, :code => code)
+ find(:one, :from => :lookup, :params => {:product_family_id => product_family_id, :code => code})
end
def usage
@@ -1,7 +1,7 @@
module Chargify
class Customer < Base
def self.find_by_reference(reference)
- Customer.new get(:lookup, :reference => reference)
+ find(:one, :from => :lookup, :params => {:reference => reference})
end
class Subscription < Base
@@ -1,7 +1,7 @@
module Chargify
class Product < Base
def self.find_by_handle(handle)
- Product.new get(:lookup, :handle => handle)
+ find(:one, :from => :lookup, :params => {:handle => handle})
end
protected
@@ -16,6 +16,11 @@
coupon = Chargify::Coupon.find_by_product_family_id_and_code(10, '20OFF')
coupon.should be_instance_of(Chargify::Coupon)
end
+
+ it 'is marked as persisted' do
+ coupon = Chargify::Coupon.find_by_product_family_id_and_code(10, '20OFF')
+ coupon.persisted?.should == true
+ end
end
context '.find_all_by_product_family_id' do
@@ -17,6 +17,11 @@
customer = Chargify::Customer.find_by_reference('sigma')
customer.should be_instance_of(Chargify::Customer)
end
+
+ it 'is marked as persisted' do
+ customer = Chargify::Customer.find_by_reference('sigma')
+ customer.persisted?.should == true
+ end
end
context "#subscriptions" do
@@ -18,6 +18,11 @@
product = Chargify::Product.find_by_handle('green-money')
product.should be_instance_of(Chargify::Product)
end
+
+ it 'is marked as persisted' do
+ product = Chargify::Product.find_by_handle('green-money')
+ product.persisted?.should == true
+ end
end
end

0 comments on commit 125ac28

Please sign in to comment.