stripe-rails 1.0.0 → 1.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: b07e6ff640777c2280d2dd29d46ddb72f8412ffb
4
- data.tar.gz: 952adfc0b8538e40e53b0eaf59b1c6620c7c418e
3
+ metadata.gz: d7064822cbaf76623c55cdb77ca09fc0024ad995
4
+ data.tar.gz: c431f805019acf8b747078e464219936bd105ab2
5
5
  SHA512:
6
- metadata.gz: caeda4e7f70ed9b564abaf7f065dd25591aaedf8cf57f7b95a71274b5a10bd269c6a55ab60ebe0487de8ed6941b7dd5f154981f4e7d4b7b87b4ba8f4c42112c5
7
- data.tar.gz: c2f965d400379c69d80c02055f30d288630793142aa02736fad46ba4cf33dd201b6f546248301e6d6bd43b361aff613ddae81b1b7a22e13b6b321783813ff30b
6
+ metadata.gz: da180772c4e9efa49b565cefcdc9b81328cac4ed8d8afdde59f1313734c0df76b64f014520914f118a908341b0e239fd224e4e0d988cd1290bf179fc1574ba31
7
+ data.tar.gz: 073db41216f36f6041f1844ebe58413850dc4f3bb75bfc9cefe6305f9c6dec6aa233eb58164b1a515f0be88b1a33a61908bb8de6c9006799abfb917dac3468ed
data/Changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.1 (2017-08-08)
2
+
3
+ * Fixes a bug with Stripe JS V3, i.e. `Stripe.setPublishableKey` is no longer a function. Thanks to @kartikluke for reporting this.
4
+
1
5
  ## 1.0.0 (2017-07-24 - Breaky McBreakface)
2
6
 
3
7
  * [BREAKING] Update to latest stripe events (thanks @hopsoft). Note that if you are using the `after_customer_card_created`, `after_customer_card_updated` or `after_customer_card_deleted` callbacks, you MUST update them to `after_customer_source_created`, `after_customer_source_updated` or `after_customer_source_deleted` respectively. You also need to start using [Stripe API Version > 2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) or else the webhook might not work as expected.
data/Gemfile CHANGED
@@ -12,4 +12,7 @@ gem 'responders', '~> 2.0' # to support Rails 4.2
12
12
 
13
13
  group :test do
14
14
  gem 'simplecov', require: false
15
+ gem 'poltergeist' # required for system tests
16
+ gem 'phantomjs' # ditto
17
+ gem 'puma' # ditto
15
18
  end
@@ -1,13 +1,16 @@
1
- <%- case (stripe_js_version || 'v1') %>
1
+ <%- case (stripe_js_version || 'v3') %>
2
2
  <%- when 'v1', 'v2' %>
3
- <%- if ::Rails.application.config.stripe.debug_js %>
4
- <script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/stripe-debug.js"></script>
5
- <%- else %>
6
- <script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
7
- <%- end %>
3
+ <%- if ::Rails.application.config.stripe.debug_js %>
4
+ <script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/stripe-debug.js"></script>
5
+ <%- else %>
6
+ <script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
7
+ <%- end %>
8
+ <script type="text/javascript">
9
+ Stripe.setPublishableKey("<%= Rails.application.config.stripe.publishable_key or fail 'No stripe.com publishable key found. Please set config.stripe.publishable_key in config/application.rb to one of your publishable keys, which can be found here: https://manage.stripe.com/#account/apikeys' %>")
10
+ </script>
8
11
  <%- when 'v3' # the debug js for v3 isn't available %>
9
- <script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
10
- <%- end %>
11
- <script type="text/javascript">
12
- Stripe.setPublishableKey("<%= Rails.application.config.stripe.publishable_key or fail 'No stripe.com publishable key found. Please set config.stripe.publishable_key in config/application.rb to one of your publishable keys, which can be found here: https://manage.stripe.com/#account/apikeys' %>")
13
- </script>
12
+ <script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
13
+ <script type="text/javascript">
14
+ var stripe = Stripe("<%= Rails.application.config.stripe.publishable_key or fail 'No stripe.com publishable key found. Please set config.stripe.publishable_key in config/application.rb to one of your publishable keys, which can be found here: https://manage.stripe.com/#account/apikeys' %>");
15
+ </script>
16
+ <%- end %>
@@ -12,4 +12,7 @@ gem 'stripe'
12
12
 
13
13
  group :test do
14
14
  gem 'simplecov', require: false
