stripe-ruby-mock 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0b68df0cf8a9bb5fcc7743fe4dd1983cf4bd0a3
4
- data.tar.gz: 4a10d0bbbf8b53ebb4dbf86875b4c2cc35191c15
3
+ metadata.gz: 3d4f15152fa1de80be81c36c7d32ce3c95368c35
4
+ data.tar.gz: a784112eabc78dfdbff8ccfacf76a010b3b388e5
5
5
  SHA512:
6
- metadata.gz: acce1dfcefe02aab720f6ae0b489bd25fbef197d50bc0b4b57971264ce14fbad3c6b42a4cd379d12bba6ada203f81f037e49e11277a7db5af227b023729268db
7
- data.tar.gz: e206a8a69476fd96a82e42a53f16855ce9645a97b0dee81b6dd714dee78b25a2646f30e2b516908c1529b2df8bddca8dc786945d24951b0631305ba54343ad39
6
+ metadata.gz: d1e1ada3e91652ecec3d26f12906e0ccd86d630a5d035241c1fd2b2f3cb3f706566c2b6a3fdefe484d671f7987d09554a5f66fdfd65ffee1d72dd8d490ea4722
7
+ data.tar.gz: beb89639c55692a25db58d0efca70e6c69487b37aba4c8ec87027e745bb620ed442629302b34e3e1015da52270b2b103a70f6684ad11aea9f6685fb970c19cd6
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ rvm:
6
6
  before_script:
7
7
  - "sudo touch /var/log/stripe-mock-server.log"
8
8
  - "sudo chown travis /var/log/stripe-mock-server.log"
9
- script: "bundle exec rake"
9
+ script: "bundle exec rspec"
10
10
  notifications:
11
11
  webhooks:
12
12
  urls:
data/README.md CHANGED
@@ -23,11 +23,6 @@ In your gemfile:
23
23
 
24
24
  * Strict params: Plan, Token#create
25
25
 
26
- ## TODO BEFORE MERGE
27
-
28
- * Strictify params: Customer#create
29
- * Require existing card tokens
30
-
31
26
  ## Description
32
27
 
33
28
  ** *WARNING: This library does not cover all Stripe API endpoints. If you need one that's missing, please create an issue for it.* **
data/Rakefile CHANGED
@@ -12,17 +12,3 @@ rescue LoadError => e
12
12
  warn e.message
13
13
  warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
14
14
  end
15
-
16
- begin
17
- gem 'rspec', '~> 3.1'
18
- require 'rspec/core/rake_task'
19
-
20
- RSpec::Core::RakeTask.new
21
- rescue LoadError => e
22
- task :spec do
23
- abort "Please run `gem install rspec` to install RSpec."
24
- end
25
- end
26
-
27
- task :test => :spec
28
- task :default => :spec
@@ -15,7 +15,14 @@ module StripeMock
15
15
  id = new_id('ch')
16
16
 
17
17
  if params[:card] && params[:card].is_a?(String)
18
- params[:card] = get_card_by_token(params[:card])
18
+ # if a customer is provided, the card parameter is assumed to be the actual
19
+ # card id, not a token. in this case we'll find the card in the customer
20
+ # object and return that.
21
+ if params[:customer]
22
+ params[:card] = get_card(customers[params[:customer]], params[:card])
23
+ else
24
+ params[:card] = get_card_by_token(params[:card])
25
+ end
19
26
  elsif params[:card] && params[:card][:id]
20
27
  raise Stripe::InvalidRequestError.new("Invalid token id: #{params[:card]}", 'card', 400)
21
28
  end
@@ -5,6 +5,7 @@ module StripeMock
5
5
  def Invoices.included(klass)
6
6
  klass.add_handler 'post /v1/invoices', :new_invoice
7
7
  klass.add_handler 'get /v1/invoices/upcoming', :upcoming_invoice
8
+ klass.add_handler 'get /v1/invoices/(.*)/lines', :get_invoice_line_items
8
9
  klass.add_handler 'get /v1/invoices/(.*)', :get_invoice
9
10
  klass.add_handler 'get /v1/invoices', :list_invoices
10
11
  klass.add_handler 'post /v1/invoices/(.*)/pay', :pay_invoice
@@ -41,6 +42,12 @@ module StripeMock
41
42
  assert_existance :invoice, $1, invoices[$1]
42
43
  end
43
44
 
45
+ def get_invoice_line_items(route, method_url, params, headers)
46
+ route =~ method_url
47
+ assert_existance :invoice, $1, invoices[$1]
48
+ invoices[$1][:lines]
49
+ end
50
+
44
51
  def pay_invoice(route, method_url, params, headers)
45
52
  route =~ method_url
46
53
  assert_existance :invoice, $1, invoices[$1]
@@ -59,7 +66,10 @@ module StripeMock
59
66
  most_recent = customer[:subscriptions][:data].min_by { |sub| sub[:current_period_end] }
60
67
  invoice_item = get_mock_subscription_line_item(most_recent)
61
68
 
