chargify_api_ares 0.2.1 → 0.2.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chargify_api_ares}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs"]
12
- s.date = %q{2009-12-09}
12
+ s.date = %q{2010-01-08}
13
13
  s.description = %q{}
14
14
  s.email = %q{mklett@grasshopper.com}
15
15
  s.extra_rdoc_files = [
@@ -26,13 +26,29 @@ Gem::Specification.new do |s|
26
26
  "lib/chargify_api_ares.rb",
27
27
  "samples/customers.rb",
28
28
  "samples/products.rb",
29
- "samples/subscriptions.rb"
29
+ "samples/subscriptions.rb",
30
+ "spec/base_spec.rb",
31
+ "spec/customer_spec.rb",
32
+ "spec/factories.rb",
33
+ "spec/mocks/fake_resource.rb",
34
+ "spec/product_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "spec/subscription_spec.rb"
30
37
  ]
31
38
  s.homepage = %q{http://github.com/grasshopperlabs/chargify_api_ares}
32
39
  s.rdoc_options = ["--charset=UTF-8"]
33
40
  s.require_paths = ["lib"]
34
41
  s.rubygems_version = %q{1.3.5}
35
42
  s.summary = %q{A Chargify API wrapper for Ruby using ActiveResource}
43
+ s.test_files = [
44
+ "spec/base_spec.rb",
45
+ "spec/customer_spec.rb",
46
+ "spec/factories.rb",
47
+ "spec/mocks/fake_resource.rb",
48
+ "spec/product_spec.rb",
49
+ "spec/spec_helper.rb",
50
+ "spec/subscription_spec.rb"
51
+ ]
36
52
 
37
53
  if s.respond_to? :specification_version then
38
54
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -76,7 +76,7 @@ module Chargify
76
76
 
77
77
  class Customer < Base
78
78
  def self.find_by_reference(reference)
79
- get(:lookup, :reference => reference)
79
+ Customer.new get(:lookup, :reference => reference)
80
80
  end
81
81
  end
82
82
 
@@ -96,7 +96,7 @@ module Chargify
96
96
 
97
97
  class Product < Base
98
98
  def self.find_by_handle(handle)
99
- get(:lookup, :handle => handle)
99
+ Product.new get(:lookup, :handle => handle)
100
100
  end
101
101
  end
102
- end
102
+ end
data/spec/base_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Chargify::Base do
4
+
5
+ it 'parses element names' do
6
+ Chargify::Base.stub!(:name).and_return("Test::Namespace::ElementName")
7
+ Chargify::Base.element_name.should eql('element_name')
8
+ end
9
+
10
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Chargify::Customer do
4
+
5
+ context 'find by reference' do
6
+ before do
7
+ @reference = 'ref0123'
8
+ @existing_customer = Factory(:customer, :reference => @reference, :id => Factory.next(:customer_id))
9
+ FakeWeb.register_uri(:get, "#{test_domain}/customers/lookup.xml?reference=#{@existing_customer.reference}", :body => @existing_customer.attributes.to_xml)
10
+ end
11
+
12
+ it 'finds the correct customer by reference' do
13
+ customer = Chargify::Customer.find_by_reference(@reference)
14
+ customer.should eql(@existing_customer)
15
+ end
16
+
17
+ it 'is an instance of Chargify::Customer' do
18
+ customer = Chargify::Customer.find_by_reference(@reference)
19
+ customer.should be_instance_of(Chargify::Customer)
20
+ end
21
+ end
22
+
23
+ end
data/spec/factories.rb ADDED
@@ -0,0 +1,40 @@
1
+ Factory.sequence :email do |n|
2
+ "customer#{n}@example.com"
3
+ end
4
+
5
+ Factory.sequence :customer_id do |n|
6
+ n
7
+ end
8
+
9
+ Factory.define :customer, :class => Chargify::Customer do |c|
10
+ c.first_name { Faker::Name.first_name }
11
+ c.last_name { Faker::Name.last_name }
12
+ c.email { Factory.next(:email) }
13
+ c.organization { Faker::Company.name }
14
+ c.created_at { 2.days.ago }
15
+ c.updated_at { 1.hour.ago }
16
+ end
17
+
18
+
19
+ Factory.sequence :product_id do |n|
20
+ n
21
+ end
22
+
23
+ Factory.sequence :product_name do |n|
24
+ "Product #{n}"
25
+ end
26
+
27
+ Factory.define :product, :class => Chargify::Product do |p|
28
+ p.name { Factory.next(:product_name) }
29
+ end
30
+
31
+ Factory.define :subscription, :class => Chargify::Subscription do |s|
32
+ s.balance_in_cents 500
33
+ s.current_period_ends_at 3.days.from_now
34
+ end
35
+
36
+ Factory.define :subscription_with_extra_attrs, :parent => :subscription do |swea|
37
+ swea.customer Chargify::Customer.new
38
+ swea.product Chargify::Product.new
39
+ swea.credit_card "CREDIT CARD"
40
+ end
@@ -0,0 +1,82 @@
1
+ # Taken from https://gist.github.com/238158/487a411c392e1fb2a0c00347e32444320f5cdd49
2
+ require 'FakeWeb'
3
+
4
+ module ActiveResource
5
+
6
+ #
7
+ # The FakeResource fakes ActiveResources so that no real resources are transferred. It catches the creation methods
8
+ # and stores the resources internally instead of sending to a remote service and responds these resources back on
9
+ # request.
10
+ #
11
+ # Additionally it adds a save! method and can be used in conjunction with Cucumber/Pickle/FactoryGirl to fully
12
+ # fake a back end service in the BDD cycle
13
+ #
14
+ module FakeResource
15
+
16
+ @@fake_resources = []
17
+
18
+ def self.clean
19
+ FakeWeb.clean_registry
20
+ @@fake_resources = []
21
+ end
22
+
23
+ def self.included(base)
24
+ base.class_eval do
25
+
26
+ def save
27
+ @@fake_resources << self
28
+ update_fake_responses
29
+ end
30
+
31
+ def destroy
32
+ @@fake_resources.delete(self)
33
+ update_fake_responses
34
+ end
35
+
36
+ def self.delete(id, options = {})
37
+ puts "delete"
38
+ @@fake_resources.delete_if {|r| r.id == id }
39
+ #update_fake_responses
40
+ end
41
+
42
+ def self.exists?(id, options = {})
43
+ not @@fake_resources.select {|r| r.id == id}.blank?
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ def save!
50
+ save
51
+ end
52
+
53
+ def save
54
+ super
55
+ end
56
+
57
+ private
58
+
59
+ def update_fake_responses
60
+ FakeWeb.clean_registry
61
+
62
+ @@fake_resources.each do |r|
63
+ FakeWeb.register_uri(:get, element_uri, :body => r.to_xml)
64
+ end
65
+
66
+ FakeWeb.register_uri(:get, collection_uri, :body => @@fake_resources.to_xml)
67
+ end
68
+
69
+ def element_uri
70
+ "#{base_uri}#{element_path}"
71
+ end
72
+
73
+ def collection_uri
74
+ "#{base_uri}#{collection_path}"
75
+ end
76
+
77
+ def base_uri
78
+ "#{connection.site.scheme}://#{connection.user}:#{connection.password}@#{connection.site.host}:#{connection.site.port}"
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Chargify::Product do
4
+
5
+ context 'find by handle' do
6
+ before do
7
+ @handle = 'handle1'
8
+ @existing_product = Factory(:product, :handle => @handle, :id => Factory.next(:product_id))
9
+ FakeWeb.register_uri(:get, "#{test_domain}/products/lookup.xml?handle=#{@existing_product.handle}", :body => @existing_product.attributes.to_xml)
10
+ end
11
+
12
+ it 'finds the correct product by handle' do
13
+ product = Chargify::Product.find_by_handle(@handle)
14
+ product.should eql(@existing_product)
15
+ end
16
+
17
+ it 'is an instance of Chargify::Product' do
18
+ product = Chargify::Product.find_by_handle(@handle)
19
+ product.should be_instance_of(Chargify::Product)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,28 @@
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
+
15
+ Chargify.configure do |c|
16
+ c.subdomain = 'test'
17
+ c.api_key = 'test'
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ config.after(:each) do
22
+ ActiveResource::FakeResource.clean
23
+ end
24
+ end
25
+
26
+ def test_domain
27
+ "#{Chargify::Base.connection.site.scheme}://#{Chargify::Base.connection.user}:#{Chargify::Base.connection.password}@#{Chargify::Base.connection.site.host}:#{Chargify::Base.connection.site.port}"
28
+ end
@@ -0,0 +1,44 @@
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 'cancels the subscription' do
36
+ @subscription = Factory(:subscription, :id => 1)
37
+ find_subscription = lambda { Chargify::Subscription.find(1) }
38
+
39
+ find_subscription.should_not raise_error
40
+ @subscription.cancel
41
+ find_subscription.should raise_error
42
+ end
43
+
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargify_api_ares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klett
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-09 00:00:00 -05:00
13
+ date: 2010-01-08 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -34,6 +34,13 @@ files:
34
34
  - samples/customers.rb
35
35
  - samples/products.rb
36
36
  - samples/subscriptions.rb
37
+ - spec/base_spec.rb
38
+ - spec/customer_spec.rb
39
+ - spec/factories.rb
40
+ - spec/mocks/fake_resource.rb
41
+ - spec/product_spec.rb
42
+ - spec/spec_helper.rb
43
+ - spec/subscription_spec.rb
37
44
  has_rdoc: true
38
45
  homepage: http://github.com/grasshopperlabs/chargify_api_ares
39
46
  licenses: []
@@ -62,5 +69,11 @@ rubygems_version: 1.3.5
62
69
  signing_key:
63
70
  specification_version: 3
64
71
  summary: A Chargify API wrapper for Ruby using ActiveResource
65
- test_files: []
66
-
72
+ test_files:
73
+ - spec/base_spec.rb
74
+ - spec/customer_spec.rb
75
+ - spec/factories.rb
76
+ - spec/mocks/fake_resource.rb
77
+ - spec/product_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/subscription_spec.rb