effective_orders 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/effective_orders/version.rb +1 -1
- metadata +10 -258
- data/spec/controllers/admin/orders_controller_spec.rb +0 -243
- data/spec/controllers/carts_controller_spec.rb +0 -143
- data/spec/controllers/ccbill_orders_controller_spec.rb +0 -103
- data/spec/controllers/moneris_orders_controller_spec.rb +0 -133
- data/spec/controllers/orders_controller_spec.rb +0 -500
- data/spec/controllers/stripe_orders_controller_spec.rb +0 -128
- data/spec/controllers/webhooks_controller_spec.rb +0 -170
- data/spec/dummy/README.rdoc +0 -8
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/product.rb +0 -9
- data/spec/dummy/app/models/product_with_float_price.rb +0 -9
- data/spec/dummy/app/models/user.rb +0 -11
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -32
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -80
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/devise.rb +0 -254
- data/spec/dummy/config/initializers/effective_addresses.rb +0 -15
- data/spec/dummy/config/initializers/effective_orders.rb +0 -269
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/simple_form.rb +0 -189
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/schema.rb +0 -158
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -164
- data/spec/dummy/log/test.log +0 -60
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/stripe_webhooks/invoice.payment_succeeded.without_renewals.json +0 -76
- data/spec/helpers/effective_orders_helper_spec.rb +0 -21
- data/spec/models/acts_as_purchasable_spec.rb +0 -75
- data/spec/models/customer_spec.rb +0 -72
- data/spec/models/factories_spec.rb +0 -35
- data/spec/models/order_item_spec.rb +0 -35
- data/spec/models/order_spec.rb +0 -445
- data/spec/models/stripe_charge_spec.rb +0 -39
- data/spec/models/subscription_spec.rb +0 -103
- data/spec/spec_helper.rb +0 -46
- data/spec/support/factories.rb +0 -139
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# We're testing the effective/providers/stripe.rb file, which is included into the OrdersController at runtime
|
4
|
-
|
5
|
-
describe Effective::OrdersController, type: :controller do
|
6
|
-
routes { EffectiveOrders::Engine.routes }
|
7
|
-
|
8
|
-
before { StripeMock.start }
|
9
|
-
after { StripeMock.stop }
|
10
|
-
|
11
|
-
let(:stripe_helper) { StripeMock.create_test_helper }
|
12
|
-
let(:order) { FactoryGirl.create(:order) }
|
13
|
-
let(:buyer) { Effective::Customer.for_buyer(order.user) }
|
14
|
-
let(:token) { stripe_helper.generate_card_token }
|
15
|
-
let(:stripe_charge_params) do
|
16
|
-
{:effective_providers_stripe_charge => {'effective_order_id' => order.to_param, 'token' => token}}
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#stripe_charge' do
|
20
|
-
before do
|
21
|
-
sign_in order.user
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'invalid parameters' do
|
25
|
-
it 'raises RecordNotFound when passed an unknown order id' do
|
26
|
-
expect {
|
27
|
-
post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_providers_stripe_charge]['effective_order_id'] = 999 }
|
28
|
-
}.to raise_error(ActiveRecord::RecordNotFound)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'renders the :create action on validation failure' do
|
32
|
-
expect(subject).not_to receive(:process_stripe_charge)
|
33
|
-
|
34
|
-
post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_providers_stripe_charge]['token'] = nil }
|
35
|
-
|
36
|
-
flash[:danger].downcase.include?('token').should eq true
|
37
|
-
assigns(:stripe_charge).errors[:token].present?.should eq true
|
38
|
-
|
39
|
-
assigns(:order).purchased?.should eq false
|
40
|
-
response.should render_template(:checkout_step2)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'valid parameters' do
|
45
|
-
it 'redirects to order_purchase_path on success' do
|
46
|
-
post :stripe_charge, stripe_charge_params
|
47
|
-
assigns(:order).purchased?.should eq true
|
48
|
-
response.should redirect_to "/orders/#{assigns(:order).to_param}/purchased"
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'assigns the @stripe_charge, @order and @buyer properly' do
|
52
|
-
post :stripe_charge, stripe_charge_params
|
53
|
-
|
54
|
-
assigns(:stripe_charge).valid?.should eq true
|
55
|
-
assigns(:stripe_charge).order.should eq order
|
56
|
-
assigns(:order).should eq order
|
57
|
-
assigns(:buyer).should eq buyer
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'calls process_stripe_charge when the stripe_charge form object is valid' do
|
61
|
-
expect(subject).to receive(:process_stripe_charge)
|
62
|
-
post :stripe_charge, stripe_charge_params
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'assigns the buyer a new card based on the passed token' do
|
66
|
-
Effective::Customer.any_instance.should_receive(:update_card!).with(token)
|
67
|
-
post :stripe_charge, stripe_charge_params
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'stores the Stripe::Charge info in the order.payment' do
|
71
|
-
post :stripe_charge, stripe_charge_params
|
72
|
-
assigns(:order).payment[:charge]['object'].should eq 'charge'
|
73
|
-
assigns(:order).payment[:charge]['amount'].should eq order.total
|
74
|
-
assigns(:order).payment[:charge]['customer'].should eq buyer.stripe_customer_id
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'stripe charge errors' do
|
79
|
-
it 'rollsback the entire transaction when Stripe::Charge fails' do
|
80
|
-
StripeMock.prepare_card_error(:card_declined)
|
81
|
-
|
82
|
-
post :stripe_charge, stripe_charge_params
|
83
|
-
|
84
|
-
assigns(:order).purchased?.should eq false
|
85
|
-
assigns(:stripe_charge).errors[:base].first.downcase.include?('unable to process order with stripe').should eq true
|
86
|
-
assigns(:stripe_charge).errors[:base].first.downcase.include?('the card was declined').should eq true
|
87
|
-
response.should render_template(:checkout_step2)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#stripe_charge with a subscription' do
|
93
|
-
let(:order) { FactoryGirl.create(:order_with_subscription) }
|
94
|
-
let(:buyer) { Effective::Customer.for_buyer(order.user) }
|
95
|
-
let(:subscription) { order.order_items[1].purchasable }
|
96
|
-
let(:token) { stripe_helper.generate_card_token }
|
97
|
-
let(:stripe_charge_params) do
|
98
|
-
{:effective_providers_stripe_charge => {'effective_order_id' => order.to_param, 'token' => token}}
|
99
|
-
end
|
100
|
-
|
101
|
-
before do
|
102
|
-
sign_in order.user
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'redirects to order_purchase_path on success' do
|
106
|
-
post :stripe_charge, stripe_charge_params
|
107
|
-
assigns(:order).purchased?.should eq true
|
108
|
-
response.should redirect_to "/orders/#{assigns(:order).to_param}/purchased"
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'makes a Stripe::Charge for only the non-Subscription OrderItems' do
|
112
|
-
post :stripe_charge, stripe_charge_params
|
113
|
-
assigns(:order).payment[:charge]['object'].should eq 'charge'
|
114
|
-
assigns(:order).payment[:charge]['amount'].should eq order.order_items.first.total
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'makes a Stripe::Subscription for the Subscriptions' do
|
118
|
-
post :stripe_charge, stripe_charge_params
|
119
|
-
|
120
|
-
assigns(:order).payment[:subscriptions]["#{subscription.stripe_plan_id}"]['object'].should eq 'subscription'
|
121
|
-
assigns(:order).payment[:subscriptions]["#{subscription.stripe_plan_id}"]['plan']['id'].should eq subscription.stripe_plan_id
|
122
|
-
subscription.reload.stripe_subscription_id.present?.should eq true
|
123
|
-
subscription.reload.stripe_coupon_id.present?.should eq true
|
124
|
-
|
125
|
-
Effective::Subscription.find(subscription.id).purchased?.should eq true
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Effective::WebhooksController, type: :controller do
|
4
|
-
routes { EffectiveOrders::Engine.routes }
|
5
|
-
|
6
|
-
before { StripeMock.start }
|
7
|
-
after { StripeMock.stop }
|
8
|
-
|
9
|
-
let(:order) { FactoryGirl.create(:order) }
|
10
|
-
let(:buyer) { Effective::Customer.for_buyer(order.user) }
|
11
|
-
|
12
|
-
let(:event_hash) { event.to_hash }
|
13
|
-
|
14
|
-
describe '#stripe' do
|
15
|
-
let(:event) { StripeMock.mock_webhook_event('customer.subscription.created') }
|
16
|
-
|
17
|
-
it 'retrieves the real event from Stripe based on passed ID' do
|
18
|
-
expect(Stripe::Event).to receive(:retrieve) { event_hash[:id] }
|
19
|
-
post :stripe, event_hash
|
20
|
-
response.code.should eq '200'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'assigns the @event based on the passed ID' do
|
24
|
-
post :stripe, event_hash
|
25
|
-
assigns(:event).id.should eq event_hash[:id]
|
26
|
-
response.code.should eq '200'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'exits immediately when passed a livemode=false event in Production' do
|
30
|
-
event_hash[:livemode] = false
|
31
|
-
Rails.env.stub(:production?).and_return(true)
|
32
|
-
|
33
|
-
post :stripe, event_hash
|
34
|
-
assigns(:event).should eq nil
|
35
|
-
response.code.should eq '200'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'exits immediately when passed a non-object event' do
|
39
|
-
event_hash[:object] = 'not-object'
|
40
|
-
|
41
|
-
post :stripe, event_hash
|
42
|
-
assigns(:event).should eq nil
|
43
|
-
response.code.should eq '200'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#stripe.subscription_created' do
|
48
|
-
let(:event) { StripeMock.mock_webhook_event('customer.subscription.created') }
|
49
|
-
|
50
|
-
before { buyer.update_attributes(stripe_customer_id: event.data.object.customer) }
|
51
|
-
|
52
|
-
it 'assigns the existing customer, if exists' do
|
53
|
-
post :stripe, event_hash
|
54
|
-
assigns(:customer).should eq buyer
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'creates a new purchased Order for the Subscription' do
|
58
|
-
Effective::Subscription.any_instance.stub(:valid?).and_return(true)
|
59
|
-
Effective::Subscription.any_instance.stub(:purchased?).and_return(false)
|
60
|
-
|
61
|
-
post :stripe, event_hash
|
62
|
-
|
63
|
-
assigns(:order).purchased?.should eq true
|
64
|
-
assigns(:order).user.should eq buyer.user
|
65
|
-
assigns(:order).payment.to_s.include?(event_hash[:id]).should eq true
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'does not create an Order for an existing purchased Subscription' do
|
69
|
-
Effective::Subscription.any_instance.stub(:valid?).and_return(true)
|
70
|
-
Effective::Subscription.any_instance.stub(:purchased?).and_return(true)
|
71
|
-
|
72
|
-
post :stripe, event_hash
|
73
|
-
|
74
|
-
assigns(:order).present?.should eq false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#stripe.subscription_deleted' do
|
79
|
-
let(:event) { StripeMock.mock_webhook_event('customer.subscription.deleted') }
|
80
|
-
let!(:subscription) { FactoryGirl.create(:subscription, customer_id: buyer.id) }
|
81
|
-
|
82
|
-
context 'when customer exists' do
|
83
|
-
before do
|
84
|
-
buyer.update_attributes(stripe_customer_id: event.data.object.customer)
|
85
|
-
subscription.stripe_plan_id = event.data.object.plan.id
|
86
|
-
subscription.save(validate: false)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'assigns the existing customer' do
|
90
|
-
post :stripe, event_hash
|
91
|
-
assigns(:customer).should eq buyer
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should destroy customer subscription' do
|
95
|
-
expect { post :stripe, event_hash }.to change { buyer.subscriptions.count }.from(1).to(0)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should invoke subscription_deleted_callback' do
|
99
|
-
expect(controller).to receive(:subscription_deleted_callback)
|
100
|
-
post :stripe, event_hash
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when customer does not exist' do
|
105
|
-
it 'should not destroy any of subscriptions' do
|
106
|
-
expect { post :stripe, event_hash }.not_to change { Effective::Subscription.count }
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should not invoke subscription_deleted_callback' do
|
110
|
-
expect(controller).not_to receive(:subscription_deleted_callback)
|
111
|
-
post :stripe, event_hash
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe '#stripe.invoice_payment_succeeded' do
|
117
|
-
let(:event) { StripeMock.mock_webhook_event('invoice.payment_succeeded') }
|
118
|
-
|
119
|
-
context 'when customer exists' do
|
120
|
-
before { buyer.update_attributes(stripe_customer_id: event.data.object.customer) }
|
121
|
-
|
122
|
-
context 'when subscription payments present' do
|
123
|
-
context 'with renewals' do
|
124
|
-
let(:subscription_mock) { double('subscription', status: 'active', start: 1383672652) }
|
125
|
-
let(:subscriptions) { double('subscriptions', retrieve: subscription_mock) }
|
126
|
-
|
127
|
-
before { allow(Stripe::Customer).to receive(:retrieve).and_return(double('customer', subscriptions: subscriptions)) }
|
128
|
-
|
129
|
-
it 'assigns the existing customer, if exists' do
|
130
|
-
post :stripe, event_hash
|
131
|
-
assigns(:customer).should eq buyer
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should invoke subscription_renewed_callback' do
|
135
|
-
controller.should_receive(:subscription_renewed_callback).with(kind_of(Stripe::Event)).once
|
136
|
-
post :stripe, event_hash
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context 'without renewals' do
|
141
|
-
let(:subscription_mock) { double('subscription', status: 'active', start: 1383759053) } # start and period.start are equal
|
142
|
-
let(:subscriptions) { double('subscriptions', retrieve: subscription_mock) }
|
143
|
-
|
144
|
-
before { Stripe::Customer.should_receive(:retrieve).and_return(double('customer', subscriptions: subscriptions)) }
|
145
|
-
|
146
|
-
it 'should not invoke subscription_renewed_callback' do
|
147
|
-
expect(controller).not_to receive(:subscription_renewed_callback)
|
148
|
-
post :stripe, event_hash
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'when no subscription payments' do
|
154
|
-
let(:event) { StripeMock.mock_webhook_event('invoice.payment_succeeded.without_renewals') }
|
155
|
-
|
156
|
-
it 'should not invoke subscription_renewed_callback' do
|
157
|
-
expect(controller).not_to receive(:subscription_renewed_callback)
|
158
|
-
post :stripe, event_hash
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when customer does not exist' do
|
164
|
-
it 'should not invoke subscription_renewed_callback' do
|
165
|
-
expect(controller).not_to receive(:subscription_renewed_callback)
|
166
|
-
post :stripe, event_hash
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
data/spec/dummy/README.rdoc
DELETED
data/spec/dummy/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
devise :database_authenticatable, :registerable, :rememberable, :recoverable, :trackable, :validatable, :authentication_keys => [:email]
|
3
|
-
|
4
|
-
acts_as_addressable :billing, :shipping
|
5
|
-
|
6
|
-
attr_accessor :first_name, :last_name
|
7
|
-
|
8
|
-
def to_s
|
9
|
-
email
|
10
|
-
end
|
11
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
-
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|
data/spec/dummy/bin/bundle
DELETED
data/spec/dummy/bin/rails
DELETED
data/spec/dummy/bin/rake
DELETED
data/spec/dummy/config.ru
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'rails/all'
|
4
|
-
|
5
|
-
Bundler.require(*Rails.groups)
|
6
|
-
require 'devise'
|
7
|
-
require 'haml'
|
8
|
-
require 'effective_addresses'
|
9
|
-
require 'effective_orders'
|
10
|
-
require 'effective_obfuscation'
|
11
|
-
|
12
|
-
module Dummy
|
13
|
-
class Application < Rails::Application
|
14
|
-
# Settings in config/environments/* take precedence over those specified here.
|
15
|
-
# Application configuration should go into files in config/initializers
|
16
|
-
# -- all .rb files in that directory are automatically loaded.
|
17
|
-
|
18
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
19
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
20
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
21
|
-
|
22
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
23
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
24
|
-
# config.i18n.default_locale = :de
|
25
|
-
|
26
|
-
config.generators do |g|
|
27
|
-
g.template_engine :haml
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|