fake_chargify 0.1.0

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.
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe "FakeChargify::Product" do
4
+ describe ".to_xml" do
5
+ it "returns xml from object properties" do
6
+ product = FakeChargify::Product.new
7
+ product.accounting_code = '1234'
8
+ product.handle = 'Starter'
9
+ product.interval = 4
10
+ product.name = 'Subscription'
11
+ product.price_in_cents = 897
12
+ product.family = FakeChargify::ProductFamily.new
13
+ product.family.accounting_code = '1234'
14
+ product.family.handle = 'Starter'
15
+ product.family.name = 'Subscription'
16
+ product.to_xml.gsub(/\s/,'').should ==
17
+ """
18
+ <?xml version=\"1.0\"?>
19
+ <product>
20
+ <accounting_code>1234</accounting_code>
21
+ <handle>Starter</handle>
22
+ <interval>4</interval>
23
+ <name>Subscription</name>
24
+ <price_in_cents>897</price_in_cents>
25
+ <product_family>
26
+ <accounting_code>1234</accounting_code>
27
+ <handle>Starter</handle>
28
+ <name>Subscription</name>
29
+ </product_family>
30
+ </product>
31
+ """.gsub(/\s/,'')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe "chargify_api_ares gem" do
4
+ before(:each) do
5
+ FakeChargify.activate!
6
+ end
7
+
8
+ describe "Chargify::Subscription.statements" do
9
+ it "finds all the statements for a given subscription" do
10
+ Chargify::Subscription.create(
11
+ :id => 1,
12
+ :customer_reference => 'jblow',
13
+ :product_handle => 'Starter',
14
+ :credit_card_attributes => {
15
+ :first_name => "Lester",
16
+ :last_name => "Tester",
17
+ :expiration_month => 1,
18
+ :expiration_year => 2020,
19
+ :full_number => "1"
20
+ }
21
+ )
22
+ subscription = FakeChargify.subscriptions.repository.select { |s| s.id == 1 }.first
23
+ statement = FakeChargify::Statement.new(
24
+ :id => 1,
25
+ :subscription_id => subscription.id
26
+ )
27
+ FakeChargify.statements.repository << statement
28
+
29
+ subscription = Chargify::Subscription.find 1
30
+ statements = subscription.statements
31
+ statements.count.should == 1
32
+ statements[0].id.should == '1'
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "FakeChargify::Statement" do
38
+ describe ".to_xml" do
39
+ it "returns xml from object properties" do
40
+ statement = FakeChargify::Statement.new(
41
+ :id => 1,
42
+ :subscription_id => 1
43
+ )
44
+ statement.to_xml.gsub(/\s/,'').should ==
45
+ """
46
+ <?xml version=\"1.0\"?>
47
+ <statement>
48
+ <id>1</id>
49
+ <subscription_id>1</subscription_id>
50
+ <opened_at></opened_at>
51
+ <closed_at></closed_at>
52
+ <settled_at></settled_at>
53
+ <text_view></text_view>
54
+ <basic_html_view></basic_html_view>
55
+ <html_view></html_view>
56
+ <starting_balance_in_cents></starting_balance_in_cents>
57
+ <ending_balance_in_cents></ending_balance_in_cents>
58
+ <customer_first_name></customer_first_name>
59
+ <customer_last_name></customer_last_name>
60
+ <customer_organization></customer_organization>
61
+ <customer_shipping_address></customer_shipping_address>
62
+ <customer_shipping_address_2></customer_shipping_address_2>
63
+ <customer_shipping_city></customer_shipping_city>
64
+ <customer_shipping_state></customer_shipping_state>
65
+ <customer_shipping_country></customer_shipping_country>
66
+ <customer_shipping_zip></customer_shipping_zip>
67
+ <customer_billing_address></customer_billing_address>
68
+ <customer_billing_address_2></customer_billing_address_2>
69
+ <customer_billing_city></customer_billing_city>
70
+ <customer_billing_state></customer_billing_state>
71
+ <customer_billing_country></customer_billing_country>
72
+ <customer_billing_zip></customer_billing_zip>
73
+ <created_at></created_at>
74
+ <updated_at></updated_at>
75
+ </statement>
76
+ """.gsub(/\s/,'')
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,195 @@
1
+ require 'spec_helper'
2
+
3
+ describe "chargify_api_ares gem" do
4
+ before(:each) do
5
+ FakeChargify.activate!
6
+ end
7
+
8
+ describe "Chargify::Subscription.create" do
9
+ it "returns the correct values" do
10
+ subscription = Chargify::Subscription.create(
11
+ :customer_reference => 'jblow',
12
+ :product_handle => 'Starter',
13
+ :credit_card_attributes => {
14
+ :first_name => "Lester",
15
+ :last_name => "Tester",
16
+ :expiration_month => 1,
17
+ :expiration_year => 2020,
18
+ :full_number => "1"
19
+ }
20
+ )
21
+ subscription.customer_reference.should == 'jblow'
22
+ subscription.product_handle.should == 'Starter'
23
+ end
24
+ end
25
+
26
+ describe "Chargify::Subscription.find" do
27
+ it "returns the correct values" do
28
+ subscription = Chargify::Subscription.create(
29
+ :customer_reference => 'jblow',
30
+ :product_handle => 'Starter',
31
+ :credit_card_attributes => {
32
+ :first_name => "Lester",
33
+ :last_name => "Tester",
34
+ :expiration_month => 1,
35
+ :expiration_year => 2020,
36
+ :full_number => "1"
37
+ }
38
+ )
39
+ subscriptions = Chargify::Subscription.find(:all)
40
+ subscriptions.count.should == 1
41
+ end
42
+ end
43
+
44
+ describe "Chargify::Subscription.show" do
45
+ it "returns the correct values" do
46
+ Chargify::Subscription.create(
47
+ :id => 1,
48
+ :customer_reference => 'jblow',
49
+ :product_handle => 'Starter',
50
+ :credit_card_attributes => {
51
+ :first_name => "Lester",
52
+ :last_name => "Tester",
53
+ :expiration_month => 1,
54
+ :expiration_year => 2020,
55
+ :full_number => "1"
56
+ }
57
+ )
58
+ subscription = Chargify::Subscription.find 1
59
+ subscription.credit_card.expiration_month.should == '1'
60
+ subscription.credit_card.expiration_year.should == '2020'
61
+ subscription.credit_card.masked_card_number.should == 'XXXX-XXXX-XXXX-1'
62
+ end
63
+ end
64
+
65
+ describe "Chargify::Subscription.update" do
66
+ it "returns the correct values" do
67
+ subscription = Chargify::Subscription.create(
68
+ :id => 2,
69
+ :product_handle => 'Starter',
70
+ :credit_card_attributes => {
71
+ :first_name => "Lester",
72
+ :last_name => "Tester",
73
+ :expiration_month => 1,
74
+ :expiration_year => 2020,
75
+ :full_number => "1"
76
+ }
77
+ )
78
+ subscription.balance_in_cents = 1000
79
+ subscription.save
80
+ subscription = Chargify::Subscription.find 2
81
+ subscription.balance_in_cents.should == '1000'
82
+ end
83
+ end
84
+
85
+ describe "Chargify::Subscription.cancel" do
86
+ it "returns the correct values" do
87
+ subscription = Chargify::Subscription.create(
88
+ :id => 3,
89
+ :product_handle => 'Starter',
90
+ :credit_card_attributes => {
91
+ :first_name => "Lester",
92
+ :last_name => "Tester",
93
+ :expiration_month => 1,
94
+ :expiration_year => 2020,
95
+ :full_number => "1"
96
+ }
97
+ )
98
+ subscription.cancel
99
+ lambda { Chargify::Subscription.find(3) }.should raise_error
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "FakeChargify::Subscription" do
105
+ describe ".to_xml" do
106
+ it "returns xml from object properties" do
107
+ subscription = FakeChargify::Subscription.new
108
+ subscription.id = 5
109
+ subscription.state = 'active'
110
+ subscription.balance_in_cents = 39
111
+ subscription.customer = FakeChargify::Customer.new
112
+ subscription.customer.id = 6
113
+ subscription.customer.first_name = 'Joe'
114
+ subscription.customer.last_name = 'Blow'
115
+ subscription.customer.email = 'joe@example.com'
116
+ subscription.product = FakeChargify::Product.new
117
+ subscription.product.accounting_code = '1234'
118
+ subscription.product.handle = 'Starter'
119
+ subscription.product.interval = 4
120
+ subscription.product.name = 'Subscription'
121
+ subscription.product.price_in_cents = 897
122
+ subscription.product.family = FakeChargify::ProductFamily.new
123
+ subscription.product.family.accounting_code = '1234'
124
+ subscription.product.family.handle = 'Starter'
125
+ subscription.product.family.name = 'Subscription'
126
+ subscription.to_xml.gsub(/\s/,'').should ==
127
+ """
128
+ <?xml version=\"1.0\"?>
129
+ <subscription>
130
+ <id>5</id>
131
+ <state>active</state>
132
+ <balance_in_cents>39</balance_in_cents>
133
+ <current_period_started_at></current_period_started_at>
134
+ <current_period_ends_at></current_period_ends_at>
135
+ <trial_started_at></trial_started_at>
136
+ <trial_ended_at></trial_ended_at>
137
+ <activated_at></activated_at>
138
+ <expires_at></expires_at>
139
+ <created_at></created_at>
140
+ <updated_at></updated_at>
141
+ <customer>
142
+ <id>6</id>
143
+ <first_name>Joe</first_name>
144
+ <last_name>Blow</last_name>
145
+ <email>joe@example.com</email>
146
+ <organization />
147
+ <reference />
148
+ <created_at />
149
+ <updated_at />
150
+ </customer>
151
+ <product>
152
+ <accounting_code>1234</accounting_code>
153
+ <handle>Starter</handle>
154
+ <interval>4</interval>
155
+ <name>Subscription</name>
156
+ <price_in_cents>897</price_in_cents>
157
+ <product_family>
158
+ <accounting_code>1234</accounting_code>
159
+ <handle>Starter</handle>
160
+ <name>Subscription</name>
161
+ </product_family>
162
+ </product>
163
+ </subscription>
164
+ """.gsub(/\s/,'')
165
+ end
166
+ end
167
+
168
+ describe ".from_xml" do
169
+ it "parses valid xml and sets properties" do
170
+ subscription = FakeChargify::Subscription.from_xml """
171
+ <?xml version='1.0' encoding='UTF-8'?>
172
+ <subscription>
173
+ <product_handle>Starter</product_handle>
174
+ <customer_attributes>
175
+ <first_name>Joe</first_name>
176
+ <last_name>Blow</last_name>
177
+ <email>joe@example.com</email>
178
+ </customer_attributes>
179
+ <credit_card_attributes>
180
+ <full_number>1</full_number>
181
+ <expiration_month>10</expiration_month>
182
+ <expiration_year>2020</expiration_year>
183
+ </credit_card_attributes>
184
+ </subscription>
185
+ """
186
+ subscription.product.handle.should == 'Starter'
187
+ subscription.customer.first_name.should == 'Joe'
188
+ subscription.customer.last_name.should == 'Blow'
189
+ subscription.customer.email.should == 'joe@example.com'
190
+ subscription.credit_card.masked_card_number.should == 'XXXX-XXXX-XXXX-1'
191
+ subscription.credit_card.expiration_month.should == 10
192
+ subscription.credit_card.expiration_year.should == 2020
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe FakeChargify do
5
+ describe ".activate!" do
6
+ it "activates fake web requests" do
7
+ FakeChargify.activate!
8
+ lambda { Net::HTTP.get('example.com', '/index.html') }.should raise_error WebMock::NetConnectNotAllowedError
9
+ end
10
+ end
11
+
12
+ describe ".activate=" do
13
+ it "deactivates fake web requests" do
14
+ FakeChargify.activate = false
15
+ lambda { Net::HTTP.get('example.com', '/index.html') }.should_not raise_error WebMock::NetConnectNotAllowedError
16
+ end
17
+ end
18
+
19
+ describe ".clear!" do
20
+ it "clears the customers" do
21
+ FakeChargify.customers.repository << FakeChargify::Customer.new
22
+ FakeChargify.customers.repository.count.should == 1
23
+ FakeChargify.clear!
24
+ FakeChargify.customers.repository.count.should == 0
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'rspec'
2
+ require 'fake_chargify'
3
+
4
+ require 'chargify_api_ares'
5
+
6
+ Chargify.configure do |c|
7
+ c.subdomain = 'test'
8
+ c.api_key = 'api'
9
+ end
10
+
11
+ FakeChargify.configure do |c|
12
+ c.subdomain = Chargify.subdomain
13
+ c.api_key = Chargify.api_key
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.before { FakeChargify.clear! }
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "String" do
4
+ describe ".last" do
5
+ it "returns last characters for a string with enough characters" do
6
+ "123456".last(4).should == "3456"
7
+ end
8
+
9
+ it "returns last characters for a string with just enough characters" do
10
+ "12".last(2).should == "12"
11
+ end
12
+
13
+ it "returns last characters for a string with not enough characters" do
14
+ "123456".last(9).should == "123456"
15
+ end
16
+
17
+ it "returns empty string for an empty string" do
18
+ "".last(123).should == ""
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_chargify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jamie Wright
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-11-29 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: webmock
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 7
30
+ - 8
31
+ version: 1.7.8
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: nokogiri
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 5
44
+ - 0
45
+ version: 1.5.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: A helper for faking web requests and responses to and from the Chargify API.
49
+ email: jamie@brilliantfantastic.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README.md
56
+ files:
57
+ - Gemfile
58
+ - Rakefile
59
+ - fake_chargify.gemspec
60
+ - lib/fake_chargify.rb
61
+ - lib/fake_chargify/configuration.rb
62
+ - lib/fake_chargify/credit_card.rb
63
+ - lib/fake_chargify/customer.rb
64
+ - lib/fake_chargify/customer_registry.rb
65
+ - lib/fake_chargify/product.rb
66
+ - lib/fake_chargify/product_family.rb
67
+ - lib/fake_chargify/statement.rb
68
+ - lib/fake_chargify/statement_registry.rb
69
+ - lib/fake_chargify/string_patches.rb
70
+ - lib/fake_chargify/subscription.rb
71
+ - lib/fake_chargify/subscription_registry.rb
72
+ - lib/fake_chargify/url_parser.rb
73
+ - readme.md
74
+ - spec/fake_chargify/configuration_spec.rb
75
+ - spec/fake_chargify/credit_card_spec.rb
76
+ - spec/fake_chargify/customer_spec.rb
77
+ - spec/fake_chargify/product_family_spec.rb
78
+ - spec/fake_chargify/product_spec.rb
79
+ - spec/fake_chargify/statement_spec.rb
80
+ - spec/fake_chargify/subscription_spec.rb
81
+ - spec/fake_chargify_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/string_patches_spec.rb
84
+ - README.md
85
+ has_rdoc: true
86
+ homepage: http://github.com/brilliantfantastic/fake_chargify
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options:
91
+ - --charset=UTF-8
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project: fake_chargify
111
+ rubygems_version: 1.3.6
112
+ signing_key:
113
+ specification_version: 2
114
+ summary: A helper for faking web requests and responses to and from the Chargify API.
115
+ test_files: []
116
+