stripe-rails 1.0.2 → 1.1.0

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: fc13abc0e868f9694a9709777de1a94365d1fd3b
4
- data.tar.gz: 732785e90b16d15ce68c61767db21cabf3b6b062
3
+ metadata.gz: ac50cc61a92527aeb62ea99d1c288dd9057e2796
4
+ data.tar.gz: a499347e24515c8d7ccddc7b961e62abf633e9a6
5
5
  SHA512:
6
- metadata.gz: 9a07835744d0b8c03439916e5ab39a8afb0bedcc614bfa55fef0a06a6ef13530c1e6f6c1252c1a6c14975c3669647203818896d996486332de41c5f2cdcac832
7
- data.tar.gz: 9285d16a3d4eabd200a5c73f76ff0ddb065cd7a2d4a8b0a68b5beac7a0a22ece7f09081125a6a68f6d99fed289199b889264161006cd0b607dd09d531e642955
6
+ metadata.gz: 077e01fe7390da6d0c3facab63783dc89d71fe9d91ba14bddc7b6b765855379d832857d2b17630898d9d9cd5be618cac8ce676cddd99e29e5a1d761846118c62
7
+ data.tar.gz: 3a506cbec7767db9a96b5bf4b7c30b81dcc9f833d0904f049afee2b9aae64082e1da346a8902379e884869b473d18ca639506121cac1e10afbb4e0c3f79da50e
data/.travis.yml CHANGED
@@ -4,10 +4,6 @@ rvm:
4
4
  - 2.3.4
5
5
  - 2.2.7
6
6
  - 2.1.9
7
- notifications:
8
- email:
9
- recipients:
10
- - cowboyd@thefrontside.net
11
7
  env:
12
8
  global:
13
9
  - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
@@ -33,4 +29,4 @@ matrix:
33
29
  - rvm: 2.1.9
34
30
  gemfile: Gemfile
35
31
  - rvm: 2.1.9
36
- gemfile: gemfiles/rails5.gemfile
32
+ gemfile: gemfiles/rails5.gemfile
data/Changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.1.0 (2017-08-29)
2
+
3
+ * Adds a testing module for testing callbacks (thanks @Pyo25)
4
+ * Fixes loading with ActionController::API (thanks @gaffneyc)
5
+ * Fixes `NoMethodError: NoMethodError (undefined method `object' for #ActionController::Parameters` (thanks to a whole bunch of people for reporting this)
6
+
1
7
  ## 1.0.2 (2017-08-15)
2
8
 
3
9
  * Remove authenticity token check (thanks @lewispb)
data/README.md CHANGED
@@ -358,6 +358,30 @@ end
358
358
 
359
359
  See the [complete listing of all stripe events][5], and the [webhook tutorial][6] for more great information on this subject.
360
360
 
