vitalish-chargify_api_ares 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/chargify_api_ares.gemspec +75 -0
- data/config/remote.example.yml +7 -0
- data/lib/chargify_api_ares.rb +277 -0
- data/samples/customers.rb +51 -0
- data/samples/metered_components.rb +35 -0
- data/samples/products.rb +24 -0
- data/samples/subscriptions.rb +53 -0
- data/samples/transactions.rb +17 -0
- data/spec/base_spec.rb +10 -0
- data/spec/components_spec.rb +48 -0
- data/spec/customer_spec.rb +23 -0
- data/spec/factories.rb +62 -0
- data/spec/mocks/fake_resource.rb +82 -0
- data/spec/product_spec.rb +23 -0
- data/spec/remote/remote_spec.rb +514 -0
- data/spec/remote/spec_helper.rb +37 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/subscription_spec.rb +78 -0
- data/spec/subscriptions_component_spec.rb +82 -0
- data/vitalish-chargify_api_ares.gemspec +75 -0
- metadata +106 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
5
|
+
|
6
|
+
require 'chargify_api_ares'
|
7
|
+
|
8
|
+
Spec::Runner.configure do |config|
|
9
|
+
config.before(:all) do
|
10
|
+
Chargify.configure do |c|
|
11
|
+
c.subdomain = remote_configuration['subdomain']
|
12
|
+
c.api_key = remote_configuration['api_key']
|
13
|
+
if remote_configuration['site']
|
14
|
+
c.site = remote_configuration['site']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def run_remote_tests?
|
21
|
+
remote_configuration['run_tests'] === true
|
22
|
+
end
|
23
|
+
|
24
|
+
def remote_configuration
|
25
|
+
@remote_configuration ||= load_remote_configuration_file
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def load_remote_configuration_file
|
31
|
+
configuration_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'remote.yml'))
|
32
|
+
if File.exist?(configuration_file)
|
33
|
+
YAML.load_file(configuration_file)
|
34
|
+
else
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
|
6
|
+
require 'chargify_api_ares'
|
7
|
+
|
8
|
+
require 'fakeweb'
|
9
|
+
require 'mocks/fake_resource'
|
10
|
+
ActiveResource::Base.send :include, ActiveResource::FakeResource
|
11
|
+
FakeWeb.allow_net_connect = false
|
12
|
+
require 'factory_girl'
|
13
|
+
require 'faker'
|
14
|
+
require 'factories'
|
15
|
+
|
16
|
+
Chargify.configure do |c|
|
17
|
+
c.subdomain = 'test'
|
18
|
+
c.api_key = 'test'
|
19
|
+
end
|
20
|
+
|
21
|
+
Spec::Runner.configure do |config|
|
22
|
+
config.after(:each) do
|
23
|
+
ActiveResource::FakeResource.clean
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_domain
|
28
|
+
"#{Chargify::Base.connection.site.scheme}://#{Chargify::Base.connection.user}:#{Chargify::Base.connection.password}@#{Chargify::Base.connection.site.host}:#{Chargify::Base.connection.site.port}"
|
29
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Chargify::Subscription do
|
4
|
+
|
5
|
+
context 'strips nested association attributes before saving' do
|
6
|
+
before do
|
7
|
+
@subscription = Factory.build(:subscription_with_extra_attrs)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'strips customer' do
|
11
|
+
@subscription.attributes['customer'].should_not be_blank
|
12
|
+
@subscription.save!
|
13
|
+
@subscription.attributes['customer'].should be_blank
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'strips product' do
|
17
|
+
@subscription.attributes['product'].should_not be_blank
|
18
|
+
@subscription.save!
|
19
|
+
@subscription.attributes['product'].should be_blank
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'strips credit card' do
|
23
|
+
@subscription.attributes['credit_card'].should_not be_blank
|
24
|
+
@subscription.save!
|
25
|
+
@subscription.attributes['credit_card'].should be_blank
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'doesn\'t strip other attrs' do
|
29
|
+
subscription = Factory.build(:subscription)
|
30
|
+
|
31
|
+
lambda { subscription.save! }.should_not change(subscription, :attributes)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'creates a one-time charge' do
|
36
|
+
id = Factory.next(:subscription_id)
|
37
|
+
subscription = Factory(:subscription, :id => id)
|
38
|
+
expected_response = {:charge => {:amount_in_cents => 1000, :memo => "one-time charge", :success => true}}.to_xml
|
39
|
+
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/charges.xml?charge%5Bamount%5D=10.00&charge%5Bmemo%5D=one-time+charge", :status => 201, :body => expected_response)
|
40
|
+
|
41
|
+
response = subscription.charge(:amount => "10.00", "memo" => "one-time charge")
|
42
|
+
|
43
|
+
response.body.should == expected_response
|
44
|
+
response.should be_a(Net::HTTPCreated)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'finds by customer reference' do
|
48
|
+
customer = Factory(:customer, :reference => 'roger', :id => 10)
|
49
|
+
subscription = Factory(:subscription, :id => 11, :customer_id => customer.id, :product => Factory(:product))
|
50
|
+
|
51
|
+
expected_response = [subscription.attributes].to_xml(:root => 'subscriptions')
|
52
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions.xml?customer_id=#{customer.id}", :status => 200, :body => expected_response)
|
53
|
+
|
54
|
+
Chargify::Customer.stub!(:find_by_reference).with('roger').and_return(customer)
|
55
|
+
Chargify::Subscription.find_by_customer_reference('roger').should eql(subscription)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'cancels the subscription' do
|
59
|
+
@subscription = Factory(:subscription, :id => 1)
|
60
|
+
find_subscription = lambda { Chargify::Subscription.find(1) }
|
61
|
+
|
62
|
+
find_subscription.should_not raise_error
|
63
|
+
@subscription.cancel
|
64
|
+
find_subscription.should raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'migrates the subscription' do
|
68
|
+
id = Factory.next(:subscription_id)
|
69
|
+
subscription = Factory(:subscription, :id => id)
|
70
|
+
expected_response = [subscription.attributes].to_xml(:root => 'subscription')
|
71
|
+
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/migrations.xml?migration%5Bproduct_handle%5D=upgraded-plan", :status => 201, :body => expected_response)
|
72
|
+
|
73
|
+
response = subscription.migrate(:product_handle => 'upgraded-plan')
|
74
|
+
|
75
|
+
response.body.should == expected_response
|
76
|
+
response.should be_a(Net::HTTPCreated)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Chargify::Subscription::Component do
|
4
|
+
before(:each) do
|
5
|
+
@subscription = Chargify::Subscription.new(:id => 1)
|
6
|
+
@sc1 = Chargify::Subscription::Component.new(
|
7
|
+
:subscription_id => @subscription.id,
|
8
|
+
:component_id => 1,
|
9
|
+
:allocated_quantity => 0,
|
10
|
+
:name => "Paying Customers",
|
11
|
+
:unit_name => "customers",
|
12
|
+
:component_type => "quantity_based_component",
|
13
|
+
:pricing_scheme => "stairstep"
|
14
|
+
)
|
15
|
+
@sc2 = Chargify::Subscription::Component.new(
|
16
|
+
:subscription_id => @subscription.id,
|
17
|
+
:component_id => 2,
|
18
|
+
:unit_balance => 0,
|
19
|
+
:name => "Text Messages",
|
20
|
+
:unit_name => "text message",
|
21
|
+
:component_type => "metered_component"
|
22
|
+
)
|
23
|
+
@subscriptions_components = [@sc1, @sc2]
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "listing subscription components" do
|
27
|
+
before(:each) do
|
28
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}.xml", :body => @subscription.to_xml)
|
29
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components.xml", :body => @subscriptions_components.to_xml(:root => 'components'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns an array of components from Chargify::Subscription::Component.find(:all, :params => {:subscription_id => @subscription.id})" do
|
33
|
+
Chargify::Subscription::Component.find(:all, :params => {:subscription_id => @subscription.id}).should == @subscriptions_components
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns an array of components from Chargify::Subscription.find(2).components" do
|
37
|
+
subscription = Chargify::Subscription.find(@subscription.id)
|
38
|
+
subscription.components.should == @subscriptions_components
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "reading a subscription component" do
|
43
|
+
before(:each) do
|
44
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}.xml", :body => @subscription.to_xml)
|
45
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1.to_xml)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns the subscription's component resource from Chargify::Subscription::Component.find(1, :params => {:subscription_id => 1})" do
|
49
|
+
Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id}).should == @sc1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns the subscription's component resource from Chargify::Subscription.find(1).component(1)" do
|
53
|
+
subscription = Chargify::Subscription.find(@subscription.id)
|
54
|
+
subscription.component(@sc1.component_id).should == @sc1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "updating a subscription component" do
|
59
|
+
before(:each) do
|
60
|
+
@new_allocated_quantity = @sc1.allocated_quantity + 5
|
61
|
+
|
62
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}.xml", :body => @subscription.to_xml)
|
63
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1.to_xml)
|
64
|
+
|
65
|
+
@sc1_prime = @sc1
|
66
|
+
@sc1_prime.allocated_quantity = @new_allocated_quantity
|
67
|
+
|
68
|
+
FakeWeb.register_uri(:put, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1_prime.to_xml)
|
69
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/#{@subscription.id}/components/#{@sc1.component_id}.xml", :body => @sc1_prime.to_xml)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "updates the subscription's component allocated quantity" do
|
73
|
+
component = Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id})
|
74
|
+
component.allocated_quantity = @new_allocated_quantity
|
75
|
+
|
76
|
+
result = component.save
|
77
|
+
result.should be_true
|
78
|
+
|
79
|
+
Chargify::Subscription::Component.find(@sc1.component_id, :params => {:subscription_id => @subscription.id}).should == @sc1_prime
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{vitalish-chargify_api_ares}
|
8
|
+
s.version = "0.3.9"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose", "Nathan Verni"]
|
12
|
+
s.date = %q{2011-03-14}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{mklett@grasshopper.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rvmrc",
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"chargify_api_ares.gemspec",
|
26
|
+
"config/remote.example.yml",
|
27
|
+
"lib/chargify_api_ares.rb",
|
28
|
+
"samples/customers.rb",
|
29
|
+
"samples/metered_components.rb",
|
30
|
+
"samples/products.rb",
|
31
|
+
"samples/subscriptions.rb",
|
32
|
+
"samples/transactions.rb",
|
33
|
+
"spec/base_spec.rb",
|
34
|
+
"spec/components_spec.rb",
|
35
|
+
"spec/customer_spec.rb",
|
36
|
+
"spec/factories.rb",
|
37
|
+
"spec/mocks/fake_resource.rb",
|
38
|
+
"spec/product_spec.rb",
|
39
|
+
"spec/remote/remote_spec.rb",
|
40
|
+
"spec/remote/spec_helper.rb",
|
41
|
+
"spec/spec.opts",
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"spec/subscription_spec.rb",
|
44
|
+
"spec/subscriptions_component_spec.rb",
|
45
|
+
"vitalish-chargify_api_ares.gemspec"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/grasshopperlabs/chargify_api_ares}
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.7}
|
50
|
+
s.summary = %q{A Chargify API wrapper for Ruby using ActiveResource}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/base_spec.rb",
|
53
|
+
"spec/components_spec.rb",
|
54
|
+
"spec/customer_spec.rb",
|
55
|
+
"spec/factories.rb",
|
56
|
+
"spec/mocks/fake_resource.rb",
|
57
|
+
"spec/product_spec.rb",
|
58
|
+
"spec/remote/remote_spec.rb",
|
59
|
+
"spec/remote/spec_helper.rb",
|
60
|
+
"spec/spec_helper.rb",
|
61
|
+
"spec/subscription_spec.rb",
|
62
|
+
"spec/subscriptions_component_spec.rb"
|
63
|
+
]
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
|
+
else
|
71
|
+
end
|
72
|
+
else
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vitalish-chargify_api_ares
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 9
|
10
|
+
version: 0.3.9
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Klett
|
14
|
+
- The Lab Rats @ Phase Two Labs
|
15
|
+
- Brian Rose
|
16
|
+
- Nathan Verni
|
17
|
+
autorequire:
|
18
|
+
bindir: bin
|
19
|
+
cert_chain: []
|
20
|
+
|
21
|
+
date: 2011-03-14 00:00:00 +02:00
|
22
|
+
default_executable:
|
23
|
+
dependencies: []
|
24
|
+
|
25
|
+
description: ""
|
26
|
+
email: mklett@grasshopper.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE.txt
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- .rvmrc
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- chargify_api_ares.gemspec
|
41
|
+
- config/remote.example.yml
|
42
|
+
- lib/chargify_api_ares.rb
|
43
|
+
- samples/customers.rb
|
44
|
+
- samples/metered_components.rb
|
45
|
+
- samples/products.rb
|
46
|
+
- samples/subscriptions.rb
|
47
|
+
- samples/transactions.rb
|
48
|
+
- spec/base_spec.rb
|
49
|
+
- spec/components_spec.rb
|
50
|
+
- spec/customer_spec.rb
|
51
|
+
- spec/factories.rb
|
52
|
+
- spec/mocks/fake_resource.rb
|
53
|
+
- spec/product_spec.rb
|
54
|
+
- spec/remote/remote_spec.rb
|
55
|
+
- spec/remote/spec_helper.rb
|
56
|
+
- spec/spec.opts
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
- spec/subscription_spec.rb
|
59
|
+
- spec/subscriptions_component_spec.rb
|
60
|
+
- vitalish-chargify_api_ares.gemspec
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/grasshopperlabs/chargify_api_ares
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: A Chargify API wrapper for Ruby using ActiveResource
|
95
|
+
test_files:
|
96
|
+
- spec/base_spec.rb
|
97
|
+
- spec/components_spec.rb
|
98
|
+
- spec/customer_spec.rb
|
99
|
+
- spec/factories.rb
|
100
|
+
- spec/mocks/fake_resource.rb
|
101
|
+
- spec/product_spec.rb
|
102
|
+
- spec/remote/remote_spec.rb
|
103
|
+
- spec/remote/spec_helper.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/subscription_spec.rb
|
106
|
+
- spec/subscriptions_component_spec.rb
|