Skip to content

Commit

Permalink
Merge pull request #23 from realpractice/product_family_components
Browse files Browse the repository at this point in the history
Added nested component resource under product families.
  • Loading branch information
shayfrendt committed Oct 19, 2011
2 parents 2a53e65 + bb31f4b commit dbffedb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/chargify_api_ares.rb
Expand Up @@ -68,6 +68,7 @@ def configure
Subscription::Statement.site = site + "/subscriptions/:subscription_id"
Subscription::Transaction.site = site + "/subscriptions/:subscription_id"
Coupon.site = site + "/product_families/:product_family_id"
ProductFamily::Component.site = site + "/product_families/:product_family_id"
end
end

Expand Down Expand Up @@ -247,6 +248,15 @@ class ProductFamily < Base
def self.find_by_handle(handle, attributes = {})
ProductFamily.find(:one, :from => :lookup, :handle => handle)
end

class Component < Base
end

def components(params = {})
params.merge!({:product_family_id => self.id})
::Chargify::ProductFamily::Component.find(:all, :params => params)
end

end

class Usage < Base
Expand Down
33 changes: 33 additions & 0 deletions spec/product_families_component_spec.rb
@@ -0,0 +1,33 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Chargify::Subscription::Component do
before(:each) do
@product_family = Chargify::ProductFamily.new(:id => 1)
@component = Chargify::ProductFamily::Component.new(
:id => 2,
:name => "Purple Widgets",
:pricing_scheme => "per_unit",
:product_family_id => 1,
:unit_name => "purple widget",
:unit_price => 2.99,
:kind => "quantity_based_component",
:prices => []
)

@product_family_components = [ @component ]

end

describe "listing subscription components" do
before(:each) do
FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{@product_family.id}.xml", :body => @product_family.to_xml)
FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{@product_family.id}/components.xml", :body => @product_family_components.to_xml(:root => 'components'))
end

it "returns an array of components from Chargify::ProductFamily.find(1).components" do
product_family = Chargify::ProductFamily.find(@product_family.id)
product_family.components.should == @product_family_components
end

end
end

0 comments on commit dbffedb

Please sign in to comment.