62
- Data.mock_invoice([invoice_item],
69
+ id = new_id('in')
70
+ invoices[id] = Data.mock_invoice([invoice_item],
71
+ id: id,
72
+ customer: customer[:id],
63
73
  subscription: most_recent[:id],
64
74
  period_start: most_recent[:current_period_start],
65
75
  period_end: most_recent[:current_period_end],
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
@@ -27,6 +27,34 @@ shared_examples 'Charge API' do
27
27
  end
28
28
 
29
29
 
30
+ it "creates a stripe charge item with a customer and card id" do
31
+ customer = Stripe::Customer.create({
32
+ email: 'johnny@appleseed.com',
33
+ card: stripe_helper.generate_card_token(number: '4012888888881881'),
34
+ description: "a description"
35
+ })
36
+
37
+ expect(customer.cards.data.length).to eq(1)
38
+ expect(customer.cards.data[0].id).not_to be_nil
39
+ expect(customer.cards.data[0].last4).to eq('1881')
40
+
41
+ card = customer.cards.data[0]
42
+ charge = Stripe::Charge.create(
43
+ amount: 999,
44
+ currency: 'USD',
45
+ customer: customer.id,
46
+ card: card.id,
47
+ description: 'a charge with a specific card'
48
+ )
49
+
50
+ expect(charge.id).to match(/^test_ch/)
51
+ expect(charge.amount).to eq(999)
52
+ expect(charge.description).to eq('a charge with a specific card')
53
+ expect(charge.captured).to eq(true)
54
+ expect(charge.card.last4).to eq('1881')
55
+ end
56
+
57
+
30
58
  it "stores a created stripe charge in memory" do
31
59
  charge = Stripe::Charge.create({
32
60
  amount: 333,
@@ -114,18 +114,19 @@ shared_examples 'Invoice API' do
114
114
  expect(e.message).to eq("No upcoming invoices for customer: #{@customer.id}") }
115
115
  end
116
116
 
117
- it 'works when customer has a subscription' do
118
- @plan = stripe_helper.create_plan()
119
- @subscription = @customer.subscriptions.create(plan: @plan.id)
120
- @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
117
+ it 'works when customer has a subscription', :live => true do
118
+ plan = stripe_helper.create_plan(:id => 'has_sub')
119
+ subscription = @customer.subscriptions.create(plan: plan.id)
120
+ upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
121
121
 
122
- expect(@upcoming).to be_a Stripe::Invoice
123
- expect(@upcoming.total).to eq(@upcoming.lines.data[0].amount)
124
- expect(@upcoming.period_end).to eq(@upcoming.lines.data[0].period.start)
125
- expect(Time.at(@upcoming.period_start).to_datetime >> 1).to eq(Time.at(@upcoming.period_end).to_datetime) # +1 month
126
- expect(Time.at(@upcoming.period_start).to_datetime >> 2).to eq(Time.at(@upcoming.lines.data[0].period.end).to_datetime) # +1 month
127
- expect(@upcoming.next_payment_attempt).to eq(@upcoming.period_end + 3600) # +1 hour
128
- expect(@upcoming.subscription).to eq(@subscription.id)
122
+ expect(upcoming).to be_a Stripe::Invoice
123
+ expect(upcoming.customer).to eq(@customer.id)
124
+ expect(upcoming.total).to eq(upcoming.lines.data[0].amount)
125
+ expect(upcoming.period_end).to eq(upcoming.lines.data[0].period.start)
126
+ expect(Time.at(upcoming.period_start).to_datetime >> 1).to eq(Time.at(upcoming.period_end).to_datetime) # +1 month
127
+ expect(Time.at(upcoming.period_start).to_datetime >> 2).to eq(Time.at(upcoming.lines.data[0].period.end).to_datetime) # +1 month
128
+ expect(upcoming.next_payment_attempt).to eq(upcoming.period_end + 3600) # +1 hour
129
+ expect(upcoming.subscription).to eq(subscription.id)
129
130
  end
130
131
 
131
132
  it 'sets the start and end of billing periods correctly when plan has an interval_count' do
@@ -155,6 +156,32 @@ shared_examples 'Invoice API' do
155
156
  expect(@upcoming.subscription).to eq(@shortsub.id)
156
157
  end
157
158
 
159
+ context 'retrieving invoice line items' do
160
+ it 'returns all line items for created invoice' do
161
+ invoice = Stripe::Invoice.create(customer: @customer.id)
162
+ line_items = invoice.lines.all
163
+
164
+ expect(invoice).to be_a Stripe::Invoice
165
+ expect(line_items.count).to eq(1)
166
+ expect(line_items.data[0].object).to eq('line_item')
167
+ expect(line_items.data[0].description).to eq('Test invoice item')
168
+ expect(line_items.data[0].type).to eq('invoiceitem')
169
+ end
170
+
171
+ it 'returns all line items for upcoming invoice' do
172
+ plan = stripe_helper.create_plan()
173
+ subscription = @customer.subscriptions.create(plan: plan.id)
174
+ upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
175
+ line_items = upcoming.lines.all
176
+
177
+ expect(upcoming).to be_a Stripe::Invoice
178
+ expect(line_items.count).to eq(1)
179
+ expect(line_items.data[0].object).to eq('line_item')
180
+ expect(line_items.data[0].description).to eq('Test invoice item')
181
+ expect(line_items.data[0].type).to eq('subscription')
182
+ end
183
+ end
184
+
158
185
  context 'calculates month and year offsets correctly' do
159
186
 
160
187
  it 'for one month plan on the 1st' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe