effective_orders 1.8.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +150 -60
- data/Rakefile +0 -3
- data/active_admin/effective_orders.rb +14 -9
- data/app/assets/javascripts/effective_orders.js +2 -0
- data/app/assets/javascripts/effective_orders/{stripe_charges.js.coffee → providers/stripe_charges.js.coffee} +1 -1
- data/app/assets/javascripts/effective_orders/{stripe_subscriptions.js.coffee → providers/stripe_subscriptions.js.coffee} +1 -1
- data/app/assets/stylesheets/effective_orders/_order.scss +9 -3
- data/app/controllers/admin/orders_controller.rb +87 -3
- data/app/controllers/concerns/acts_as_active_admin_controller.rb +2 -1
- data/app/controllers/effective/carts_controller.rb +4 -2
- data/app/controllers/effective/orders_controller.rb +101 -60
- data/app/controllers/effective/providers/app_checkout.rb +10 -2
- data/app/controllers/effective/providers/ccbill.rb +34 -0
- data/app/controllers/effective/providers/cheque.rb +30 -0
- data/app/controllers/effective/providers/moneris.rb +7 -7
- data/app/controllers/effective/providers/paypal.rb +7 -5
- data/app/controllers/effective/providers/pretend.rb +22 -0
- data/app/controllers/effective/providers/stripe.rb +26 -24
- data/app/controllers/effective/webhooks_controller.rb +1 -1
- data/app/helpers/effective_carts_helper.rb +59 -29
- data/app/helpers/effective_ccbill_helper.rb +25 -0
- data/app/helpers/effective_orders_helper.rb +50 -41
- data/app/helpers/effective_paypal_helper.rb +11 -11
- data/app/mailers/effective/orders_mailer.rb +95 -20
- data/app/models/concerns/acts_as_purchasable.rb +14 -22
- data/app/models/effective/cart.rb +9 -15
- data/app/models/effective/cart_item.rb +15 -13
- data/app/models/effective/customer.rb +9 -9
- data/app/models/effective/datatables/order_items.rb +14 -8
- data/app/models/effective/datatables/orders.rb +56 -69
- data/app/models/effective/order.rb +250 -139
- data/app/models/effective/order_item.rb +23 -16
- data/app/models/effective/product.rb +23 -0
- data/app/models/effective/providers/ccbill_postback.rb +85 -0
- data/app/models/effective/{stripe_charge.rb → providers/stripe_charge.rb} +1 -1
- data/app/models/effective/subscription.rb +16 -12
- data/app/models/effective/tax_rate_calculator.rb +45 -0
- data/app/views/admin/customers/index.html.haml +2 -5
- data/app/views/admin/order_items/index.html.haml +2 -5
- data/app/views/admin/orders/_actions.html.haml +2 -0
- data/app/views/admin/orders/_form.html.haml +28 -0
- data/app/views/admin/orders/_order_item_fields.html.haml +9 -0
- data/app/views/admin/orders/index.html.haml +9 -5
- data/app/views/admin/orders/new.html.haml +3 -0
- data/app/views/effective/carts/_cart.html.haml +3 -12
- data/app/views/effective/carts/_cart_actions.html.haml +4 -0
- data/app/views/effective/carts/show.html.haml +10 -12
- data/app/views/effective/orders/_checkout_step1.html.haml +46 -0
- data/app/views/effective/orders/_checkout_step2.html.haml +33 -0
- data/app/views/effective/orders/_order.html.haml +2 -0
- data/app/views/effective/orders/_order_actions.html.haml +10 -5
- data/app/views/effective/orders/_order_footer.html.haml +1 -0
- data/app/views/effective/orders/_order_items.html.haml +11 -9
- data/app/views/effective/orders/_order_note.html.haml +8 -0
- data/app/views/effective/orders/_order_note_fields.html.haml +5 -0
- data/app/views/effective/orders/_order_shipping.html.haml +4 -4
- data/app/views/effective/orders/_order_user_fields.html.haml +1 -0
- data/app/views/effective/orders/_orders_table.html.haml +27 -0
- data/app/views/effective/orders/ccbill/_form.html.haml +24 -0
- data/app/views/effective/orders/checkout_step1.html.haml +3 -0
- data/app/views/effective/orders/checkout_step2.html.haml +3 -0
- data/app/views/effective/orders/cheque/_form.html.haml +2 -0
- data/app/views/effective/orders/cheque/pay_by_cheque.html.haml +9 -0
- data/app/views/effective/orders/declined.html.haml +4 -2
- data/app/views/effective/orders/my_purchases.html.haml +1 -1
- data/app/views/effective/orders/my_sales.html.haml +1 -1
- data/app/views/effective/orders/purchased.html.haml +3 -2
- data/app/views/effective/orders/show.html.haml +1 -1
- data/app/views/effective/orders/stripe/_form.html.haml +5 -5
- data/app/views/effective/orders_mailer/order_error.html.haml +11 -0
- data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +13 -0
- data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +13 -0
- data/app/views/layouts/effective_orders_mailer_layout.html.haml +7 -7
- data/config/routes.rb +39 -24
- data/db/migrate/01_create_effective_orders.rb.erb +20 -1
- data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +95 -0
- data/lib/effective_orders.rb +67 -9
- data/lib/effective_orders/app_checkout_service.rb +1 -2
- data/lib/effective_orders/engine.rb +46 -14
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/effective_orders/install_generator.rb +1 -0
- data/lib/generators/effective_orders/upgrade_from03x_generator.rb +1 -0
- data/lib/generators/effective_orders/upgrade_from1x_generator.rb +31 -0
- data/lib/generators/templates/effective_orders.rb +131 -66
- data/lib/generators/templates/effective_orders_mailer_preview.rb +28 -13
- data/spec/controllers/admin/orders_controller_spec.rb +242 -0
- data/spec/controllers/ccbill_orders_controller_spec.rb +103 -0
- data/spec/controllers/moneris_orders_controller_spec.rb +23 -23
- data/spec/controllers/orders_controller_spec.rb +167 -79
- data/spec/controllers/stripe_orders_controller_spec.rb +7 -7
- data/spec/dummy/app/models/product.rb +0 -8
- data/spec/dummy/app/models/product_with_float_price.rb +0 -8
- data/spec/dummy/app/models/user.rb +2 -19
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/initializers/effective_orders.rb +109 -64
- data/spec/dummy/db/schema.rb +15 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +0 -258
- data/spec/models/acts_as_purchasable_spec.rb +8 -6
- data/spec/models/factories_spec.rb +7 -1
- data/spec/models/order_item_spec.rb +1 -1
- data/spec/models/order_spec.rb +165 -46
- data/spec/models/stripe_charge_spec.rb +5 -5
- data/spec/spec_helper.rb +2 -0
- data/spec/support/factories.rb +49 -33
- metadata +47 -64
- data/app/views/effective/orders/_checkout_step_1.html.haml +0 -43
- data/app/views/effective/orders/_checkout_step_2.html.haml +0 -25
- data/app/views/effective/orders/_my_purchases.html.haml +0 -17
- data/app/views/effective/orders/checkout.html.haml +0 -3
- data/app/views/effective/orders/new.html.haml +0 -4
- data/spec/dummy/log/development.log +0 -82
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# We're testing the effective/providers/ccbill.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
|
+
let(:order) { FactoryGirl.create(:order) }
|
9
|
+
|
10
|
+
let(:ccbill_params) do
|
11
|
+
{
|
12
|
+
"customer_fname"=>"Nathan",
|
13
|
+
"customer_lname"=>"Feaver",
|
14
|
+
"email"=>"nathan@agilestyle.com",
|
15
|
+
"username"=>"",
|
16
|
+
"password"=>"[FILTERED]",
|
17
|
+
"productDesc"=>"Cool Stuff",
|
18
|
+
"price"=>"#{ccbill_formatted_price(order.total)} for 365 days",
|
19
|
+
"subscription_id"=>"0216026202000000347",
|
20
|
+
"denialId"=>"",
|
21
|
+
"clientAccnum"=>"999999",
|
22
|
+
"clientSubacc"=>"0000",
|
23
|
+
"address1"=>"123 Easy St",
|
24
|
+
"city"=>"Edmonton",
|
25
|
+
"state"=>"AB",
|
26
|
+
"country"=>"CA",
|
27
|
+
"phone_number"=>"",
|
28
|
+
"zipcode"=>"A1B 2C3",
|
29
|
+
"start_date"=>"2016-01-26 13:55:44",
|
30
|
+
"referer"=>"",
|
31
|
+
"ccbill_referer"=>"",
|
32
|
+
"affiliate"=>"",
|
33
|
+
"reservationId"=>"",
|
34
|
+
"referringUrl"=>"http://localhost:3000/orders/833-7014-992",
|
35
|
+
"reasonForDecline"=>"",
|
36
|
+
"reasonForDeclineCode"=>"",
|
37
|
+
"formName"=>"211cc",
|
38
|
+
"cardType"=>"VISA",
|
39
|
+
"responseDigest"=>"43492c3db3f97944bab31a0f15d486cb",
|
40
|
+
"commit"=>"Checkout with CCBill",
|
41
|
+
"authenticity_token"=>"96wvM13VjhtNwgCyRZfO03Gn4x2ntgl7GBSn3U51OdwlGLxe2YYNdCHETtGjm8WwikQfRF79/aHF2zmldwsFCA==",
|
42
|
+
"order_id"=>order.to_param,
|
43
|
+
"utf8"=>"✓",
|
44
|
+
"typeId"=>"0",
|
45
|
+
"initialPrice"=>"10.5",
|
46
|
+
"initialPeriod"=>"365",
|
47
|
+
"recurringPrice"=>"0",
|
48
|
+
"recurringPeriod"=>"0",
|
49
|
+
"rebills"=>"0",
|
50
|
+
"initialFormattedPrice"=>ccbill_formatted_price(order.total),
|
51
|
+
"recurringFormattedPrice"=>"$0.00",
|
52
|
+
"ip_address"=>"00.00.000.00"
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:ccbill_declined_params) do
|
57
|
+
ccbill_params.merge(
|
58
|
+
"denialId"=>"",
|
59
|
+
"reasonForDecline"=>"Transaction Denied by Bank",
|
60
|
+
"reasonForDeclineCode"=>"24",
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def ccbill_formatted_price(price)
|
65
|
+
price_in_dollars = price.to_s.insert(-3, '.')
|
66
|
+
"$#{price_in_dollars}"
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'ccbill_postback' do
|
70
|
+
before do
|
71
|
+
sign_in order.user
|
72
|
+
allow_any_instance_of(Effective::Providers::CcbillPostback).to receive(:verified?).and_return(true)
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'invalid parameters' do
|
76
|
+
it 'raises RecordNotFound when passed an unknown order id' do
|
77
|
+
expect {
|
78
|
+
post :ccbill_postback, ccbill_params.tap { |x| x[:order_id] = 999 }
|
79
|
+
}.to raise_error(ActiveRecord::RecordNotFound)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'declined purchase params' do
|
84
|
+
it 'marks an order declined when params[:result] indicate decline' do
|
85
|
+
expect(subject).to receive(:order_declined).and_call_original
|
86
|
+
|
87
|
+
post :ccbill_postback, ccbill_declined_params
|
88
|
+
|
89
|
+
expect(assigns(:order)).to be_declined
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'approved purchase' do
|
94
|
+
it 'marks the order as purchased' do
|
95
|
+
expect(subject).to receive(:order_purchased).and_call_original
|
96
|
+
|
97
|
+
post :ccbill_postback, ccbill_params
|
98
|
+
|
99
|
+
expect(assigns(:order)).to be_purchased
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -8,23 +8,23 @@ describe Effective::OrdersController, type: :controller do
|
|
8
8
|
let(:order) { FactoryGirl.create(:order) }
|
9
9
|
let(:moneris_params) do
|
10
10
|
{
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
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
28
|
}
|
29
29
|
end
|
30
30
|
|
@@ -72,7 +72,7 @@ describe Effective::OrdersController, type: :controller do
|
|
72
72
|
|
73
73
|
describe 'transaction verification step' do
|
74
74
|
it 'marks the order as purchased when response code is valid' do
|
75
|
-
allow(subject).to receive(:parse_moneris_response).and_return({:
|
75
|
+
allow(subject).to receive(:parse_moneris_response).and_return({response_code: 1}) # success
|
76
76
|
|
77
77
|
post :moneris_postback, moneris_params
|
78
78
|
|
@@ -81,7 +81,7 @@ describe Effective::OrdersController, type: :controller do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'marks order declined when response_code = null' do
|
84
|
-
allow(subject).to receive(:parse_moneris_response).and_return({:
|
84
|
+
allow(subject).to receive(:parse_moneris_response).and_return({response_code: 'null'}) # failure
|
85
85
|
|
86
86
|
post :moneris_postback, moneris_params
|
87
87
|
|
@@ -101,14 +101,14 @@ describe Effective::OrdersController, type: :controller do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'marks order declined when response_code = 0' do
|
104
|
-
allow(subject).to receive(:parse_moneris_response).and_return({:
|
104
|
+
allow(subject).to receive(:parse_moneris_response).and_return({response_code: 0}) # failure
|
105
105
|
post :moneris_postback, moneris_params
|
106
106
|
response.should redirect_to "/orders/#{order.to_param}/declined"
|
107
107
|
assigns(:order).purchased?.should eq false
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'marks order declined when response_code = 50' do
|
111
|
-
allow(subject).to receive(:parse_moneris_response).and_return({:
|
111
|
+
allow(subject).to receive(:parse_moneris_response).and_return({response_code: 50}) # failure
|
112
112
|
post :moneris_postback, moneris_params
|
113
113
|
response.should redirect_to "/orders/#{order.to_param}/declined"
|
114
114
|
assigns(:order).purchased?.should eq false
|
@@ -117,13 +117,13 @@ describe Effective::OrdersController, type: :controller do
|
|
117
117
|
|
118
118
|
describe 'redirect urls' do
|
119
119
|
it 'redirects to the purchased_redirect_url on purchase' do
|
120
|
-
allow(subject).to receive(:parse_moneris_response).and_return({:
|
120
|
+
allow(subject).to receive(:parse_moneris_response).and_return({response_code: 1}) # success
|
121
121
|
post :moneris_postback, moneris_params.tap { |x| x[:rvar_purchased_redirect_url] = '/something' }
|
122
122
|
response.should redirect_to '/something'
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'redirects to the declined_redirect_url on decline' do
|
126
|
-
allow(subject).to receive(:parse_moneris_response).and_return({:
|
126
|
+
allow(subject).to receive(:parse_moneris_response).and_return({response_code: 'null'}) # failure
|
127
127
|
post :moneris_postback, moneris_params.tap { |x| x[:rvar_declined_redirect_url] = '/something' }
|
128
128
|
response.should redirect_to '/something'
|
129
129
|
end
|
@@ -17,9 +17,9 @@ describe Effective::OrdersController, type: :controller do
|
|
17
17
|
|
18
18
|
let(:valid_order_attributes) do
|
19
19
|
{
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
20
|
+
effective_order: {
|
21
|
+
billing_address: billing_atts, save_billing_address: false,
|
22
|
+
shipping_address: shipping_atts, save_shipping_address: false,
|
23
23
|
}
|
24
24
|
}
|
25
25
|
end
|
@@ -90,11 +90,11 @@ describe Effective::OrdersController, type: :controller do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'assign appropriate User fields' do
|
93
|
-
post :create, :
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
93
|
+
post :create, effective_order: {
|
94
|
+
billing_address: billing_atts, save_billing_address: false,
|
95
|
+
shipping_address: shipping_atts, save_shipping_address: false,
|
96
|
+
shipping_address_same_as_billing: false,
|
97
|
+
user_attributes: {first_name: 'First', last_name: 'Last', email: 'email@somwhere.com'}
|
98
98
|
}
|
99
99
|
|
100
100
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -105,10 +105,10 @@ describe Effective::OrdersController, type: :controller do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'assign addresses to the order and not the user' do
|
108
|
-
post :create, :
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
108
|
+
post :create, effective_order: {
|
109
|
+
billing_address: billing_atts, save_billing_address: false,
|
110
|
+
shipping_address: shipping_atts, save_shipping_address: false,
|
111
|
+
shipping_address_same_as_billing: false
|
112
112
|
}
|
113
113
|
|
114
114
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -121,10 +121,10 @@ describe Effective::OrdersController, type: :controller do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'assign addresses to the order and the user' do
|
124
|
-
post :create, :
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
124
|
+
post :create, effective_order: {
|
125
|
+
billing_address: billing_atts, save_billing_address: true,
|
126
|
+
shipping_address: shipping_atts, save_shipping_address: true,
|
127
|
+
shipping_address_same_as_billing: false
|
128
128
|
}
|
129
129
|
|
130
130
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -139,10 +139,10 @@ describe Effective::OrdersController, type: :controller do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'does not assign the billing_address to user if save_billing_address is false' do
|
142
|
-
post :create, :
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
142
|
+
post :create, effective_order: {
|
143
|
+
billing_address: billing_atts, save_billing_address: false,
|
144
|
+
shipping_address: shipping_atts, save_shipping_address: true,
|
145
|
+
shipping_address_same_as_billing: false
|
146
146
|
}
|
147
147
|
|
148
148
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -157,10 +157,10 @@ describe Effective::OrdersController, type: :controller do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'does not assign the shipping_address to user if save_shipping_address is false' do
|
160
|
-
post :create, :
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:
|
160
|
+
post :create, effective_order: {
|
161
|
+
billing_address: billing_atts, save_billing_address: true,
|
162
|
+
shipping_address: shipping_atts, save_shipping_address: false,
|
163
|
+
shipping_address_same_as_billing: false
|
164
164
|
}
|
165
165
|
|
166
166
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -175,10 +175,10 @@ describe Effective::OrdersController, type: :controller do
|
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'assign billing address to the order shipping_address when shipping_address_same_as_billing' do
|
178
|
-
post :create, :
|
179
|
-
:
|
180
|
-
:
|
181
|
-
:
|
178
|
+
post :create, effective_order: {
|
179
|
+
billing_address: billing_atts, save_billing_address: true,
|
180
|
+
shipping_address: shipping_atts, save_shipping_address: true,
|
181
|
+
shipping_address_same_as_billing: true
|
182
182
|
}
|
183
183
|
|
184
184
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -193,9 +193,9 @@ describe Effective::OrdersController, type: :controller do
|
|
193
193
|
end
|
194
194
|
|
195
195
|
it 'assign billing address to the order shipping_address when shipping_address_same_as_billing and no shipping provided' do
|
196
|
-
post :create, :
|
197
|
-
:
|
198
|
-
:
|
196
|
+
post :create, effective_order: {
|
197
|
+
billing_address: billing_atts, save_billing_address: true,
|
198
|
+
shipping_address_same_as_billing: true
|
199
199
|
}
|
200
200
|
|
201
201
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -210,10 +210,10 @@ describe Effective::OrdersController, type: :controller do
|
|
210
210
|
end
|
211
211
|
|
212
212
|
it 'assign billing address to the order shipping_address but not the user when shipping_address_same_as_billing provided' do
|
213
|
-
post :create, :
|
214
|
-
:
|
215
|
-
:
|
216
|
-
:
|
213
|
+
post :create, effective_order: {
|
214
|
+
billing_address: billing_atts, save_billing_address: false,
|
215
|
+
save_shipping_address: false,
|
216
|
+
shipping_address_same_as_billing: true
|
217
217
|
}
|
218
218
|
|
219
219
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq true
|
@@ -228,61 +228,61 @@ describe Effective::OrdersController, type: :controller do
|
|
228
228
|
end
|
229
229
|
|
230
230
|
it 'is invalid when passed an invalid address' do
|
231
|
-
post :create, :
|
232
|
-
:
|
233
|
-
:
|
234
|
-
:
|
231
|
+
post :create, effective_order: {
|
232
|
+
billing_address: billing_atts, save_billing_address: true,
|
233
|
+
shipping_address: shipping_atts.tap { |x| x[:address1] = nil }, save_shipping_address: true,
|
234
|
+
shipping_address_same_as_billing: false
|
235
235
|
}
|
236
236
|
|
237
237
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq false
|
238
238
|
assigns(:order).errors[:shipping_address].present?.should eq true
|
239
239
|
|
240
|
-
response.should render_template(:
|
240
|
+
response.should render_template(:checkout_step1)
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'is invalid when passed an invalid order_item' do
|
244
244
|
Effective::OrderItem.any_instance.stub(:valid?).and_return(false)
|
245
245
|
|
246
|
-
post :create, :
|
247
|
-
:
|
248
|
-
:
|
246
|
+
post :create, effective_order: {
|
247
|
+
billing_address: billing_atts, save_billing_address: true,
|
248
|
+
shipping_address: shipping_atts, save_shipping_address: true,
|
249
249
|
}
|
250
250
|
|
251
251
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq false
|
252
|
-
response.should render_template(:
|
252
|
+
response.should render_template(:checkout_step1)
|
253
253
|
end
|
254
254
|
|
255
255
|
it 'is invalid when passed an invalid user' do
|
256
256
|
User.any_instance.stub(:valid?).and_return(false)
|
257
257
|
|
258
|
-
post :create, :
|
259
|
-
:
|
260
|
-
:
|
258
|
+
post :create, effective_order: {
|
259
|
+
billing_address: billing_atts, save_billing_address: true,
|
260
|
+
shipping_address: shipping_atts, save_shipping_address: true,
|
261
261
|
}
|
262
262
|
|
263
263
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq false
|
264
|
-
response.should render_template(:
|
264
|
+
response.should render_template(:checkout_step1)
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'is invalid when passed an invalid purchasable' do
|
268
268
|
Product.any_instance.stub(:valid?).and_return(false)
|
269
269
|
|
270
|
-
post :create, :
|
271
|
-
:
|
272
|
-
:
|
270
|
+
post :create, effective_order: {
|
271
|
+
billing_address: billing_atts, save_billing_address: true,
|
272
|
+
shipping_address: shipping_atts, save_shipping_address: true,
|
273
273
|
}
|
274
274
|
|
275
275
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq false
|
276
|
-
response.should render_template(:
|
276
|
+
response.should render_template(:checkout_step1)
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'prevents the order from proceeding when missing a required address' do
|
280
|
-
post :create, :
|
280
|
+
post :create, effective_order: { billing_address: billing_atts, save_billing_address: true, shipping_address_same_as_billing: false }
|
281
281
|
|
282
282
|
(assigns(:order).valid? && assigns(:order).persisted?).should eq false
|
283
283
|
assigns(:order).errors[:shipping_address].present?.should eq true
|
284
284
|
|
285
|
-
response.should render_template(:
|
285
|
+
response.should render_template(:checkout_step1)
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
@@ -339,21 +339,20 @@ describe Effective::OrdersController, type: :controller do
|
|
339
339
|
describe '#order_purchased (with a free order)' do
|
340
340
|
before(:each) do
|
341
341
|
sign_in cart.user
|
342
|
-
cart.cart_items.each { |cart_item| cart_item.purchasable.update_attributes(:
|
342
|
+
cart.cart_items.each { |cart_item| cart_item.purchasable.update_attributes(price: 0.0) }
|
343
343
|
end
|
344
344
|
|
345
345
|
it 'creates a purchased order' do
|
346
346
|
post :create, valid_order_attributes
|
347
347
|
assigns(:order).purchased?.should eq true
|
348
|
-
assigns(:order).payment[:details].should eq 'automatic purchase of free order
|
348
|
+
assigns(:order).payment[:details].should eq 'automatic purchase of free order'
|
349
349
|
end
|
350
350
|
|
351
351
|
it 'destroys the current user cart' do
|
352
352
|
post :create, valid_order_attributes
|
353
353
|
|
354
354
|
expect { Effective::Cart.find(cart.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
355
|
-
|
356
|
-
expect(Effective::CartItem.where(:id => ci_ids).count).to be 0
|
355
|
+
Effective::Cart.count.should eq 0
|
357
356
|
end
|
358
357
|
|
359
358
|
it 'redirects to the purchased page' do
|
@@ -363,28 +362,81 @@ describe Effective::OrdersController, type: :controller do
|
|
363
362
|
end
|
364
363
|
|
365
364
|
describe '#show' do
|
365
|
+
context 'when finding order' do
|
366
|
+
before { sign_in purchased_order.user }
|
366
367
|
|
367
|
-
|
368
|
-
|
369
|
-
get :show, :id => purchased_order.to_param
|
370
|
-
assigns(:order).id.should eq purchased_order.id
|
371
|
-
end
|
368
|
+
it 'should find the order by obfuscated ID' do
|
369
|
+
get :show, id: purchased_order.to_param
|
372
370
|
|
373
|
-
|
374
|
-
|
375
|
-
expect { get :show, :id => purchased_order.id }.to raise_error(ActiveRecord::RecordNotFound)
|
376
|
-
end
|
371
|
+
expect(assigns(:order).id).to eq purchased_order.id
|
372
|
+
end
|
377
373
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
response.should render_template(:show)
|
374
|
+
it 'should not find an order by regular ID' do
|
375
|
+
expect { get :show, id: purchased_order.id }.to raise_error(ActiveRecord::RecordNotFound)
|
376
|
+
end
|
382
377
|
end
|
383
378
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
379
|
+
context 'when rendering template' do
|
380
|
+
let(:user) { FactoryGirl.create(:user) }
|
381
|
+
|
382
|
+
before { sign_in user }
|
383
|
+
|
384
|
+
context 'when not purchased order' do
|
385
|
+
let(:order) { FactoryGirl.create(:order, user: user) }
|
386
|
+
|
387
|
+
it 'should render checkout page successfully' do
|
388
|
+
get :show, id: order.to_param
|
389
|
+
|
390
|
+
expect(response).to be_successful
|
391
|
+
expect(response).to render_template :checkout_step2
|
392
|
+
expect(assigns(:order)).to eq order
|
393
|
+
expect(assigns(:page_title)).to eq 'Checkout'
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'should render checkout page successfully' do
|
397
|
+
get :edit, id: order.to_param
|
398
|
+
|
399
|
+
expect(response).to be_successful
|
400
|
+
expect(response).to render_template :checkout_step1
|
401
|
+
expect(assigns(:order)).to eq order
|
402
|
+
expect(assigns(:page_title)).to eq 'Checkout'
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'when pending order' do
|
407
|
+
let(:order) { FactoryGirl.create(:pending_order, user: user) }
|
408
|
+
|
409
|
+
it 'should render checkout page successfully' do
|
410
|
+
get :show, id: order.to_param
|
411
|
+
|
412
|
+
expect(response).to be_successful
|
413
|
+
expect(response).to render_template :checkout_step2
|
414
|
+
expect(assigns(:order)).to eq order
|
415
|
+
expect(assigns(:page_title)).to eq 'Checkout'
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'should render checkout page successfully' do
|
419
|
+
get :edit, id: order.to_param
|
420
|
+
|
421
|
+
expect(response).to be_successful
|
422
|
+
expect(response).to render_template :checkout_step1
|
423
|
+
expect(assigns(:order)).to eq order
|
424
|
+
expect(assigns(:page_title)).to eq 'Checkout'
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
context 'when purchased order' do
|
429
|
+
let(:order) { FactoryGirl.create(:purchased_order, user: user) }
|
430
|
+
|
431
|
+
it 'should render order show page successfully' do
|
432
|
+
get :show, id: order.to_param
|
433
|
+
|
434
|
+
expect(response).to be_successful
|
435
|
+
expect(response).to render_template :show
|
436
|
+
expect(assigns(:order)).to eq order
|
437
|
+
expect(assigns(:page_title)).to eq 'Receipt'
|
438
|
+
end
|
439
|
+
end
|
388
440
|
end
|
389
441
|
end
|
390
442
|
|
@@ -394,12 +446,12 @@ describe Effective::OrdersController, type: :controller do
|
|
394
446
|
end
|
395
447
|
|
396
448
|
it 'finds the order by obfuscated ID' do
|
397
|
-
get :purchased, :
|
449
|
+
get :purchased, id: purchased_order.to_param
|
398
450
|
assigns(:order).id.should eq purchased_order.id
|
399
451
|
end
|
400
452
|
|
401
453
|
it 'does not find an order by regular ID' do
|
402
|
-
expect { get :purchased, :
|
454
|
+
expect { get :purchased, id: purchased_order.id }.to raise_error(ActiveRecord::RecordNotFound)
|
403
455
|
end
|
404
456
|
end
|
405
457
|
|
@@ -409,13 +461,49 @@ describe Effective::OrdersController, type: :controller do
|
|
409
461
|
end
|
410
462
|
|
411
463
|
it 'finds the order by obfuscated ID' do
|
412
|
-
get :declined, :
|
464
|
+
get :declined, id: purchased_order.to_param
|
413
465
|
assigns(:order).id.should eq purchased_order.id
|
414
466
|
end
|
415
467
|
|
416
468
|
it 'does not find an order by regular ID' do
|
417
|
-
expect { get :declined, :
|
469
|
+
expect { get :declined, id: purchased_order.id }.to raise_error(ActiveRecord::RecordNotFound)
|
418
470
|
end
|
419
471
|
end
|
420
472
|
|
473
|
+
describe 'POST #pay_by_cheque' do
|
474
|
+
let(:user) { FactoryGirl.create(:user) }
|
475
|
+
let(:order) { FactoryGirl.create(:order, user: user) }
|
476
|
+
let!(:cart) { FactoryGirl.create(:cart_with_items, user: user) }
|
477
|
+
|
478
|
+
before { sign_in user }
|
479
|
+
|
480
|
+
context 'when success' do
|
481
|
+
it 'should update order state, empty cart and redirect to order show page with success message' do
|
482
|
+
Effective::OrdersMailer.deliveries.clear
|
483
|
+
|
484
|
+
post :pay_by_cheque, id: order.to_param
|
485
|
+
|
486
|
+
expect(assigns(:order).pending?).to be_truthy
|
487
|
+
expect(Effective::Cart.first).to be_nil
|
488
|
+
flash[:success].present?.should eq true
|
489
|
+
response.should render_template(:pay_by_cheque)
|
490
|
+
Effective::OrdersMailer.deliveries.length.should eq 1
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
context 'when failed' do
|
495
|
+
before { Effective::Order.any_instance.stub(:save).and_return(false) }
|
496
|
+
|
497
|
+
it 'should not empty cart and redirect to order show page with danger message' do
|
498
|
+
Effective::OrdersMailer.deliveries.clear
|
499
|
+
post :pay_by_cheque, id: order.to_param
|
500
|
+
|
501
|
+
expect(response).to be_redirect
|
502
|
+
expect(response).to redirect_to EffectiveOrders::Engine.routes.url_helpers.order_path(order)
|
503
|
+
expect(Effective::Cart.first.empty?).to be_falsey
|
504
|
+
flash[:danger].present?.should eq true
|
505
|
+
Effective::OrdersMailer.deliveries.length.should eq 0
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
421
509
|
end
|