15
+ gem 'poltergeist'
16
+ gem 'phantomjs', :require => 'phantomjs/poltergeist'
17
+ gem 'puma'
15
18
  end
@@ -12,4 +12,7 @@ gem 'stripe'
12
12
 
13
13
  group :test do
14
14
  gem 'simplecov', require: false
15
+ gem 'poltergeist'
16
+ gem 'phantomjs', :require => 'phantomjs/poltergeist'
17
+ gem 'puma'
15
18
  end
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  module Rails
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -3,114 +3,90 @@ require 'spec_helper'
3
3
 
4
4
  describe Stripe::Callbacks do
5
5
  include Rack::Test::Methods
6
+ include CallbackHelpers
6
7
 
7
- def app
8
- Rails.application
9
- end
8
+ let(:app) { Rails.application }
9
+ let(:event) { JSON.parse(File.read File.expand_path('../event.json', __FILE__)) }
10
+ let(:invoice) { JSON.parse(File.read File.expand_path('../invoice.json', __FILE__)) }
11
+ let(:content) { event }
12
+ let(:observer) { Class.new }
10
13
 
11
14
  before do
12
15
  header 'Accept', 'application/json'
13
16
  header 'Content-Type', 'application/json'
14
- @observer = Class.new.tap do |cls|
15
- cls.class_eval do
16
- include Stripe::Callbacks
17
- end
18
- end
19
17
 
20
- event = JSON.parse(File.read File.expand_path('../event.json', __FILE__))
21
- invoice = JSON.parse(File.read File.expand_path('../invoice.json', __FILE__))
22
- event['data']['object'] = invoice
18
+ observer.include Stripe::Callbacks
23
19
 
24
- @content = event
25
- self.type = @content['type']
26
- end
27
-
28
- def type=(type)
29
- @content['type'] = type
30
- @stubbed_event = Stripe::Event.construct_from(@content)
31
- Stripe::Event.stubs(:retrieve).returns(@stubbed_event)
32
- end
33
-
34
- after do
35
- ::Stripe::Callbacks.clear_callbacks!
36
- end
20
+ event['data']['object'] = invoice
37
21
 
38
- it 'has eager loaded the callbacks listed in the configuration' do
39
- assert Dummy.const_defined?(:ModelWithCallbacks), 'should have eager loaded'
40
- assert Dummy.const_defined?(:ModuleWithCallbacks), 'should have eager loaded'
22
+ self.type = content['type']
41
23
  end
24
+ after { ::Stripe::Callbacks.clear_callbacks! }
42
25
 
43
- it 'has a ping interface just to make sure that everything is working just fine' do
44
- get '/stripe/ping'
45
- assert last_response.ok?
46
- end
26
+ subject { post 'stripe/events', JSON.pretty_generate(content) }
47
27
 
48
28
  describe 'defined with a bang' do
49
- code = nil
50
- before do
51
- code = proc {|target, e| @event = e; @target = target}
52
- @observer.class_eval do
53
- after_invoice_payment_succeeded! do |evt, target|
54
- code.call(evt, target)
55
- end
29
+ let(:callback) { :after_invoice_payment_succeeded! }
30
+ before { run_callback_with(callback) {|target, e| @event = e; @target = target} }
31
+
32
+ describe 'when it is invoked for the invoice.payment_succeeded event' do
33
+ it 'is invoked for the invoice.payment_succeeded event' do
34
+ subject
35
+ @event.wont_be_nil
36
+ @event.type.must_equal 'invoice.payment_succeeded'
37
+ @target.total.must_equal 6999
56
38
  end
57
39
  end
58
- it 'is invoked for the invoice.payment_succeeded event' do
59
- post 'stripe/events', JSON.pretty_generate(@content)
60
- @event.wont_be_nil
61
- @event.type.must_equal 'invoice.payment_succeeded'
62
- @target.total.must_equal 6999
63
- end
64
- it 'is not invoked for other types of events' do
65
- self.type = 'invoked.payment_failed'
66
- post 'stripe/events/', JSON.pretty_generate(@content)
40
+
41
+ describe 'when the invoked.payment_failed webhook is called' do
42
+ before { self.type = 'invoked.payment_failed' }
43
+
44
+ it 'the invoice.payment_succeeded callback is not invoked' do
45
+ subject
46
+ @event.must_be_nil
47
+ end
67
48
  end
49
+
68
50
  describe 'if it raises an exception' do
