pay_me 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +111 -0
  3. data/Rakefile +33 -0
  4. data/app/controllers/pay_me/api/v1/invoices_controller.rb +30 -0
  5. data/app/controllers/pay_me/api/v1/stripe_plans_controller.rb +35 -0
  6. data/app/controllers/pay_me/application_controller.rb +10 -0
  7. data/app/helpers/pay_me/application_helper.rb +4 -0
  8. data/app/subscribers/pay_me/customer_subscriber.rb +42 -0
  9. data/app/subscribers/pay_me/plan_subscriber.rb +38 -0
  10. data/app/subscribers/pay_me/subscription_subscriber.rb +50 -0
  11. data/app/subscribers/pay_me/webhook_event_subscriber.rb +11 -0
  12. data/config/routes.rb +11 -0
  13. data/db/migrate/20160725204454_create_pay_me_subscriptions.rb +16 -0
  14. data/db/migrate/20161011170659_create_pay_me_plans.rb +8 -0
  15. data/db/migrate/20171030174731_add_quantity_to_pay_me_subscription.rb +6 -0
  16. data/db/migrate/20171130192525_create_pay_me_customers.rb +11 -0
  17. data/db/migrate/20180116193943_remove_customerable_from_subscriptions.rb +11 -0
  18. data/db/migrate/20180215235017_add_past_due_to_subscriptions.rb +5 -0
  19. data/lib/generators/pay_me/controllers/controllers_generator.rb +11 -0
  20. data/lib/generators/pay_me/controllers/templates/subscriptions_controller.rb +12 -0
  21. data/lib/generators/pay_me/install_generator.rb +39 -0
  22. data/lib/generators/pay_me/migrate_to_customer_model/USAGE +8 -0
  23. data/lib/generators/pay_me/migrate_to_customer_model/migrate_to_customer_model_generator.rb +9 -0
  24. data/lib/generators/pay_me/migrate_to_customer_model/templates/migration.rb.erb +64 -0
  25. data/lib/generators/pay_me/models/models_generator.rb +13 -0
  26. data/lib/generators/pay_me/models/templates/customer.rb +14 -0
  27. data/lib/generators/pay_me/models/templates/plan.rb +14 -0
  28. data/lib/generators/pay_me/models/templates/subscription.rb +14 -0
  29. data/lib/generators/pay_me/policies/policies_generator.rb +11 -0
  30. data/lib/generators/pay_me/policies/templates/subscription_policy.rb +34 -0
  31. data/lib/generators/pay_me/templates/pay_me_initializer.rb +17 -0
  32. data/lib/pay_me.rb +28 -0
  33. data/lib/pay_me/active_record.rb +6 -0
  34. data/lib/pay_me/concerns/controllers/customerable.rb +116 -0
  35. data/lib/pay_me/concerns/models/customerable.rb +54 -0
  36. data/lib/pay_me/concerns/models/stripe_customerable.rb +24 -0
  37. data/lib/pay_me/concerns/models/stripe_plannable.rb +31 -0
  38. data/lib/pay_me/concerns/models/stripe_subscribable.rb +43 -0
  39. data/lib/pay_me/configuration.rb +27 -0
  40. data/lib/pay_me/engine.rb +8 -0
  41. data/lib/pay_me/models.rb +4 -0
  42. data/lib/pay_me/railtie.rb +2 -0
  43. data/lib/pay_me/route_helpers.rb +21 -0
  44. data/lib/pay_me/services/customer.rb +141 -0
  45. data/lib/pay_me/version.rb +3 -0
  46. data/lib/pay_me/view_models/charge.rb +48 -0
  47. data/lib/tasks/pay_me_tasks.rake +4 -0
  48. data/lib/tasks/stripe.rake +22 -0
  49. data/test/controllers/pay_me/api/v1/invoices_controller_test.rb +82 -0
  50. data/test/controllers/pay_me/api/v1/plans_controller_test.rb +62 -0
  51. data/test/dummy/README.rdoc +28 -0
  52. data/test/dummy/Rakefile +6 -0
  53. data/test/dummy/app/assets/javascripts/application.js +13 -0
  54. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  55. data/test/dummy/app/controllers/api/v1/users_controller.rb +10 -0
  56. data/test/dummy/app/controllers/application_controller.rb +5 -0
  57. data/test/dummy/app/controllers/pay_me/api/v1/subscriptions_controller.rb +12 -0
  58. data/test/dummy/app/helpers/application_helper.rb +2 -0
  59. data/test/dummy/app/models/pay_me/customer.rb +5 -0
  60. data/test/dummy/app/models/pay_me/plan.rb +5 -0
  61. data/test/dummy/app/models/pay_me/subscription.rb +5 -0
  62. data/test/dummy/app/models/user.rb +8 -0
  63. data/test/dummy/app/policies/pay_me/subscription_policy.rb +34 -0
  64. data/test/dummy/app/serializers/pay_me/subscription_serializer.rb +3 -0
  65. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  66. data/test/dummy/bin/bundle +3 -0
  67. data/test/dummy/bin/rails +4 -0
  68. data/test/dummy/bin/rake +4 -0
  69. data/test/dummy/bin/setup +29 -0
  70. data/test/dummy/config.ru +4 -0
  71. data/test/dummy/config/application.rb +25 -0
  72. data/test/dummy/config/boot.rb +5 -0
  73. data/test/dummy/config/database.yml +25 -0
  74. data/test/dummy/config/environment.rb +5 -0
  75. data/test/dummy/config/environments/development.rb +41 -0
  76. data/test/dummy/config/environments/production.rb +79 -0
  77. data/test/dummy/config/environments/test.rb +42 -0
  78. data/test/dummy/config/initializers/assets.rb +11 -0
  79. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  80. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  81. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  82. data/test/dummy/config/initializers/inflections.rb +16 -0
  83. data/test/dummy/config/initializers/mime_types.rb +4 -0
  84. data/test/dummy/config/initializers/pay_me.rb +17 -0
  85. data/test/dummy/config/initializers/session_store.rb +3 -0
  86. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  87. data/test/dummy/config/locales/en.yml +23 -0
  88. data/test/dummy/config/routes.rb +10 -0
  89. data/test/dummy/config/secrets.yml +22 -0
  90. data/test/dummy/db/migrate/20160630181300_create_pay_me_users.rb +12 -0
  91. data/test/dummy/db/migrate/20180118001940_api_me_migrate_to_customer_model.rb +9 -0
  92. data/test/dummy/db/schema.rb +53 -0
  93. data/test/dummy/public/404.html +67 -0
  94. data/test/dummy/public/422.html +67 -0
  95. data/test/dummy/public/500.html +66 -0
  96. data/test/dummy/public/favicon.ico +0 -0
  97. data/test/integration/customer_test.rb +395 -0
  98. data/test/lib/generators/pay_me/pay_me/migrate_to_customer_model_generator_test.rb +16 -0
  99. data/test/models/pay_me/customer_test.rb +9 -0
  100. data/test/models/pay_me/subscription_test.rb +9 -0
  101. data/test/models/pay_me/user_test.rb +6 -0
  102. data/test/pay_me_test.rb +7 -0
  103. data/test/support/concerns/api_test_helper.rb +15 -0
  104. data/test/support/concerns/stripe_helpers.rb +25 -0
  105. data/test/test_helper.rb +52 -0
  106. data/test/unit/concerns/customerable.rb +21 -0
  107. data/test/unit/models/customerable_test.rb +18 -0
  108. data/test/unit/services/customer_test.rb +75 -0
  109. data/test/unit/stubs/customerable.rb +28 -0
  110. data/test/unit/stubs/customerable_test.rb +16 -0
  111. data/test/webhooks/customer_webhook_test.rb +74 -0
  112. data/test/webhooks/plan_webhook_test.rb +74 -0
  113. metadata +288 -0
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'generators/pay_me/migrate_to_customer_model/migrate_to_customer_model_generator'
3
+
4
+ module PayMe
5
+ class PayMe::MigrateToCustomerModelGeneratorTest < Rails::Generators::TestCase
6
+ tests PayMe::MigrateToCustomerModelGenerator
7
+ destination Rails.root.join('tmp/generators')
8
+ setup :prepare_destination
9
+
10
+ # test "generator runs without errors" do
11
+ # assert_nothing_raised do
12
+ # run_generator ["arguments"]
13
+ # end
14
+ # end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module PayMe
4
+ class CustomerTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module PayMe
4
+ class SubscriptionTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ module PayMe
4
+ class UserTest < ActiveSupport::TestCase
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PayMeTest < ActiveSupport::TestCase
4
+ test 'truth' do
5
+ assert_kind_of Module, PayMe
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/test_help'
2
+ require 'rack/test'
3
+
4
+ module PayMe
5
+ module Support
6
+ module ApiTestHelper
7
+ include Engine.routes.url_helpers
8
+ include Rack::Test::Methods
9
+
10
+ def app
11
+ Rails.application
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest/autorun'
2
+
3
+ module Minitest
4
+ class Spec
5
+ def self.with_a_monthly_plan(&block) # rubocop:disable Metrics/MethodLength
6
+ describe 'looking to subscribe to a monthly plan' do
7
+ after do
8
+ plan.delete
9
+ end
10
+
11
+ let(:plan) do
12
+ Stripe::Plan.create(
13
+ amount: 200,
14
+ interval: 'month',
15
+ name: 'This is a automated tests monthly plan',
16
+ currency: 'usd',
17
+ id: "pay_me_monthly_test-#{SecureRandom.uuid}"
18
+ )
19
+ end
20
+
21
+ instance_exec(&block)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,52 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+ require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
4
+ ActiveRecord::Migrator.migrations_paths = [
5
+ File.expand_path('../../test/dummy/db/migrate', __FILE__)
6
+ ]
7
+ ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
8
+ require 'minitest/pride'
9
+ require 'stripe'
10
+ require 'vcr'
11
+ require 'minitest-vcr'
12
+ require 'webmock'
13
+ require 'stripe_mock'
14
+ require 'spy/integration'
15
+ require 'database_cleaner'
16
+ require 'dotenv/load'
17
+
18
+ VCR.configure do |c|
19
+ c.cassette_library_dir = 'test/cassettes'
20
+ c.hook_into :webmock
21
+ c.filter_sensitive_data("<ENV['STRIPE_TEST_PUBLISHABLE_KEY']>") { ENV['STRIPE_TEST_PUBLISHABLE_KEY'] }
22
+ c.allow_http_connections_when_no_cassette = true
23
+ end
24
+
25
+ DatabaseCleaner.strategy = :transaction
26
+
27
+ class Minitest::Test
28
+ def before_setup
29
+ super
30
+ DatabaseCleaner.clean
31
+ DatabaseCleaner.start
32
+ end
33
+ end
34
+
35
+
36
+ MinitestVcr::Spec.configure!
37
+
38
+ # Stripe.api_key = ENV['STRIPE_TEST_SECRET_KEY']
39
+
40
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
41
+ # to be shown.
42
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
43
+
44
+ # Load support files
45
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
46
+
47
+ # Load fixtures from the engine
48
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
49
+ ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
50
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
51
+ ActiveSupport::TestCase.fixtures :all
52
+ end
@@ -0,0 +1,21 @@
1
+ module PayMe
2
+ module Concerns
3
+ module CustomerableInterfaceTest
4
+ def test_responds_to_customer_service
5
+ assert_respond_to(@object, :customer_service)
6
+ end
7
+
8
+ def test_responds_to_customer_id
9
+ assert_respond_to(@object, :customer_id)
10
+ end
11
+
12
+ def test_responds_to_update!
13
+ assert_respond_to(@object, :update!)
14
+ end
15
+
16
+ def test_responds_to_id
17
+ assert_respond_to(@object, :id)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'securerandom'
2
+ require 'test_helper'
3
+ require 'unit/concerns/customerable'
4
+
5
+ module PayMe
6
+ module Models
7
+ class TestCustomerableInterface < Minitest::Test
8
+ include PayMe::Concerns::CustomerableInterfaceTest
9
+
10
+ def setup
11
+ ActiveRecord::Base.transaction do
12
+ customer = PayMe::Customer.create!(customer_id: SecureRandom.uuid)
13
+ @object = User.create(customer: customer)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,75 @@
1
+ require 'minitest/mock'
2
+ require 'minitest/test'
3
+ require 'securerandom'
4
+ require 'test_helper'
5
+ require 'pay_me/services/customer'
6
+ require 'unit/stubs/customerable'
7
+
8
+ module PayMe
9
+ module Services
10
+ class TestCustomerService < Minitest::Test
11
+ # def setup
12
+ # customer_class_mock = Minitest::Mock.new
13
+ # customerable_stub = PayMe::Stubs::Customerable.new
14
+
15
+ # @object = PayMe::Services::Customer.new(
16
+ # customerable: customerable_stub,
17
+ # customer_class: customer_class_mock
18
+ # )
19
+ # end
20
+
21
+ # def test_create_will_invoke_the_create_method_on_the_customer_class
22
+ # customer_mock = Minitest::Mock.new
23
+ # customer_mock.expect :id, SecureRandom.uuid
24
+
25
+ # @object.customer_class.expect :create, customer_mock, [Hash]
26
+ # @object.create!({})
27
+ # @object.customer_class.verify
28
+ # end
29
+
30
+ # def test_create_will_create_a_new_customer
31
+ # customer_mock = Minitest::Mock.new
32
+ # customer_mock.expect :id, SecureRandom.uuid
33
+
34
+ # @object.customer_class.expect :create, customer_mock, [Hash]
35
+ # @object.create!({})
36
+ # assert @object.customer, 'The create! method should create a new customer'
37
+ # end
38
+
39
+ # def test_create_will_set_the_customer_id_on_the_customerable_instance
40
+ # customer_mock = Minitest::Mock.new
41
+ # customer_mock.expect :id, SecureRandom.uuid
42
+
43
+ # @object.customer_class.expect :create, customer_mock, [Hash]
44
+ # @object.create!({})
45
+
46
+ # assert @object.customerable.customer_id,
47
+ # 'The create! method should set the customer id on the customerable instance'
48
+ # end
49
+
50
+ # def test_destroy_will_invoke_the_delete_method_on_the_customer_class
51
+ # customer_mock = Minitest::Mock.new
52
+ # customer_mock.expect :delete, customer_mock
53
+ # @object.customerable.customer_id = SecureRandom.uuid
54
+ # @object.customer_class.expect :retrieve, customer_mock, [String]
55
+ # @object.destroy!
56
+ # customer_mock.verify
57
+ # end
58
+
59
+ # def test_customer_will_invoke_the_retieve_method_on_the_customer_class_if_an_id_exists
60
+ # customer_mock = Minitest::Mock.new
61
+ # @object.customerable.customer_id = SecureRandom.uuid
62
+ # @object.customer_class.expect :retrieve, customer_mock, [String]
63
+ # @object.customer
64
+ # @object.customer_class.verify
65
+ # end
66
+
67
+ # def test_customer_will_raise_on_the_retieve_method_on_the_customer_class_if_an_id_does_not_exist
68
+ # customer_mock = Minitest::Mock.new
69
+ # assert_raises RuntimeError do
70
+ # @object.customer
71
+ # end
72
+ # end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,28 @@
1
+ require 'securerandom'
2
+ require 'pay_me/services/customer'
3
+
4
+ module PayMe
5
+ module Stubs
6
+ class Customerable
7
+ attr_accessor :customer_id
8
+
9
+ def initialize
10
+ end
11
+
12
+ def update!(params)
13
+ self.customer_id = params[:customer_id]
14
+ end
15
+
16
+ def customer_service
17
+ PayMe::Services::Customer.new(
18
+ customerable: self,
19
+ customer_class: nil
20
+ )
21
+ end
22
+
23
+ def id
24
+ SecureRandom.uuid
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'unit/stubs/customerable'
3
+ require 'unit/concerns/customerable'
4
+
5
+ module PayMe
6
+ module Stubs
7
+ # Mixin Interface tests to insure the stub matches the correct interface
8
+ class TestCustomerableStub < Minitest::Test
9
+ include PayMe::Concerns::CustomerableInterfaceTest
10
+
11
+ def setup
12
+ @object = PayMe::Stubs::Customerable.new
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+ require 'webmock/minitest'
3
+
4
+ describe "Customer Events" do
5
+ include PayMe::Support::ApiTestHelper # Mixin get/post/etc... methods, see /test/test_helper.rb for details
6
+ before { StripeMock.start }
7
+ after { StripeMock.stop }
8
+ let(:customer_id) { 'cus_CBY9H0MMBoZfnu' }
9
+
10
+ describe "customer.created" do
11
+ let(:event) { StripeMock.mock_webhook_event('customer.created', id: customer_id) }
12
+
13
+ it "is successful if customer does not exist" do
14
+ assert_equal 0, PayMe::Customer.count
15
+ callback_spy = Spy.on(PayMe::Customer, :created_webhook!)
16
+ post "/pay_me/stripe_webhooks", id: event.id
17
+ assert_equal 200, last_response.status
18
+ assert_equal 0, PayMe::Customer.count # Shouldn't autocreate customer
19
+ assert callback_spy.has_been_called?
20
+ end
21
+
22
+ it "is successful if customer does exist" do
23
+ PayMe::Customer.create(customer_id: customer_id)
24
+ assert_equal 1, PayMe::Customer.count
25
+ callback_spy = Spy.on(PayMe::Customer, :created_webhook!)
26
+ post "/pay_me/stripe_webhooks", id: event.id
27
+ assert_equal 200, last_response.status
28
+ assert_equal 1, PayMe::Customer.count
29
+ assert callback_spy.has_been_called?
30
+ end
31
+ end
32
+
33
+ describe "customer.updated" do
34
+ let(:event) { StripeMock.mock_webhook_event('customer.updated', id: customer_id) }
35
+
36
+ it "is successful if Customer does not exist" do
37
+ callback_spy = Spy.on(PayMe::Customer, :updated_webhook!)
38
+ post "/pay_me/stripe_webhooks", id: event.id
39
+ assert_equal 200, last_response.status
40
+ assert callback_spy.has_been_called?
41
+ end
42
+
43
+ it "is successful if Customer does exist" do
44
+ PayMe::Customer.create(customer_id: customer_id)
45
+ callback_spy = Spy.on(PayMe::Customer, :updated_webhook!)
46
+ post "/pay_me/stripe_webhooks", id: event.id
47
+ assert_equal 200, last_response.status
48
+ assert callback_spy.has_been_called?
49
+ end
50
+ end
51
+
52
+ describe "customer.deleted" do
53
+ let(:event) { StripeMock.mock_webhook_event('customer.deleted', id: customer_id) }
54
+
55
+ it "is successful if plan does not exist" do
56
+ assert_equal 0, PayMe::Customer.count
57
+ callback_spy = Spy.on(PayMe::Customer, :deleted_webhook!)
58
+ post "/pay_me/stripe_webhooks", id: event.id
59
+ assert_equal 200, last_response.status
60
+ assert_equal 0, PayMe::Customer.count
61
+ assert callback_spy.has_been_called?
62
+ end
63
+
64
+ it "is successful if plan does exist" do
65
+ PayMe::Customer.create(customer_id: customer_id)
66
+ assert_equal 1, PayMe::Customer.count
67
+ callback_spy = Spy.on(PayMe::Customer, :deleted_webhook!)
68
+ post "/pay_me/stripe_webhooks", id: event.id
69
+ assert_equal 200, last_response.status
70
+ assert_equal 0, PayMe::Customer.count
71
+ assert callback_spy.has_been_called?
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+ require 'webmock/minitest'
3
+
4
+ describe "Plan Events" do
5
+ include PayMe::Support::ApiTestHelper # Mixin get/post/etc... methods, see /test/test_helper.rb for details
6
+ before { StripeMock.start }
7
+ after { StripeMock.stop }
8
+ let(:plan_id) { 'test_plan' }
9
+
10
+ describe "plan.created" do
11
+ let(:event) { StripeMock.mock_webhook_event('plan.created', id: plan_id) }
12
+
13
+ it "is successful if plan does not exist" do
14
+ assert_equal 0, PayMe::Plan.count
15
+ callback_spy = Spy.on(PayMe::Plan, :created_webhook!)
16
+ post "/pay_me/stripe_webhooks", id: event.id
17
+ assert_equal 200, last_response.status
18
+ assert_equal 1, PayMe::Plan.count
19
+ assert callback_spy.has_been_called?
20
+ end
21
+
22
+ it "is successful if plan does exist" do
23
+ PayMe::Plan.create(plan_id: plan_id)
24
+ assert_equal 1, PayMe::Plan.count
25
+ callback_spy = Spy.on(PayMe::Plan, :created_webhook!)
26
+ post "/pay_me/stripe_webhooks", id: event.id
27
+ assert_equal 200, last_response.status
28
+ assert_equal 1, PayMe::Plan.count
29
+ assert callback_spy.has_been_called?
30
+ end
31
+ end
32
+
33
+ describe "plan.updated" do
34
+ let(:event) { StripeMock.mock_webhook_event('plan.updated', id: plan_id) }
35
+
36
+ it "is successful if plan does not exist" do
37
+ callback_spy = Spy.on(PayMe::Plan, :updated_webhook!)
38
+ post "/pay_me/stripe_webhooks", id: event.id
39
+ assert_equal 200, last_response.status
40
+ assert callback_spy.has_been_called?
41
+ end
42
+
43
+ it "is successful if plan does exist" do
44
+ PayMe::Plan.create(plan_id: plan_id)
45
+ callback_spy = Spy.on(PayMe::Plan, :updated_webhook!)
46
+ post "/pay_me/stripe_webhooks", id: event.id
47
+ assert_equal 200, last_response.status
48
+ assert callback_spy.has_been_called?
49
+ end
50
+ end
51
+
52
+ describe "plan.deleted" do
53
+ let(:event) { StripeMock.mock_webhook_event('plan.deleted', id: plan_id) }
54
+
55
+ it "is successful if plan does not exist" do
56
+ assert_equal 0, PayMe::Plan.count
57
+ callback_spy = Spy.on(PayMe::Plan, :deleted_webhook!)
58
+ post "/pay_me/stripe_webhooks", id: event.id
59
+ assert_equal 200, last_response.status
60
+ assert_equal 0, PayMe::Plan.count
61
+ assert callback_spy.has_been_called?
62
+ end
63
+
64
+ it "is successful if plan does exist" do
65
+ PayMe::Plan.create(plan_id: plan_id)
66
+ assert_equal 1, PayMe::Plan.count
67
+ callback_spy = Spy.on(PayMe::Plan, :deleted_webhook!)
68
+ post "/pay_me/stripe_webhooks", id: event.id
69
+ assert_equal 200, last_response.status
70
+ assert_equal 0, PayMe::Plan.count
71
+ assert callback_spy.has_been_called?
72
+ end
73
+ end
74
+ end