stripe-ruby-mock 1.8.7.1 → 1.8.7.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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  In your gemfile:
9
9
 
10
- gem 'stripe-ruby-mock', '>= 1.8.7.1'
10
+ gem 'stripe-ruby-mock', '>= 1.8.7.2'
11
11
 
12
12
  ## Features
13
13
 
data/lib/stripe_mock.rb CHANGED
@@ -32,6 +32,7 @@ require 'stripe_mock/api/debug'
32
32
  require 'stripe_mock/request_handlers/charges.rb'
33
33
  require 'stripe_mock/request_handlers/cards.rb'
34
34
  require 'stripe_mock/request_handlers/customers.rb'
35
+ require 'stripe_mock/request_handlers/events.rb'
35
36
  require 'stripe_mock/request_handlers/invoices.rb'
36
37
  require 'stripe_mock/request_handlers/invoice_items.rb'
37
38
  require 'stripe_mock/request_handlers/plans.rb'
@@ -16,8 +16,17 @@ module StripeMock
16
16
  json = Stripe::Util.symbolize_names(json)
17
17
  params = Stripe::Util.symbolize_names(params)
18
18
  json[:data][:object] = Util.rmerge(json[:data][:object], params)
19
+ json.delete(:id)
19
20
 
20
- Stripe::Event.construct_from(json)
21
+ if @state == 'local'
22
+ event_data = instance.generate_event(json)
23
+ elsif @state == 'remote'
24
+ event_data = client.generate_event(json)
25
+ else
26
+ raise UnstartedStateError
27
+ end
28
+
29
+ Stripe::Event.construct_from(event_data)
21
30
  end
22
31
 
23
32
  module Webhooks
@@ -56,6 +56,10 @@ module StripeMock
56
56
  timeout_wrap { @pipe.generate_card_token(card_params) }
57
57
  end
58
58
 
59
+ def generate_event(event_data)
60
+ timeout_wrap { Stripe::Util.symbolize_names @pipe.generate_event(event_data) }
61
+ end
62
+
59
63
  def clear_server_data
60
64
  timeout_wrap { @pipe.clear_data }
61
65
  end
@@ -18,29 +18,31 @@ module StripeMock
18
18
  include StripeMock::RequestHandlers::Charges
19
19
  include StripeMock::RequestHandlers::Cards
20
20
  include StripeMock::RequestHandlers::Customers
21
+ include StripeMock::RequestHandlers::Events
21
22
  include StripeMock::RequestHandlers::Invoices
22
23
  include StripeMock::RequestHandlers::InvoiceItems
23
24
  include StripeMock::RequestHandlers::Plans
24
25
  include StripeMock::RequestHandlers::Recipients
25
26
 
26
27
 
27
- attr_reader :charges, :customers, :invoices, :plans, :error_queue,
28
- :recipients
29
- attr_reader :bank_tokens
30
- attr_accessor :debug, :strict
28
+ attr_reader :bank_tokens, :charges, :customers, :events,
29
+ :invoices, :plans, :recipients
30
+
31
+ attr_accessor :error_queue, :debug, :strict
31
32
 
32
33
  def initialize
34
+ @bank_tokens = {}
35
+ @card_tokens = {}
33
36
  @customers = {}
34
- @recipients = {}
35
37
  @charges = {}
36
- @plans = {}
38
+ @events = {}
37
39
  @invoices = {}
38
- @bank_tokens = {}
39
- @card_tokens = {}
40
+ @plans = {}
41
+ @recipients = {}
40
42
 
41
- @id_counter = 0
42
- @error_queue = ErrorQueue.new
43
43
  @debug = false
44
+ @error_queue = ErrorQueue.new
45
+ @id_counter = 0
44
46
  @strict = true
45
47
  end
46
48
 
@@ -86,6 +88,11 @@ module StripeMock
86
88
  token
87
89
  end
88
90
 
91
+ def generate_event(event_data)
92
+ event_data[:id] ||= new_id 'evt'
93
+ @events[ event_data[:id] ] = event_data
94
+ end
95
+
89
96
  def get_bank_by_token(token)
90
97
  if token.nil? || @bank_tokens[token].nil?
91
98
  Data.mock_bank_account
@@ -0,0 +1,18 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module Events
4
+
5
+ def Events.included(klass)
6
+ klass.add_handler 'get /v1/events/(.*)', :retrieve_event
7
+ end
8
+
9
+ def retrieve_event(route, method_url, params, headers)
10
+ route =~ method_url
11
+ event = events[$1]
12
+ assert_existance :event, $1, event
13
+ event
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -54,6 +54,10 @@ module StripeMock
54
54
  @instance.generate_bank_token(recipient_params)
55
55
  end
56
56
 
57
+ def generate_event(event_data)
58
+ @instance.generate_event(event_data)
59
+ end
60
+
57
61
  def debug?; @instance.debug; end
58
62
  def strict?; @instance.strict; end
59
63
  def ping; true; end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.8.7.1"
3
+ VERSION = "1.8.7.2"
4
4
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Webhook Generation' do
3
+ shared_examples 'Webhook Events API' do
4
4
 
5
5
  it "matches the list of webhooks with the folder of fixtures" do
6
6
  events = StripeMock::Webhooks.event_list.to_set
@@ -15,7 +15,7 @@ describe 'Webhook Generation' do
15
15
  it "first looks in spec/fixtures/stripe_webhooks/ for fixtures by default" do