69
- before do
70
- code = proc {fail 'boom!'}
71
- end
51
+ before { run_callback_with(callback) { fail } }
52
+
72
53
  it 'causes the whole webhook to fail' do
73
- proc {post 'stripe/events', JSON.pretty_generate(@content)}.must_raise RuntimeError
54
+ ->{ subject }.must_raise RuntimeError
74
55
  end
75
56
  end
76
57
  end
77
58
 
78
59
  describe 'defined without a bang and raising an exception' do
79
- before do
80
- @observer.class_eval do
81
- after_invoice_payment_succeeded do |evt|
82
- fail 'boom!'
83
- end
84
- end
85
- end
60
+ let(:callback) { :after_invoice_payment_succeeded }
61
+ before { run_callback_with(callback) { fail } }
86
62
 
87
63
  it 'does not cause the webhook to fail' do
88
- post 'stripe/events', JSON.pretty_generate(@content)
64
+ subject
89
65
  last_response.status.must_be :>=, 200
90
66
  last_response.status.must_be :<, 300
91
67
  end
92
68
  end
93
69
 
94
- describe 'designed to catch any event' do
95
- events = nil
96
- before do
97
- events = []
98
- @observer.class_eval do
99
- after_stripe_event do |target, evt|
100
- events << evt
101
- end
70
+ describe 'the after_stripe_event callback to catch any event' do
71
+ let(:events) { [] }
72
+ before { run_callback_with(:after_stripe_event) { |_, evt| events << evt } }
73
+
74
+ describe 'when it gets invoked for a standard event' do
75
+ before { self.type = 'invoice.payment_failed' }
76
+
77
+ it 'it will be run' do
78
+ subject
79
+ events.first.type.must_equal 'invoice.payment_failed'
102
80
  end
103
81
  end
104
- it 'gets invoked for any standard event' do
105
- self.type = 'invoice.payment_failed'
106
- post 'stripe/events/', JSON.pretty_generate(@content)
107
- events.first.type.must_equal 'invoice.payment_failed'
108
- end
109
82
 
110
- it 'gets invoked for any event whatsoever' do
111
- self.type = 'foo.bar.baz'
112
- post 'stripe/events/', JSON.pretty_generate(@content)
113
- events.first.type.must_equal 'foo.bar.baz'
83
+ describe 'when it gets invoked for an arbitrary event' do
84
+ before { self.type = 'foo.bar.baz' }
85
+
86
+ it 'it will be run' do
87
+ subject
88
+ events.first.type.must_equal 'foo.bar.baz'
89
+ end
114
90
  end
115
91
  end
116
92
 
@@ -121,60 +97,87 @@ describe Stripe::Callbacks do
121
97
  self.type = 'invoice.updated'
122
98
  @stubbed_event.data.previous_attributes = {}
123
99
  end
100
+
124
101
  describe 'specified as an single symbol' do
125
102
  before do
126
- @observer.class_eval do
103
+ observer.class_eval do
127
104
  after_invoice_updated! :only => :closed do |invoice, evt|
128
105
  events << evt
129
106
  end
130
107
  end
131
108
  end
132
- it 'does not fire events for with a prior attribute was specified' do
133
- post 'stripe/events', JSON.pretty_generate(@content)
134
- events.length.must_equal 0
109
+
110
+ describe 'when a prior attribute was not specified' do
111
+ it 'does not fire events' do
112
+ subject
113
+ events.length.must_equal 0
114
+ end
135
115
  end
136
- it 'does fire events for which the prior attribute was specified' do
137
- @stubbed_event.data.previous_attributes['closed'] = true
138
- post 'stripe/events', JSON.pretty_generate(@content)
139
- events.length.must_equal 1
116
+
117
+ describe 'when a prior attribute was specified' do
118
+ before { @stubbed_event.data.previous_attributes['closed'] = true }
119
+ it 'fires events' do
120
+ subject
121
+ events.length.must_equal 1
122
+ end
140
123
  end
141
124
  end
125
+
142
126
  describe 'specified as an array' do
143
127
  before do
144
- @observer.class_eval do
128
+ observer.class_eval do
145
129
  after_invoice_updated! :only => [:currency, :subtotal] do |invoice, evt|
146
130
  events << evt
147
131
  end
148
132
  end
149
133
  end
150
- it 'does not fire events for which prior attributes were not specified' do
151
- post 'stripe/events', JSON.pretty_generate(@content)
152
- events.length.must_equal 0
134
+
135
+ describe 'when a prior attribute was not specified' do
136
+ it 'does not fire events' do
137
+ subject
138
+ events.length.must_equal 0
139
+ end
153
140
  end
