effective_orders 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +856 -0
- data/Rakefile +24 -0
- data/app/assets/images/effective_orders/stripe_connect.png +0 -0
- data/app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee +30 -0
- data/app/assets/javascripts/effective_orders/stripe_charges.js.coffee +26 -0
- data/app/assets/javascripts/effective_orders/stripe_subscriptions.js.coffee +28 -0
- data/app/assets/javascripts/effective_orders.js +2 -0
- data/app/assets/stylesheets/effective_orders/_order.scss +30 -0
- data/app/assets/stylesheets/effective_orders.css.scss +1 -0
- data/app/controllers/admin/customers_controller.rb +15 -0
- data/app/controllers/admin/orders_controller.rb +22 -0
- data/app/controllers/effective/carts_controller.rb +70 -0
- data/app/controllers/effective/orders_controller.rb +191 -0
- data/app/controllers/effective/providers/moneris.rb +94 -0
- data/app/controllers/effective/providers/paypal.rb +29 -0
- data/app/controllers/effective/providers/stripe.rb +125 -0
- data/app/controllers/effective/providers/stripe_connect.rb +47 -0
- data/app/controllers/effective/subscriptions_controller.rb +123 -0
- data/app/controllers/effective/webhooks_controller.rb +86 -0
- data/app/helpers/effective_carts_helper.rb +90 -0
- data/app/helpers/effective_orders_helper.rb +108 -0
- data/app/helpers/effective_paypal_helper.rb +37 -0
- data/app/helpers/effective_stripe_helper.rb +63 -0
- data/app/mailers/effective/orders_mailer.rb +64 -0
- data/app/models/concerns/acts_as_purchasable.rb +134 -0
- data/app/models/effective/access_denied.rb +17 -0
- data/app/models/effective/cart.rb +65 -0
- data/app/models/effective/cart_item.rb +40 -0
- data/app/models/effective/customer.rb +61 -0
- data/app/models/effective/datatables/customers.rb +45 -0
- data/app/models/effective/datatables/orders.rb +53 -0
- data/app/models/effective/order.rb +247 -0
- data/app/models/effective/order_item.rb +69 -0
- data/app/models/effective/stripe_charge.rb +35 -0
- data/app/models/effective/subscription.rb +95 -0
- data/app/models/inputs/price_field.rb +63 -0
- data/app/models/inputs/price_form_input.rb +7 -0
- data/app/models/inputs/price_formtastic_input.rb +9 -0
- data/app/models/inputs/price_input.rb +19 -0
- data/app/models/inputs/price_simple_form_input.rb +8 -0
- data/app/models/validators/effective/sold_out_validator.rb +7 -0
- data/app/views/active_admin/effective_orders/orders/_show.html.haml +70 -0
- data/app/views/admin/customers/_actions.html.haml +2 -0
- data/app/views/admin/customers/index.html.haml +10 -0
- data/app/views/admin/orders/index.html.haml +7 -0
- data/app/views/admin/orders/show.html.haml +11 -0
- data/app/views/effective/carts/_cart.html.haml +33 -0
- data/app/views/effective/carts/show.html.haml +18 -0
- data/app/views/effective/orders/_checkout_step_1.html.haml +39 -0
- data/app/views/effective/orders/_checkout_step_2.html.haml +18 -0
- data/app/views/effective/orders/_my_purchases.html.haml +15 -0
- data/app/views/effective/orders/_order.html.haml +4 -0
- data/app/views/effective/orders/_order_header.html.haml +21 -0
- data/app/views/effective/orders/_order_items.html.haml +39 -0
- data/app/views/effective/orders/_order_payment_details.html.haml +11 -0
- data/app/views/effective/orders/_order_shipping.html.haml +19 -0
- data/app/views/effective/orders/_order_user_fields.html.haml +10 -0
- data/app/views/effective/orders/checkout.html.haml +3 -0
- data/app/views/effective/orders/declined.html.haml +10 -0
- data/app/views/effective/orders/moneris/_form.html.haml +34 -0
- data/app/views/effective/orders/my_purchases.html.haml +6 -0
- data/app/views/effective/orders/my_sales.html.haml +28 -0
- data/app/views/effective/orders/new.html.haml +4 -0
- data/app/views/effective/orders/paypal/_form.html.haml +5 -0
- data/app/views/effective/orders/purchased.html.haml +10 -0
- data/app/views/effective/orders/show.html.haml +17 -0
- data/app/views/effective/orders/stripe/_form.html.haml +8 -0
- data/app/views/effective/orders/stripe/_subscription_fields.html.haml +7 -0
- data/app/views/effective/orders_mailer/order_receipt_to_admin.html.haml +8 -0
- data/app/views/effective/orders_mailer/order_receipt_to_buyer.html.haml +8 -0
- data/app/views/effective/orders_mailer/order_receipt_to_seller.html.haml +30 -0
- data/app/views/effective/subscriptions/index.html.haml +16 -0
- data/app/views/effective/subscriptions/new.html.haml +10 -0
- data/app/views/effective/subscriptions/show.html.haml +49 -0
- data/config/routes.rb +57 -0
- data/db/migrate/01_create_effective_orders.rb.erb +91 -0
- data/db/upgrade/02_upgrade_effective_orders_from03x.rb.erb +29 -0
- data/db/upgrade/upgrade_price_column_on_table.rb.erb +17 -0
- data/lib/effective_orders/engine.rb +52 -0
- data/lib/effective_orders/version.rb +3 -0
- data/lib/effective_orders.rb +76 -0
- data/lib/generators/effective_orders/install_generator.rb +38 -0
- data/lib/generators/effective_orders/upgrade_from03x_generator.rb +34 -0
- data/lib/generators/effective_orders/upgrade_price_column_generator.rb +34 -0
- data/lib/generators/templates/README +1 -0
- data/lib/generators/templates/effective_orders.rb +210 -0
- data/spec/controllers/carts_controller_spec.rb +143 -0
- data/spec/controllers/moneris_orders_controller_spec.rb +245 -0
- data/spec/controllers/orders_controller_spec.rb +418 -0
- data/spec/controllers/stripe_orders_controller_spec.rb +127 -0
- data/spec/controllers/webhooks_controller_spec.rb +79 -0
- data/spec/dummy/README.rdoc +8 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/product.rb +17 -0
- data/spec/dummy/app/models/product_with_float_price.rb +17 -0
- data/spec/dummy/app/models/user.rb +28 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +31 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +83 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +254 -0
- data/spec/dummy/config/initializers/effective_addresses.rb +15 -0
- data/spec/dummy/config/initializers/effective_orders.rb +22 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +142 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +487 -0
- data/spec/dummy/log/test.log +347 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helpers/effective_orders_helper_spec.rb +21 -0
- data/spec/models/acts_as_purchasable_spec.rb +107 -0
- data/spec/models/customer_spec.rb +71 -0
- data/spec/models/factories_spec.rb +13 -0
- data/spec/models/order_item_spec.rb +35 -0
- data/spec/models/order_spec.rb +323 -0
- data/spec/models/stripe_charge_spec.rb +39 -0
- data/spec/models/subscription_spec.rb +103 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/factories.rb +118 -0
- metadata +387 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Effective::CartsController do
|
4
|
+
routes { EffectiveOrders::Engine.routes }
|
5
|
+
|
6
|
+
let(:user) { FactoryGirl.create(:user) }
|
7
|
+
let(:cart) { FactoryGirl.create(:cart) }
|
8
|
+
let(:product) { FactoryGirl.create(:product) }
|
9
|
+
|
10
|
+
describe 'First time user - not logged in' do
|
11
|
+
it 'creates a new cart and set the session[:cart]' do
|
12
|
+
get :show
|
13
|
+
assigns(:cart).id.should eq session[:cart]
|
14
|
+
assigns(:cart).size.should eq 0
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'allows me to add_to_cart' do
|
18
|
+
get :add_to_cart, :purchasable_type => product.class, :purchasable_id => product.id
|
19
|
+
assigns(:cart).size.should eq 1
|
20
|
+
assigns(:cart).find(product).present?.should eq true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'allow me to remove_from_cart' do
|
24
|
+
get :add_to_cart, :purchasable_type => product.class, :purchasable_id => product.id
|
25
|
+
assigns(:cart).size.should eq 1
|
26
|
+
assigns(:cart).find(product).present?.should eq true
|
27
|
+
|
28
|
+
delete :remove_from_cart, :id => assigns(:cart).cart_items.first.id
|
29
|
+
assigns(:cart).reload.size.should eq 0
|
30
|
+
assigns(:cart).find(product).present?.should eq false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'allow me to destroy the cart' do
|
34
|
+
get :add_to_cart, :purchasable_type => product.class, :purchasable_id => product.id
|
35
|
+
assigns(:cart).size.should eq 1
|
36
|
+
|
37
|
+
delete :destroy
|
38
|
+
response.should redirect_to('/cart')
|
39
|
+
|
40
|
+
# This redirects me, and reassigns the @cart
|
41
|
+
assigns(:cart).size.should eq 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'Logging in' do
|
46
|
+
describe 'with no previous cart' do
|
47
|
+
it 'assigns a new cart and unsets session[:cart]' do
|
48
|
+
session[:cart] = 12
|
49
|
+
sign_in user
|
50
|
+
|
51
|
+
get :show
|
52
|
+
|
53
|
+
assigns(:cart).user.should eq user
|
54
|
+
assigns(:cart).size.should eq 0
|
55
|
+
|
56
|
+
session[:cart].should eq nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'with an existing cart' do
|
61
|
+
it 'assigns me the existing cart' do
|
62
|
+
sign_in cart.user
|
63
|
+
get :show
|
64
|
+
assigns(:cart).should eq cart
|
65
|
+
assigns(:cart).size.should eq 3 # As per our factory
|
66
|
+
session[:cart].should eq nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'with no existing user cart, and a session cart full of items' do
|
71
|
+
it 'copies the session cart items into the user cart' do
|
72
|
+
get :show
|
73
|
+
assigns(:cart).id.should eq session[:cart]
|
74
|
+
assigns(:cart).size.should eq 0
|
75
|
+
|
76
|
+
get :add_to_cart, :purchasable_type => product.class, :purchasable_id => product.id
|
77
|
+
assigns(:cart).size.should eq 1
|
78
|
+
assigns(:cart).find(product).present?.should eq true
|
79
|
+
|
80
|
+
sign_in user
|
81
|
+
controller.instance_variable_set(:@cart, nil) # This is what happens in a real RailsController. zzz.
|
82
|
+
|
83
|
+
get :show
|
84
|
+
|
85
|
+
assigns(:cart).user.should eq user
|
86
|
+
assigns(:cart).size.should eq 1
|
87
|
+
assigns(:cart).find(product).present?.should eq true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'with an existing user cart, and a session cart full of items' do
|
92
|
+
it 'merges the session cart into the user cart and destroy the session cart' do
|
93
|
+
get :show
|
94
|
+
session_cart = session[:cart]
|
95
|
+
|
96
|
+
assigns(:cart).id.should eq session[:cart]
|
97
|
+
assigns(:cart).size.should eq 0
|
98
|
+
|
99
|
+
get :add_to_cart, :purchasable_type => product.class, :purchasable_id => product.id
|
100
|
+
assigns(:cart).size.should eq 1
|
101
|
+
assigns(:cart).find(product).present?.should eq true
|
102
|
+
|
103
|
+
sign_in cart.user
|
104
|
+
controller.instance_variable_set(:@cart, nil) # This is what happens in a real RailsController. zzz.
|
105
|
+
|
106
|
+
get :show
|
107
|
+
assigns(:cart).user.should eq cart.user
|
108
|
+
assigns(:cart).size.should eq 4 # the 3 from my factory, and 1 more we just created
|
109
|
+
assigns(:cart).find(product).present?.should eq true
|
110
|
+
|
111
|
+
Effective::Cart.where(:id => session_cart).should eq []
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#add_to_cart' do
|
117
|
+
before(:each) do
|
118
|
+
sign_in cart.user
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'provides a useful error when passed an unknown purchasable_id' do
|
122
|
+
get :add_to_cart, :purchasable_type => product.class, :purchasable_id => 'asdf'
|
123
|
+
|
124
|
+
assigns(:purchasable).should eq nil
|
125
|
+
flash[:danger].include?('Unable to add item').should eq true
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'provides a useful error when passed an unknown purchasable_type' do
|
129
|
+
get :add_to_cart, :purchasable_type => 'Something', :purchasable_id => product.id
|
130
|
+
|
131
|
+
assigns(:purchasable).should eq nil
|
132
|
+
flash[:danger].include?('Unable to add item').should eq true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#remove_from_cart' do
|
137
|
+
it 'throws ActiveRecord::RecordNotFound when passed an invalid ID' do
|
138
|
+
expect { delete :remove_from_cart, :id => 12345 }.to raise_error(ActiveRecord::RecordNotFound)
|
139
|
+
assigns(:cart_item).should eq nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# We're testing the effective/providers/moneris.rb file, which is included into the OrdersController at runtime
|
4
|
+
|
5
|
+
describe Effective::OrdersController do
|
6
|
+
routes { EffectiveOrders::Engine.routes }
|
7
|
+
|
8
|
+
let(:order) { FactoryGirl.create(:order) }
|
9
|
+
let(:moneris_params) do
|
10
|
+
{
|
11
|
+
:response_order_id => "#{order.to_param}",
|
12
|
+
:date_stamp => '2014-10-27',
|
13
|
+
:time_stamp => '17:42:31',
|
14
|
+
:bank_transaction_id =>'660110910011137660',
|
15
|
+
:charge_total => "#{'%.2f' % order.total}",
|
16
|
+
:bank_approval_code => '497365',
|
17
|
+
:response_code => '027',
|
18
|
+
:iso_code => '01',
|
19
|
+
:message => 'APPROVED * =',
|
20
|
+
:trans_name => 'purchase',
|
21
|
+
:cardholder => 'Matt',
|
22
|
+
:f4l4 => '4242***4242',
|
23
|
+
:card =>'V',
|
24
|
+
:expiry_date => '1904',
|
25
|
+
:result => '1',
|
26
|
+
:rvar_authenticity_token => 'nJQf5RKL9SES4uiQIaj4aMNNdIQayEeauOL44iSppD4=',
|
27
|
+
:transactionKey => 'C3kYLXwyMDDFD1ArgxiHFph3wIy1Jx'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'moneris_postback' do
|
32
|
+
before do
|
33
|
+
subject.stub(:send_moneris_verify_request).and_return('') # Dont actually make Moneris requests
|
34
|
+
sign_in order.user
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'invalid parameters' do
|
38
|
+
it 'raises RecordNotFound when passed an unknown order id' do
|
39
|
+
expect {
|
40
|
+
post :moneris_postback, moneris_params.tap { |x| x[:response_order_id] = 999 }
|
41
|
+
}.to raise_error(ActiveRecord::RecordNotFound)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'declined purchase params' do
|
46
|
+
it 'marks an order declined when params[:result] indicate decline' do
|
47
|
+
subject.should_not_receive(:send_moneris_verify_request)
|
48
|
+
subject.should_not_receive(:parse_moneris_response)
|
49
|
+
|
50
|
+
post :moneris_postback, moneris_params.tap { |x| x[:result] = 'null' }
|
51
|
+
|
52
|
+
response.should redirect_to "/orders/#{order.to_param}/declined"
|
53
|
+
assigns(:order).declined?.should eq true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'marks an order declined when params[:transactionKey] is blank' do
|
57
|
+
post :moneris_postback, moneris_params.tap { |x| x.delete(:transactionKey) }
|
58
|
+
|
59
|
+
response.should redirect_to "/orders/#{order.to_param}/declined"
|
60
|
+
assigns(:order).declined?.should eq true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'successful purchase params' do
|
65
|
+
it 'sends a moneris verify request when passed successful purchase params' do
|
66
|
+
subject.should_receive(:send_moneris_verify_request)
|
67
|
+
subject.should_receive(:parse_moneris_response)
|
68
|
+
|
69
|
+
post :moneris_postback, moneris_params
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'transaction verification step' do
|
74
|
+
it 'marks the order as purchased when response code is valid' do
|
75
|
+
subject.stub(:parse_moneris_response).and_return({:response_code => 1}) # success
|
76
|
+
|
77
|
+
post :moneris_postback, moneris_params
|
78
|
+
|
79
|
+
response.should redirect_to "/orders/#{order.to_param}/purchased"
|
80
|
+
assigns(:order).purchased?.should eq true
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'marks order declined when response_code = null' do
|
84
|
+
subject.stub(:parse_moneris_response).and_return({:response_code => 'null'}) # failure
|
85
|
+
|
86
|
+
post :moneris_postback, moneris_params
|
87
|
+
|
88
|
+
response.should redirect_to "/orders/#{order.to_param}/declined"
|
89
|
+
assigns(:order).purchased?.should eq false
|
90
|
+
assigns(:order).declined?.should eq true
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'marks order declined when response_code blank' do
|
94
|
+
subject.stub(:parse_moneris_response).and_return({}) # failure
|
95
|
+
|
96
|
+
post :moneris_postback, moneris_params
|
97
|
+
|
98
|
+
response.should redirect_to "/orders/#{order.to_param}/declined"
|
99
|
+
assigns(:order).purchased?.should eq false
|
100
|
+
assigns(:order).declined?.should eq true
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'marks order declined when response_code = 0' do
|
104
|
+
subject.stub(:parse_moneris_response).and_return({:response_code => 0}) # failure
|
105
|
+
post :moneris_postback, moneris_params
|
106
|
+
response.should redirect_to "/orders/#{order.to_param}/declined"
|
107
|
+
assigns(:order).purchased?.should eq false
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'marks order declined when response_code = 50' do
|
111
|
+
subject.stub(:parse_moneris_response).and_return({:response_code => 50}) # failure
|
112
|
+
post :moneris_postback, moneris_params
|
113
|
+
response.should redirect_to "/orders/#{order.to_param}/declined"
|
114
|
+
assigns(:order).purchased?.should eq false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'redirect urls' do
|
119
|
+
it 'redirects to the purchased_redirect_url on purchase' do
|
120
|
+
subject.stub(:parse_moneris_response).and_return({:response_code => 1}) # success
|
121
|
+
post :moneris_postback, moneris_params.tap { |x| x[:rvar_purchased_redirect_url] = '/something' }
|
122
|
+
response.should redirect_to '/something'
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'redirects to the declined_redirect_url on decline' do
|
126
|
+
subject.stub(:parse_moneris_response).and_return({:response_code => 'null'}) # nope
|
127
|
+
post :moneris_postback, moneris_params.tap { |x| x[:rvar_declined_redirect_url] = '/something' }
|
128
|
+
response.should redirect_to '/something'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
# describe '#stripe_charge' do
|
137
|
+
# before do
|
138
|
+
# sign_in order.user
|
139
|
+
# end
|
140
|
+
|
141
|
+
# describe 'invalid parameters' do
|
142
|
+
# it 'raises RecordNotFound when passed an unknown order id' do
|
143
|
+
# expect {
|
144
|
+
# post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_stripe_charge]['effective_order_id'] = 999 }
|
145
|
+
# }.to raise_error(ActiveRecord::RecordNotFound)
|
146
|
+
# end
|
147
|
+
|
148
|
+
# it 'renders the :create action on validation failure' do
|
149
|
+
# subject.should_not_receive(:process_stripe_charge)
|
150
|
+
|
151
|
+
# post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_stripe_charge]['token'] = nil }
|
152
|
+
|
153
|
+
# flash[:danger].downcase.include?('token').should eq true
|
154
|
+
# assigns(:stripe_charge).errors[:token].present?.should eq true
|
155
|
+
|
156
|
+
# assigns(:order).purchased?.should eq false
|
157
|
+
# response.should render_template(:checkout)
|
158
|
+
# end
|
159
|
+
# end
|
160
|
+
|
161
|
+
# describe 'valid parameters' do
|
162
|
+
# it 'redirects to order_purchase_path on success' do
|
163
|
+
# post :stripe_charge, stripe_charge_params
|
164
|
+
# assigns(:order).purchased?.should eq true
|
165
|
+
# response.should redirect_to "/orders/#{assigns(:order).to_param}/purchased"
|
166
|
+
# end
|
167
|
+
|
168
|
+
# it 'assigns the @stripe_charge, @order and @buyer properly' do
|
169
|
+
# post :stripe_charge, stripe_charge_params
|
170
|
+
|
171
|
+
# assigns(:stripe_charge).valid?.should eq true
|
172
|
+
# assigns(:stripe_charge).order.should eq order
|
173
|
+
# assigns(:order).should eq order
|
174
|
+
# assigns(:buyer).should eq buyer
|
175
|
+
# end
|
176
|
+
|
177
|
+
# it 'calls process_stripe_charge when the stripe_charge form object is valid' do
|
178
|
+
# subject.should_receive(:process_stripe_charge)
|
179
|
+
# post :stripe_charge, stripe_charge_params
|
180
|
+
# end
|
181
|
+
|
182
|
+
# it 'assigns the buyer a new card based on the passed token' do
|
183
|
+
# Effective::Customer.any_instance.should_receive(:update_card!).with(token)
|
184
|
+
# post :stripe_charge, stripe_charge_params
|
185
|
+
# end
|
186
|
+
|
187
|
+
# it 'stores the Stripe::Charge info in the order.payment' do
|
188
|
+
# post :stripe_charge, stripe_charge_params
|
189
|
+
# assigns(:order).payment[:charge]['object'].should eq 'charge'
|
190
|
+
# assigns(:order).payment[:charge]['amount'].should eq (order.total*100).to_i
|
191
|
+
# assigns(:order).payment[:charge]['customer'].should eq buyer.stripe_customer_id
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
|
195
|
+
# describe 'stripe charge errors' do
|
196
|
+
# it 'rollsback the entire transaction when Stripe::Charge fails' do
|
197
|
+
# StripeMock.prepare_card_error(:card_declined)
|
198
|
+
|
199
|
+
# post :stripe_charge, stripe_charge_params
|
200
|
+
|
201
|
+
# assigns(:order).purchased?.should eq false
|
202
|
+
# assigns(:stripe_charge).errors[:base].first.downcase.include?('unable to process order with stripe').should eq true
|
203
|
+
# assigns(:stripe_charge).errors[:base].first.downcase.include?('the card was declined').should eq true
|
204
|
+
# response.should render_template(:checkout)
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
# end
|
208
|
+
|
209
|
+
# describe '#stripe_charge with a subscription' do
|
210
|
+
# let(:order) { FactoryGirl.create(:order_with_subscription) }
|
211
|
+
# let(:buyer) { Effective::Customer.for_user(order.user) }
|
212
|
+
# let(:subscription) { order.order_items[1].purchasable }
|
213
|
+
# let(:token) { 'tok_123456789' }
|
214
|
+
# let(:stripe_charge_params) do
|
215
|
+
# {:effective_stripe_charge => {'effective_order_id' => order.to_param, 'token' => token}}
|
216
|
+
# end
|
217
|
+
|
218
|
+
# before do
|
219
|
+
# sign_in order.user
|
220
|
+
# end
|
221
|
+
|
222
|
+
# it 'redirects to order_purchase_path on success' do
|
223
|
+
# post :stripe_charge, stripe_charge_params
|
224
|
+
# assigns(:order).purchased?.should eq true
|
225
|
+
# response.should redirect_to "/orders/#{assigns(:order).to_param}/purchased"
|
226
|
+
# end
|
227
|
+
|
228
|
+
# it 'makes a Stripe::Charge for only the non-Subscription OrderItems' do
|
229
|
+
# post :stripe_charge, stripe_charge_params
|
230
|
+
# assigns(:order).payment[:charge]['object'].should eq 'charge'
|
231
|
+
# assigns(:order).payment[:charge]['amount'].should eq (order.order_items.first.total * 100).to_i
|
232
|
+
# end
|
233
|
+
|
234
|
+
# it 'makes a Stripe::Subscription for the Subscriptions' do
|
235
|
+
# post :stripe_charge, stripe_charge_params
|
236
|
+
|
237
|
+
# assigns(:order).payment[:subscriptions]["#{subscription.stripe_plan_id}"]['object'].should eq 'subscription'
|
238
|
+
# assigns(:order).payment[:subscriptions]["#{subscription.stripe_plan_id}"]['plan'].should eq subscription.stripe_plan_id
|
239
|
+
# subscription.reload.stripe_subscription_id.present?.should eq true
|
240
|
+
# subscription.reload.stripe_coupon_id.present?.should eq true
|
241
|
+
|
242
|
+
# Effective::Subscription.find(subscription.id).purchased?.should eq true
|
243
|
+
# end
|
244
|
+
# end
|
245
|
+
#end
|