Permalink
Browse files

Restore Chargify::Coupon.find_all_by_product_family_id functionality

  • Loading branch information...
1 parent a737db8 commit c81d5dcdfb0624ed74a1aac20b252ff35bc8aadb @shayfrendt shayfrendt committed Nov 4, 2011
Showing with 19 additions and 0 deletions.
  1. +4 −0 lib/chargify_api_ares/resources/coupon.rb
  2. +15 −0 spec/resources/coupon_spec.rb
@@ -1,5 +1,9 @@
module Chargify
class Coupon < Base
+ def self.find_all_by_product_family_id(product_family_id)
+ Coupon.find(:all, :params => { :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)
end
@@ -17,4 +17,19 @@
coupon.should be_instance_of(Chargify::Coupon)
end
end
+
+ context '.find_all_by_product_family_id' do
+ let(:coupon_1) { Factory.build(:coupon, :product_family_id => 5) }
+ let(:coupon_2) { Factory.build(:coupon, :product_family_id => 5) }
+
+ before do
+ FakeWeb.register_uri(:get, "#{test_domain}/coupons.xml?product_family_id=5", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
+ end
+
+ it "returns all of the coupons for a product family" do
+ coupons = Chargify::Coupon.find_all_by_product_family_id(5)
+ coupons.count.should == 2
+ coupons.map{|c| c.should be_instance_of(Chargify::Coupon)}
+ end
+ end
end

0 comments on commit c81d5dc

Please sign in to comment.