154
- it 'does fire events for which prior attributes were specified' do
155
- @stubbed_event.data.previous_attributes['subtotal'] = 699
156
- post 'stripe/events', JSON.pretty_generate(@content)
157
- events.length.must_equal 1
141
+
142
+ describe 'when prior attributes were specified' do
143
+ before { @stubbed_event.data.previous_attributes['subtotal'] = 699 }
144
+ it 'fire events' do
145
+ subject
146
+ events.length.must_equal 1
147
+ end
158
148
  end
159
149
  end
150
+
160
151
  describe 'specified as a lambda' do
161
152
  before do
162
- @observer.class_eval do
153
+ observer.class_eval do
163
154
  after_invoice_updated :only => proc {|target, evt| evt.data.previous_attributes.to_hash.has_key? :closed} do |i,e|
164
155
  events << e
165
156
  end
166
157
  end
167
158
  end
168
- it 'does not fire events for which the lambda is not true' do
169
- post 'stripe/events', JSON.pretty_generate(@content)
170
- events.length.must_equal 0
159
+
160
+ describe 'when the lambda is not true' do
161
+ it 'does not fire events' do
162
+ subject
163
+ events.length.must_equal 0
164
+ end
171
165
  end
172
166
 
173
- it 'does fire events for when the lambda is true' do
174
- @stubbed_event.data.previous_attributes['closed'] = 'false'
175
- post 'stripe/events', JSON.pretty_generate(@content)
176
- events.length.must_equal 1
167
+ describe 'when the lambda is not true' do
168
+ before { @stubbed_event.data.previous_attributes['closed'] = 'false' }
169
+ it 'fires events' do
170
+ subject
171
+ events.length.must_equal 1
172
+ end
177
173
  end
178
174
  end
179
175
  end
176
+
177
+ describe 'when there are eager loaded callbacks in the configuration (config/environment/test.rb)' do
178
+ it 'should be eager loaded' do
179
+ Dummy.const_defined?(:ModelWithCallbacks).must_equal true
180
+ Dummy.const_defined?(:ModuleWithCallbacks).must_equal true
181
+ end
182
+ end
180
183
  end
@@ -0,0 +1,4 @@
1
+ class StripesController < ApplicationController
2
+ def new
3
+ end
4
+ end
@@ -2,8 +2,6 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
6
- <%= javascript_include_tag "application" %>
7
5
  <%= csrf_meta_tags %>
8
6
  </head>
9
7
  <body>
@@ -0,0 +1,3 @@
1
+ <%= stripe_javascript_tag (params[:version] || :v3) %>
2
+
3
+ <p>This page tests the loading and initialization of Stripe JS</p>
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
+ resources :stripes, only: :new
2
3
  # The priority is based upon order of creation:
3
4
  # first created -> highest priority.
4
5
 
@@ -0,0 +1,17 @@
1
+ class DummyStripesControllerSpec < ApplicationSystemTestCase
2
+ setup do
3
+ Dummy::Application.configure do
4
+ config.stripe.publishable_key = 'pk_test_XXXYYYZZZ'
5
+ end
6
+ end
7
+
8
+ test "loading the default javascript helper" do
9
+ visit new_stripe_url
10
+ assert_text 'This page tests the loading and initialization of Stripe JS'
11
+ end
12
+
13
+ test "loading the v2 version of the javascript helper" do
14
+ visit new_stripe_url(version: 'v2')
15
+ assert_text 'This page tests the loading and initialization of Stripe JS'
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'spec_helper'
3
+
4
+ describe Stripe::PingsController do
5
+ include Rack::Test::Methods
6
+
7
+ let(:app) { Rails.application }
8
+ before do
9
+ header 'Accept', 'application/json'
10
+ header 'Content-Type', 'application/json'
11
+ end
12
+
13
+ describe 'the ping interface' do
14
+ subject { get '/stripe/ping' }
15
+
16
+ it { subject.must_be :ok? }
17
+ end
18
+ end
data/test/spec_helper.rb CHANGED
@@ -20,3 +20,5 @@ end
20
20
 
21
21
  Stripe::Engine.testing = true
22
22
  require 'mocha/setup'