16
16
  event = StripeMock.mock_webhook_event('account.updated')
17
17
  expect(event).to be_a(Stripe::Event)
18
- expect(event.id).to eq('evt_123')
18
+ expect(event.id).to match /^test_evt_[0-9]+/
19
19
  expect(event.type).to eq('account.updated')
20
20
  end
21
21
 
@@ -26,16 +26,49 @@ describe 'Webhook Generation' do
26
26
  end
27
27
 
28
28
  it "allows configuring the project fixture folder" do
29
+ original_path = StripeMock.webhook_fixture_path
30
+
29
31
  StripeMock.webhook_fixture_path = './spec/_dummy/webhooks/'
30
32
  expect(StripeMock.webhook_fixture_path).to eq('./spec/_dummy/webhooks/')
31
33
 
32
34
  event = StripeMock.mock_webhook_event('dummy.event')
33
35
  expect(event.val).to eq('success')
36
+
37
+ StripeMock.webhook_fixture_path = original_path
34
38
  end
35
39
 
36
- it "generates an event" do
40
+ it "generates an event and stores it in memory" do
37
41
  event = StripeMock.mock_webhook_event('customer.created')
38
42
  expect(event).to be_a(Stripe::Event)
43
+ expect(event.id).to_not be_nil
44
+
45
+ data = test_data_source(:events)
46
+ expect(data[event.id]).to_not be_nil
47
+ expect(data[event.id][:id]).to eq(event.id)
48
+ expect(data[event.id][:type]).to eq('customer.created')
49
+ end
50
+
51
+ it "generates an id for a new event" do
52
+ event_a = StripeMock.mock_webhook_event('customer.created')
53
+ event_b = StripeMock.mock_webhook_event('customer.created')
54
+ expect(event_a.id).to_not be_nil
55
+ expect(event_a.id).to_not eq(event_b.id)
56
+
57
+ data = test_data_source(:events)
58
+ expect(data[event_a.id]).to_not be_nil
59
+ expect(data[event_a.id][:id]).to eq(event_a.id)
60
+
61
+ expect(data[event_b.id]).to_not be_nil
62
+ expect(data[event_b.id][:id]).to eq(event_b.id)
63
+ end
64
+
65
+ it "retrieves an eveng using the event resource" do
66
+ webhook_event = StripeMock.mock_webhook_event('plan.created')
67
+ expect(webhook_event.id).to_not be_nil
68
+
69
+ event = Stripe::Event.retrieve(webhook_event.id)
70
+ expect(event).to_not be_nil
71
+ expect(event.type).to eq 'plan.created'
39
72
  end
40
73
 
41
74
  it "takes a hash and deep merges into the data object" do
@@ -10,6 +10,7 @@ def require_stripe_examples
10
10
  require 'shared_stripe_examples/invoice_item_examples'
11
11
  require 'shared_stripe_examples/plan_examples'
12
12
  require 'shared_stripe_examples/recipient_examples'
13
+ require 'shared_stripe_examples/webhook_event_examples'
13
14
  end
14
15
 
15
16
  def it_behaves_like_stripe(&block)
@@ -23,4 +24,5 @@ def it_behaves_like_stripe(&block)
23
24
  it_behaves_like 'Plan API', &block
24
25
  it_behaves_like 'Recipient API', &block
25
26
  it_behaves_like 'Stripe Error Mocking', &block
27
+ it_behaves_like 'Webhook Events API', &block
26
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7.1
4
+ version: 1.8.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-28 00:00:00.000000000 Z
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe
@@ -146,6 +146,7 @@ files:
146
146
  - lib/stripe_mock/request_handlers/cards.rb
147
147
  - lib/stripe_mock/request_handlers/charges.rb
148
148
  - lib/stripe_mock/request_handlers/customers.rb
149
+ - lib/stripe_mock/request_handlers/events.rb
149
150
  - lib/stripe_mock/request_handlers/invoice_items.rb
150
151
  - lib/stripe_mock/request_handlers/invoices.rb
151
152
  - lib/stripe_mock/request_handlers/plans.rb
@@ -205,11 +206,11 @@ files:
205
206
  - spec/shared_stripe_examples/invoice_item_examples.rb
206
207
  - spec/shared_stripe_examples/plan_examples.rb
207
208
  - spec/shared_stripe_examples/recipient_examples.rb
209
+ - spec/shared_stripe_examples/webhook_event_examples.rb
208
210
  - spec/spec_helper.rb
209
211
  - spec/stripe_mock_spec.rb
210
212
  - spec/support/stripe_examples.rb
211
213
  - spec/util_spec.rb
212
- - spec/webhook_spec.rb
213
214
  - stripe-ruby-mock.gemspec
214
215
  homepage: https://github.com/rebelidealist/stripe-ruby-mock
215
216
  licenses:
@@ -253,8 +254,8 @@ test_files:
253
254
  - spec/shared_stripe_examples/invoice_item_examples.rb
254
255
  - spec/shared_stripe_examples/plan_examples.rb
255
256
  - spec/shared_stripe_examples/recipient_examples.rb
257
+ - spec/shared_stripe_examples/webhook_event_examples.rb
256
258
  - spec/spec_helper.rb
257
259
  - spec/stripe_mock_spec.rb
258
260
  - spec/support/stripe_examples.rb
259
261
  - spec/util_spec.rb
260
- - spec/webhook_spec.rb