From 54419d001144657bb9983e1f7aec74d7c4fa2664 Mon Sep 17 00:00:00 2001 From: SengMing Tan Date: Thu, 31 Aug 2017 09:04:22 -0400 Subject: [PATCH 1/5] moves stripe ruby mock out of gemspec --- Gemfile | 4 +++- stripe-rails.gemspec | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index c1fa2d3e..80d4edd9 100644 --- a/Gemfile +++ b/Gemfile @@ -8,10 +8,12 @@ gem "rake" gem 'tzinfo' gem 'mocha' gem 'pry' -gem 'responders', '~> 2.0' # to support Rails 4.2 group :test do gem 'simplecov', require: false + # NOTE: tracking master temporarily until they + # release https://github.com/rebelidealist/stripe-ruby-mock/pull/433 + gem 'stripe-ruby-mock', github: 'rebelidealist/stripe-ruby-mock' gem 'poltergeist' # required for system tests gem 'phantomjs' # ditto gem 'puma' # ditto diff --git a/stripe-rails.gemspec b/stripe-rails.gemspec index d8143283..e290f090 100644 --- a/stripe-rails.gemspec +++ b/stripe-rails.gemspec @@ -17,5 +17,4 @@ Gem::Specification.new do |gem| gem.add_dependency 'rails', '>= 3' gem.add_dependency 'stripe' gem.add_dependency 'responders' - gem.add_dependency 'stripe-ruby-mock', '~> 2.4' end From e6a67bedd117e7f05e011ff5d86012cc144588db Mon Sep 17 00:00:00 2001 From: SengMing Tan Date: Thu, 31 Aug 2017 09:12:26 -0400 Subject: [PATCH 2/5] =?UTF-8?q?error=20message=20in=20case=20they=20don?= =?UTF-8?q?=E2=80=99t=20have=20stripe=20ruby=20mock=20in=20their=20gemfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/stripe/testing.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/stripe/testing.rb b/lib/stripe/testing.rb index 04590e1e..3125dfc7 100644 --- a/lib/stripe/testing.rb +++ b/lib/stripe/testing.rb @@ -1,4 +1,9 @@ -require 'stripe_mock' +begin + require 'stripe_mock' +rescue LoadError + warn %q{Please add "gem 'stripe-ruby-mock', group: 'test'"" to the Gemfile to use Stripe::Testing"} + exit +end require 'stripe/callbacks' module Stripe From 691368102e577d1fac28b87bd5d23253dd4d1ce2 Mon Sep 17 00:00:00 2001 From: SengMing Tan Date: Thu, 31 Aug 2017 09:14:43 -0400 Subject: [PATCH 3/5] stop automatically loading `stripe/testing` to the gem --- README.md | 2 ++ lib/stripe/rails.rb | 3 +-- test/testing_spec.rb | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e49a27e..60ae2ffa 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,7 @@ See the [complete listing of all stripe events][5], and the [webhook tutorial][6 If you want to test your callbacks, you can use the `Stripe::Testing` module to send mocked Stripe events. ```ruby +require 'stripe/testing' test "my callback handles new subscription" do Stripe::Testing.send_event "customer.subscription.created" # Assertions @@ -372,6 +373,7 @@ end You can also overwrite some event properties: ([More info](https://github.com/rebelidealist/stripe-ruby-mock#customizing-webhooks)) ```ruby +require 'stripe/testing' test "my callback handles new subscription" do Stripe::Testing.send_event "customer.subscription.created", { :email => "john@doe.com", diff --git a/lib/stripe/rails.rb b/lib/stripe/rails.rb index 3375d508..ee3aeeb0 100644 --- a/lib/stripe/rails.rb +++ b/lib/stripe/rails.rb @@ -4,5 +4,4 @@ require 'stripe/configuration_builder' require 'stripe/plans' require 'stripe/coupons' -require 'stripe/callbacks' -require 'stripe/testing' \ No newline at end of file +require 'stripe/callbacks' \ No newline at end of file diff --git a/test/testing_spec.rb b/test/testing_spec.rb index b172a7fc..345857ed 100644 --- a/test/testing_spec.rb +++ b/test/testing_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'stripe/testing' describe "Testing" do let(:observer) { Class.new } From 64b123832420f3ac0f3bff76ddc897ee065f6d9f Mon Sep 17 00:00:00 2001 From: SengMing Tan Date: Thu, 31 Aug 2017 10:22:02 -0400 Subject: [PATCH 4/5] Stripe::Testing -> Stripe::Rails::Testing --- README.md | 4 ++-- lib/stripe/rails/testing.rb | 19 +++++++++++++++++++ lib/stripe/testing.rb | 17 ----------------- test/testing_spec.rb | 6 +++--- 4 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 lib/stripe/rails/testing.rb delete mode 100644 lib/stripe/testing.rb diff --git a/README.md b/README.md index 60ae2ffa..569fd539 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ See the [complete listing of all stripe events][5], and the [webhook tutorial][6 If you want to test your callbacks, you can use the `Stripe::Testing` module to send mocked Stripe events. ```ruby -require 'stripe/testing' +require 'stripe/rails/testing' test "my callback handles new subscription" do Stripe::Testing.send_event "customer.subscription.created" # Assertions @@ -373,7 +373,7 @@ end You can also overwrite some event properties: ([More info](https://github.com/rebelidealist/stripe-ruby-mock#customizing-webhooks)) ```ruby -require 'stripe/testing' +require 'stripe/rails/testing' test "my callback handles new subscription" do Stripe::Testing.send_event "customer.subscription.created", { :email => "john@doe.com", diff --git a/lib/stripe/rails/testing.rb b/lib/stripe/rails/testing.rb new file mode 100644 index 00000000..f8c432d8 --- /dev/null +++ b/lib/stripe/rails/testing.rb @@ -0,0 +1,19 @@ +begin + require 'stripe_mock' +rescue LoadError + warn %q{Please add "gem 'stripe-ruby-mock', group: 'test'"" to the Gemfile to use Stripe::Testing"} + exit +end +require 'stripe/callbacks' + +module Stripe + module Rails + module Testing + def self.send_event(event, properties = {}) + evt = StripeMock.mock_webhook_event(event, properties) + target = evt.data.object + ::Stripe::Callbacks.run_callbacks(evt, target) + end + end + end +end \ No newline at end of file diff --git a/lib/stripe/testing.rb b/lib/stripe/testing.rb deleted file mode 100644 index 3125dfc7..00000000 --- a/lib/stripe/testing.rb +++ /dev/null @@ -1,17 +0,0 @@ -begin - require 'stripe_mock' -rescue LoadError - warn %q{Please add "gem 'stripe-ruby-mock', group: 'test'"" to the Gemfile to use Stripe::Testing"} - exit -end -require 'stripe/callbacks' - -module Stripe - module Testing - def self.send_event(event, properties = {}) - evt = StripeMock.mock_webhook_event(event, properties) - target = evt.data.object - ::Stripe::Callbacks.run_callbacks(evt, target) - end - end -end \ No newline at end of file diff --git a/test/testing_spec.rb b/test/testing_spec.rb index 345857ed..8782ae9d 100644 --- a/test/testing_spec.rb +++ b/test/testing_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'stripe/testing' +require 'stripe/rails/testing' describe "Testing" do let(:observer) { Class.new } @@ -21,7 +21,7 @@ end describe '.send_event' do - subject { Stripe::Testing.send_event event_name } + subject { Stripe::Rails::Testing.send_event event_name } describe 'when forwarding the event to the callback' do let(:event_name) { "invoice.payment_succeeded" } @@ -43,7 +43,7 @@ end describe 'when overwriting event properties' do - subject { Stripe::Testing.send_event event_name, params } + subject { Stripe::Rails::Testing.send_event event_name, params } let(:event_name) { "invoice.payment_succeeded" } let(:params) { { subtotal: 500, total: 1000, currency: "eur" } } From 0d4a91f9f28d4389bb3066a1a2bebfe204c73106 Mon Sep 17 00:00:00 2001 From: SengMing Tan Date: Thu, 31 Aug 2017 11:09:56 -0400 Subject: [PATCH 5/5] typos --- README.md | 6 +++--- lib/stripe/rails/testing.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 569fd539..cb9e9480 100644 --- a/README.md +++ b/README.md @@ -360,12 +360,12 @@ See the [complete listing of all stripe events][5], and the [webhook tutorial][6 ## Unit testing -If you want to test your callbacks, you can use the `Stripe::Testing` module to send mocked Stripe events. +If you want to test your callbacks, you can use the `Stripe::Rails::Testing` module to send mocked Stripe events. ```ruby require 'stripe/rails/testing' test "my callback handles new subscription" do - Stripe::Testing.send_event "customer.subscription.created" + Stripe::Rails::Testing.send_event "customer.subscription.created" # Assertions end ``` @@ -375,7 +375,7 @@ You can also overwrite some event properties: ([More info](https://github.com/re ```ruby require 'stripe/rails/testing' test "my callback handles new subscription" do - Stripe::Testing.send_event "customer.subscription.created", { + Stripe::Rails::Testing.send_event "customer.subscription.created", { :email => "john@doe.com", :account_balance => 40 } diff --git a/lib/stripe/rails/testing.rb b/lib/stripe/rails/testing.rb index f8c432d8..6dfd2bf0 100644 --- a/lib/stripe/rails/testing.rb +++ b/lib/stripe/rails/testing.rb @@ -1,7 +1,7 @@ begin require 'stripe_mock' rescue LoadError - warn %q{Please add "gem 'stripe-ruby-mock', group: 'test'"" to the Gemfile to use Stripe::Testing"} + warn %q{Please add "gem 'stripe-ruby-mock', group: 'test'"" to the Gemfile to use Stripe::Rails::Testing"} exit end require 'stripe/callbacks'