23
+
24
+ require 'irb'
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../null_system_test_case", __FILE__)
2
+ require "capybara/poltergeist"
3
+ require 'phantomjs/poltergeist'
4
+
5
+ # For Rails 4 compat
6
+ SystemTestCaseKlass = defined?(ActionDispatch::SystemTestCase) ? ActionDispatch::SystemTestCase : NullSystemTestCase
7
+
8
+ class ApplicationSystemTestCase < SystemTestCaseKlass
9
+ # Note: errors only show up with BOTH js_errors: true, inspector: true
10
+ driven_by :poltergeist, options: { js_errors: true, inspector: true, phantomjs: Phantomjs.path }
11
+ end
@@ -0,0 +1,15 @@
1
+ module CallbackHelpers
2
+ def type=(type)
3
+ content['type'] = type
4
+ @stubbed_event = Stripe::Event.construct_from(content)
5
+ Stripe::Event.stubs(:retrieve).returns(@stubbed_event)
6
+ end
7
+
8
+ def run_callback_with(callback)
9
+ observer.class_eval do
10
+ send(callback) do |evt, target|
11
+ yield evt, target
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class NullSystemTestCase
2
+ def self.driven_by(_, _)
3
+ end
4
+
5
+ def self.setup
6
+ end
7
+
8
+ def self.test(_)
9
+ warn 'WARNING: Skipping system test because this version of Rails does not support it!'
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-24 00:00:00.000000000 Z
12
+ date: 2017-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -100,11 +100,13 @@ files:
100
100
  - test/dummy/app/assets/javascripts/application.js
101
101
  - test/dummy/app/assets/stylesheets/application.css
102
102
  - test/dummy/app/controllers/application_controller.rb
103
+ - test/dummy/app/controllers/stripes_controller.rb
103
104
  - test/dummy/app/helpers/application_helper.rb
104
105
  - test/dummy/app/mailers/.gitkeep
105
106
  - test/dummy/app/models/.gitkeep
106
107
  - test/dummy/app/models/dummy/model_with_callbacks.rb
107
108
  - test/dummy/app/views/layouts/application.html.erb
109
+ - test/dummy/app/views/stripes/new.html.erb
108
110
  - test/dummy/config.ru
109
111
  - test/dummy/config/application.rb
110
112
  - test/dummy/config/boot.rb
@@ -130,12 +132,17 @@ files:
130
132
  - test/dummy/public/500.html
131
133
  - test/dummy/public/favicon.ico
132
134
  - test/dummy/script/rails
135
+ - test/dummy_stripes_controller_spec.rb
133
136
  - test/event.json
134
137
  - test/invoice.json
135
138
  - test/javascript_helper_spec.rb
139
+ - test/pings_controller_spec.rb
136
140
  - test/plan_builder_spec.rb
137
141
  - test/spec_helper.rb
138
142
  - test/stripe_rails_spec.rb
143
+ - test/support/application_system_test_case.rb
144
+ - test/support/callback_helpers.rb
145
+ - test/support/null_system_test_case.rb
139
146
  homepage: https://github.com/Everapps/stripe-rails
140
147
  licenses:
141
148
  - MIT
@@ -169,11 +176,13 @@ test_files:
169
176
  - test/dummy/app/assets/javascripts/application.js
170
177
  - test/dummy/app/assets/stylesheets/application.css
171
178
  - test/dummy/app/controllers/application_controller.rb
179
+ - test/dummy/app/controllers/stripes_controller.rb
172
180
  - test/dummy/app/helpers/application_helper.rb
173
181
  - test/dummy/app/mailers/.gitkeep
174
182
  - test/dummy/app/models/.gitkeep
175
183
  - test/dummy/app/models/dummy/model_with_callbacks.rb
176
184
  - test/dummy/app/views/layouts/application.html.erb
185
+ - test/dummy/app/views/stripes/new.html.erb
177
186
  - test/dummy/config.ru
178
187
  - test/dummy/config/application.rb
179
188
  - test/dummy/config/boot.rb
@@ -199,9 +208,14 @@ test_files:
199
208
  - test/dummy/public/500.html
200
209
  - test/dummy/public/favicon.ico
201
210
  - test/dummy/script/rails
211
+ - test/dummy_stripes_controller_spec.rb
202
212
  - test/event.json
203
213
  - test/invoice.json
204
214
  - test/javascript_helper_spec.rb
215
+ - test/pings_controller_spec.rb
205
216
  - test/plan_builder_spec.rb
206
217
  - test/spec_helper.rb
207
218
  - test/stripe_rails_spec.rb
219
+ - test/support/application_system_test_case.rb
220
+ - test/support/callback_helpers.rb
221
+ - test/support/null_system_test_case.rb