361
+ ## Unit testing
362
+
363
+ If you want to test your callbacks, you can use the `Stripe::Testing` module to send mocked Stripe events.
364
+
365
+ ```ruby
366
+ test "my callback handles new subscription" do
367
+ Stripe::Testing.send_event "customer.subscription.created"
368
+ # Assertions
369
+ end
370
+ ```
371
+
372
+ You can also overwrite some event properties: ([More info](https://github.com/rebelidealist/stripe-ruby-mock#customizing-webhooks))
373
+
374
+ ```ruby
375
+ test "my callback handles new subscription" do
376
+ Stripe::Testing.send_event "customer.subscription.created", {
377
+ :email => "john@doe.com",
378
+ :account_balance => 40
379
+ }
380
+ # Assertions
381
+ end
382
+ ```
383
+
384
+ The default fixtures come from [the `stripe-ruby-mock` gem](https://github.com/rebelidealist/stripe-ruby-mock/tree/master/lib/stripe_mock/webhook_fixtures).
361
385
 
362
386
  ## Thanks
363
387
 
@@ -11,7 +11,7 @@ module Stripe
11
11
  def retrieve_stripe_event(params)
12
12
  id = params['id']
13
13
  if id == 'evt_00000000000000' #this is a webhook test
14
- yield Stripe::Event.construct_from(params)
14
+ yield Stripe::Event.construct_from(params.to_unsafe_h)
15
15
  else
16
16
  yield Stripe::Event.retrieve(id)
17
17
  end
@@ -9,6 +9,7 @@ gem 'mocha'
9
9
  gem 'pry'
10
10
  gem 'responders', '~> 2.0' # to support Rails 4.2
11
11
  gem 'stripe'
12
+ gem 'stripe-ruby-mock', '~> 2.4'
12
13
 
13
14
  group :test do
14
15
  gem 'simplecov', require: false
@@ -9,6 +9,7 @@ gem 'mocha'
9
9
  gem 'pry'
10
10
  gem 'responders', '~> 2.0' # to support Rails 4.2
11
11
  gem 'stripe'
12
+ gem 'stripe-ruby-mock', '~> 2.4'
12
13
 
13
14
  group :test do
14
15
  gem 'simplecov', require: false
data/lib/stripe/engine.rb CHANGED
@@ -55,7 +55,10 @@ environment file directly.
55
55
 
56
56
  initializer 'stripe.javascript_helper' do
57
57
  ActiveSupport.on_load :action_controller do
58
- helper Stripe::JavascriptHelper
58
+ # ActionController::API does not have a helper method
59
+ if respond_to?(:helper)
60
+ helper Stripe::JavascriptHelper
61
+ end
59
62
  end
60
63
  end
61
64
 
data/lib/stripe/rails.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require 'responders'
1
2
  require "stripe/rails/version"
2
3
  require 'stripe/engine'
3
4
  require 'stripe/configuration_builder'
4
5
  require 'stripe/plans'
5
6
  require 'stripe/coupons'
6
- require 'stripe/callbacks'
7
+ require 'stripe/callbacks'
8
+ require 'stripe/testing'
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  module Rails
3
- VERSION = '1.0.2'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ require 'stripe_mock'
2
+ require 'stripe/callbacks'
3
+
4
+ module Stripe
5
+ module Testing
6
+ def self.send_event(event, properties = {})
7
+ evt = StripeMock.mock_webhook_event(event, properties)
8
+ target = evt.data.object
9
+ ::Stripe::Callbacks.run_callbacks(evt, target)
10
+ end
11
+ end
12
+ end
data/stripe-rails.gemspec CHANGED
@@ -1,9 +1,8 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/stripe/rails/version', __FILE__)
1
+ require File.expand_path('lib/stripe/rails/version', __dir__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.authors = ["Charles Lowell", "Nola Stowe"]
6
- gem.email = ["cowboyd@frontside.io"]
4
+ gem.authors = ["Charles Lowell", "Nola Stowe", "SengMing Tan"]
5
+ gem.email = ["sengming@sanemen.com"]
7
6
  gem.description = "A gem to integrate stripe into your rails app"
8
7
  gem.summary = "A gem to integrate stripe into your rails app"
9
8
  gem.homepage = "https://github.com/Everapps/stripe-rails"
@@ -18,4 +17,5 @@ Gem::Specification.new do |gem|
18
17
  gem.add_dependency 'rails', '>= 3'
19
18
  gem.add_dependency 'stripe'
20
19
  gem.add_dependency 'responders'
20
+ gem.add_dependency 'stripe-ruby-mock', '~> 2.4'
21
21
  end
@@ -5,8 +5,8 @@ describe Stripe::Callbacks do
5
5
  include CallbackHelpers
6
6
 
7
7
  let(:app) { Rails.application }
8
- let(:event) { JSON.parse(File.read File.expand_path('../event.json', __FILE__)) }
9
- let(:invoice) { JSON.parse(File.read File.expand_path('../invoice.json', __FILE__)) }
8
+ let(:event) { JSON.parse(File.read File.expand_path('event.json', __dir__)) }
9
+ let(:invoice) { JSON.parse(File.read File.expand_path('invoice.json', __dir__)) }
10
10
  let(:content) { event }
11
11
  let(:observer) { Class.new }
12
12
 
@@ -53,6 +53,12 @@ describe Stripe::Callbacks do
53
53
  ->{ subject }.must_raise RuntimeError
54
54
  end
55
55
  end
56
+
57
+ describe 'when run from a Stripe webhook test' do
58
+ before { event['id'] = 'evt_00000000000000' }
59
+
60
+ it { subject } # must_not raise error
61
+ end
56
62
  end
57
63
 
58
64
  describe 'defined without a bang and raising an exception' do
@@ -0,0 +1,7 @@
1
+ ApiControllerKlass = defined?(ActionController::API) ? ActionController::API : ApplicationController
2
+
3
+ class ApisController < ApiControllerKlass
4
+ def index
5
+ render json: :ok
6
+ end
7
+ end
@@ -1,5 +1,6 @@
1
1
  Dummy::Application.routes.draw do
2
2
  resources :stripes, only: :new
3
+ resources :apis, only: :index
3
4
  # The priority is based upon order of creation:
4
5
  # first created -> highest priority.
5
6
 
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApisController do
4
+ include Rack::Test::Methods
5
+
6
+ let(:app) { Rails.application }
7
+ before do
8
+ header 'Accept', 'application/json'
9
+ header 'Content-Type', 'application/json'
10
+ end
11
+
12
+ describe 'the ping interface' do
13
+ subject { get '/apis/' }
14
+
15
+ it { subject.must_be :ok? }
16
+ end
17
+ end
data/test/spec_helper.rb CHANGED
@@ -9,17 +9,17 @@ require 'minitest/autorun'
9
9
  ENV["RAILS_ENV"] = "test"
10
10
  ENV['STRIPE_SECRET_KEY'] = 'XYZ'
11
11
 
12
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
12
+ require File.expand_path("dummy/config/environment.rb", __dir__)
13
13
  require "rails/test_help"
14
14
 
15
15
  Rails.backtrace_cleaner.remove_silencers!
16
16
 
17
17
  # Load support files
18
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
18
+ Dir["#{__dir__}/support/**/*.rb"].each { |f| require f }
19
19
 
20
20
  # Load fixtures from the engine
21
21
  if ActiveSupport::TestCase.method_defined?(:fixture_path=)
22
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
22
+ ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
23
23
  end
24
24
 
25
25
  Stripe::Engine.testing = true
@@ -1,4 +1,4 @@
1
- require File.expand_path("../null_system_test_case", __FILE__)
1
+ require File.expand_path("null_system_test_case", __dir__)
2
2
  require "capybara/poltergeist"
3
3
  require 'phantomjs/poltergeist'
4
4
 
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Testing" do
4
+ let(:observer) { Class.new }
5
+ let(:event) { observer.instance_variable_get :@event }
6
+ let(:target) { observer.instance_variable_get :@target }
7
+
8
+ before do
9
+ StripeMock.start
10
+
11
+ observer.include Stripe::Callbacks
12
+ observer.class_eval do
13
+ after_invoice_payment_succeeded! { |target, event| @event, @target = event, target }
14
+ end
15
+ end
16
+
17
+ after do
18
+ ::Stripe::Callbacks.clear_callbacks!
19
+ StripeMock.stop
20
+ end
21
+
22
+ describe '.send_event' do
23
+ subject { Stripe::Testing.send_event event_name }
24
+
25
+ describe 'when forwarding the event to the callback' do
26
+ let(:event_name) { "invoice.payment_succeeded" }
27
+
28
+ it 'the callback must run' do
29
+ subject
30
+ event.wont_be_nil
31
+ event.type.must_equal "invoice.payment_succeeded"
32
+ end
33
+ end
34
+
35
+ describe 'when forwarding the event to another callback' do
36
+ let(:event_name) { 'customer.created' }
37
+
38
+ it 'the callback must not run' do
39
+ subject
40
+ event.must_be_nil
41
+ end
42
+ end
43
+
44
+ describe 'when overwriting event properties' do
45
+ subject { Stripe::Testing.send_event event_name, params }
46
+ let(:event_name) { "invoice.payment_succeeded" }
47
+ let(:params) { { subtotal: 500, total: 1000, currency: "eur" } }
48
+
49
+ it 'the callback should run with overwritten properties' do
50
+ subject
51
+ event.wont_be_nil
52
+ event.type.must_equal "invoice.payment_succeeded"
53
+ target.subtotal.must_equal 500
54
+ target.total.must_equal 1000
55
+ target.currency.must_equal "eur"
56
+ end
57
+ end
58
+ end
59
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
8
8
  - Nola Stowe
9
+ - SengMing Tan
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2017-08-15 00:00:00.000000000 Z
13
+ date: 2017-08-29 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
@@ -53,9 +54,23 @@ dependencies:
53
54
  - - ">="
54
55
  - !ruby/object:Gem::Version
55
56
  version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: stripe-ruby-mock
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.4'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '2.4'
56
71
  description: A gem to integrate stripe into your rails app
57
72
  email:
58
- - cowboyd@frontside.io
73
+ - sengming@sanemen.com
59
74
  executables: []
60
75
  extensions: []
61
76
  extra_rdoc_files: []
@@ -93,6 +108,7 @@ files:
93
108
  - lib/stripe/rails.rb
94
109
  - lib/stripe/rails/tasks.rake
95
110
  - lib/stripe/rails/version.rb
111
+ - lib/stripe/testing.rb
96
112
  - stripe-rails.gemspec
97
113
  - test/all.rb
98
114
  - test/callbacks_spec.rb
@@ -101,6 +117,7 @@ files:
101
117
  - test/dummy/Rakefile
102
118
  - test/dummy/app/assets/javascripts/application.js
103
119
  - test/dummy/app/assets/stylesheets/application.css
120
+ - test/dummy/app/controllers/apis_controller.rb
104
121
  - test/dummy/app/controllers/application_controller.rb
105
122
  - test/dummy/app/controllers/stripes_controller.rb
106
123
  - test/dummy/app/helpers/application_helper.rb
@@ -134,6 +151,7 @@ files:
134
151
  - test/dummy/public/500.html
135
152
  - test/dummy/public/favicon.ico
136
153
  - test/dummy/script/rails
154
+ - test/dummy_apis_controller_spec.rb
137
155
  - test/dummy_stripes_controller_spec.rb
138
156
  - test/event.json
139
157
  - test/invoice.json
@@ -145,6 +163,7 @@ files:
145
163
  - test/support/application_system_test_case.rb
146
164
  - test/support/callback_helpers.rb
147
165
  - test/support/null_system_test_case.rb
166
+ - test/testing_spec.rb
148
167
  homepage: https://github.com/Everapps/stripe-rails
149
168
  licenses:
150
169
  - MIT
@@ -165,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
184
  version: '0'
166
185
  requirements: []
167
186
  rubyforge_project:
168
- rubygems_version: 2.6.8
187
+ rubygems_version: 2.6.11
169
188
  signing_key:
170
189
  specification_version: 4
171
190
  summary: A gem to integrate stripe into your rails app
@@ -177,6 +196,7 @@ test_files:
177
196
  - test/dummy/Rakefile
178
197
  - test/dummy/app/assets/javascripts/application.js
179
198
  - test/dummy/app/assets/stylesheets/application.css
199
+ - test/dummy/app/controllers/apis_controller.rb
180
200
  - test/dummy/app/controllers/application_controller.rb
181
201
  - test/dummy/app/controllers/stripes_controller.rb
182
202
  - test/dummy/app/helpers/application_helper.rb
@@ -210,6 +230,7 @@ test_files:
210
230
  - test/dummy/public/500.html
211
231
  - test/dummy/public/favicon.ico
212
232
  - test/dummy/script/rails
233
+ - test/dummy_apis_controller_spec.rb
213
234
  - test/dummy_stripes_controller_spec.rb
214
235
  - test/event.json
215
236
  - test/invoice.json
@@ -221,3 +242,4 @@ test_files:
221
242
  - test/support/application_system_test_case.rb
222
243
  - test/support/callback_helpers.rb
223
244
  - test/support/null_system_test_case.rb
245
+ - test/testing_spec.rb