effective_orders 1.6.5 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/effective/carts_controller.rb +7 -7
- data/app/controllers/effective/orders_controller.rb +10 -6
- data/app/controllers/effective/subscriptions_controller.rb +2 -2
- data/app/helpers/effective_orders_helper.rb +19 -0
- data/app/mailers/effective/orders_mailer.rb +3 -2
- data/app/models/effective/cart.rb +3 -3
- data/app/views/admin/customers/index.html.haml +10 -5
- data/app/views/admin/order_items/index.html.haml +3 -2
- data/app/views/admin/orders/index.html.haml +3 -2
- data/app/views/effective/carts/_cart.html.haml +14 -10
- data/app/views/effective/orders/_checkout_step_1.html.haml +1 -1
- data/app/views/effective/orders/_checkout_step_2.html.haml +2 -2
- data/app/views/effective/orders/_order_items.html.haml +1 -1
- data/app/views/effective/orders/moneris/_form.html.haml +1 -1
- data/app/views/effective/orders/paypal/_form.html.haml +1 -1
- data/app/views/effective/orders/pretend/_form.html.haml +1 -1
- data/app/views/effective/orders/stripe/_form.html.haml +1 -1
- data/app/views/effective/orders_mailer/order_receipt_to_seller.html.haml +3 -3
- data/app/views/effective/subscriptions/new.html.haml +0 -1
- data/lib/effective_orders.rb +4 -0
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/effective_orders/install_generator.rb +10 -0
- data/lib/generators/templates/effective_orders_mailer_preview.rb +61 -0
- data/spec/controllers/moneris_orders_controller_spec.rb +8 -8
- data/spec/controllers/orders_controller_spec.rb +4 -1
- data/spec/controllers/stripe_orders_controller_spec.rb +2 -2
- data/spec/controllers/webhooks_controller_spec.rb +7 -7
- data/spec/dummy/config/initializers/effective_orders.rb +1 -1
- data/spec/dummy/config/initializers/simple_form.rb +189 -0
- data/spec/dummy/log/test.log +23 -0
- data/spec/helpers/effective_orders_helper_spec.rb +2 -2
- data/spec/models/order_spec.rb +12 -12
- data/spec/spec_helper.rb +0 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 454888d9685c161b640cb1704d16ed37089a843b
|
4
|
+
data.tar.gz: e21c978af3d83dd4104a0b56929dc000f3daf8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2bab5bcdf09101c8bd475e27c0db23e2cba18b52b4b8bc8247d20361eb5d8c5c0ae597a4eefeb1d5d1bda7d6143e55068914cedf42a967267e3bbcc0532f7c1
|
7
|
+
data.tar.gz: c8bf6d21f7f4e312c21a9693b246f8c81f5a525ab40c9d130c3398c3ac219141fb696e3b35366d77aacbe6acb794ce026e43f44de6a613d3dd33bb6585f78f8e
|
@@ -16,9 +16,9 @@ module Effective
|
|
16
16
|
EffectiveOrders.authorized?(self, :destroy, @cart)
|
17
17
|
|
18
18
|
if @cart.destroy
|
19
|
-
flash[:success] = 'Successfully emptied cart'
|
19
|
+
flash[:success] = 'Successfully emptied cart.'
|
20
20
|
else
|
21
|
-
flash[:danger] = 'Unable to destroy cart'
|
21
|
+
flash[:danger] = 'Unable to destroy cart.'
|
22
22
|
end
|
23
23
|
|
24
24
|
request.referrer ? (redirect_to :back) : (redirect_to effective_orders.cart_path)
|
@@ -30,12 +30,12 @@ module Effective
|
|
30
30
|
EffectiveOrders.authorized?(self, :update, current_cart)
|
31
31
|
|
32
32
|
begin
|
33
|
-
raise "
|
33
|
+
raise "Please select a valid #{add_to_cart_params[:purchasable_type] || 'item' }." unless @purchasable
|
34
34
|
|
35
35
|
current_cart.add_to_cart(@purchasable, [add_to_cart_params[:quantity].to_i, 1].max)
|
36
|
-
flash[:success] = 'Successfully added item to cart'
|
36
|
+
flash[:success] = 'Successfully added item to cart.'
|
37
37
|
rescue EffectiveOrders::SoldOutException
|
38
|
-
flash[:warning] = 'This item is sold out'
|
38
|
+
flash[:warning] = 'This item is sold out.'
|
39
39
|
rescue => e
|
40
40
|
flash[:danger] = 'Unable to add item to cart: ' + e.message
|
41
41
|
end
|
@@ -49,9 +49,9 @@ module Effective
|
|
49
49
|
EffectiveOrders.authorized?(self, :update, current_cart)
|
50
50
|
|
51
51
|
if @cart_item.destroy
|
52
|
-
flash[:success] = 'Successfully removed item from cart'
|
52
|
+
flash[:success] = 'Successfully removed item from cart.'
|
53
53
|
else
|
54
|
-
flash[:danger] = 'Unable to remove item from cart'
|
54
|
+
flash[:danger] = 'Unable to remove item from cart.'
|
55
55
|
end
|
56
56
|
|
57
57
|
request.referrer ? (redirect_to :back) : (redirect_to effective_orders.cart_path)
|
@@ -56,7 +56,7 @@ module Effective
|
|
56
56
|
@order.save!
|
57
57
|
|
58
58
|
if @order.total == 0 && EffectiveOrders.allow_free_orders
|
59
|
-
order_purchased('
|
59
|
+
order_purchased('automatic purchase of free order.')
|
60
60
|
else
|
61
61
|
redirect_to(effective_orders.order_path(@order))
|
62
62
|
end
|
@@ -64,7 +64,7 @@ module Effective
|
|
64
64
|
return
|
65
65
|
rescue => e
|
66
66
|
Rails.logger.info e.message
|
67
|
-
flash.now[:danger] = "An error has
|
67
|
+
flash.now[:danger] = "An error has occurred: #{e.message}. Please try again."
|
68
68
|
raise ActiveRecord::Rollback
|
69
69
|
end
|
70
70
|
end
|
@@ -118,7 +118,7 @@ module Effective
|
|
118
118
|
if @order.send_order_receipt_to_buyer!
|
119
119
|
flash[:success] = "Successfully resent order receipt to #{@order.user.email}"
|
120
120
|
else
|
121
|
-
flash[:danger] = "Unable to send order receipt"
|
121
|
+
flash[:danger] = "Unable to send order receipt."
|
122
122
|
end
|
123
123
|
|
124
124
|
redirect_to(:back) rescue effective_orders.order_path(@order)
|
@@ -145,11 +145,15 @@ module Effective
|
|
145
145
|
@order.purchase!(details)
|
146
146
|
current_cart.try(:destroy)
|
147
147
|
|
148
|
-
|
148
|
+
if EffectiveOrders.mailer[:send_order_receipt_to_buyer]
|
149
|
+
flash[:success] = "Payment successful! Please check your email for a receipt."
|
150
|
+
else
|
151
|
+
flash[:success] = "Payment successful!"
|
152
|
+
end
|
149
153
|
|
150
154
|
redirect_to (redirect_url.presence || effective_orders.order_purchased_path(':id')).gsub(':id', @order.to_param.to_s)
|
151
155
|
rescue => e
|
152
|
-
flash[:danger] = "
|
156
|
+
flash[:danger] = "An error occurred while processing your payment: #{e.message}. Please try again."
|
153
157
|
redirect_to (declined_redirect_url.presence || effective_orders.cart_path).gsub(':id', @order.to_param.to_s)
|
154
158
|
end
|
155
159
|
end
|
@@ -157,7 +161,7 @@ module Effective
|
|
157
161
|
def order_declined(details = nil, redirect_url = nil)
|
158
162
|
@order.decline!(details) rescue nil
|
159
163
|
|
160
|
-
flash[:danger] = "
|
164
|
+
flash[:danger] = "Payment was unsuccessful. Your credit card was declined by the payment processor. Please try again."
|
161
165
|
|
162
166
|
redirect_to (redirect_url.presence || effective_orders.order_declined_path(@order)).gsub(':id', @order.id.to_s)
|
163
167
|
end
|
@@ -40,7 +40,7 @@ module Effective
|
|
40
40
|
EffectiveOrders.authorized?(self, :create, @subscription)
|
41
41
|
|
42
42
|
if @subscription.update_attributes(subscription_params) && (current_cart.find(@subscription).present? || current_cart.add(@subscription))
|
43
|
-
flash[:success] = "Successfully added subscription to cart"
|
43
|
+
flash[:success] = "Successfully added subscription to cart."
|
44
44
|
redirect_to effective_orders.new_order_path
|
45
45
|
else
|
46
46
|
purchased_plans = @customer.subscriptions.purchased.map(&:stripe_plan_id)
|
@@ -75,7 +75,7 @@ module Effective
|
|
75
75
|
|
76
76
|
EffectiveOrders.authorized?(self, :show, @subscription)
|
77
77
|
|
78
|
-
@invoices = @customer.stripe_customer.invoices.all.select do |invoice|
|
78
|
+
@invoices = @customer.stripe_customer.invoices.all.select do |invoice|
|
79
79
|
invoice.lines.any? { |line| line.id == @stripe_subscription.id }
|
80
80
|
end
|
81
81
|
|
@@ -27,6 +27,25 @@ module EffectiveOrdersHelper
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def order_checkout_label(processor = nil)
|
31
|
+
return 'Checkout' if (EffectiveOrders.single_payment_processor? && processor != :pretend)
|
32
|
+
|
33
|
+
case processor
|
34
|
+
when :free
|
35
|
+
'Checkout'
|
36
|
+
when :moneris
|
37
|
+
'Checkout with Moneris'
|
38
|
+
when :paypal
|
39
|
+
'Checkout with PayPal'
|
40
|
+
when :pretend # The logic for this is in orders/views/_checkout_step_2.html.haml
|
41
|
+
EffectiveOrders.allow_pretend_purchase_in_production ? 'Purchase Order' : 'Purchase Order (development only)'
|
42
|
+
when :stripe
|
43
|
+
'Checkout with Stripe'
|
44
|
+
else
|
45
|
+
'Checkout'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
30
49
|
# This is called on the My Sales Page and is intended to be overridden in the app if needed
|
31
50
|
def acts_as_purchasable_path(purchasable, action = :show)
|
32
51
|
polymorphic_path(purchasable)
|
@@ -18,8 +18,9 @@ module Effective
|
|
18
18
|
@order = order
|
19
19
|
@user = seller.user
|
20
20
|
@order_items = order_items
|
21
|
+
@subject = receipt_to_seller_subject(order, order_items, seller.user)
|
21
22
|
|
22
|
-
mail(:to => @user.email, :subject =>
|
23
|
+
mail(:to => @user.email, :subject => @subject)
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
@@ -51,7 +52,7 @@ module Effective
|
|
51
52
|
string_or_callable = self.instance_exec(order, order_items, seller, &string_or_callable)
|
52
53
|
end
|
53
54
|
|
54
|
-
prefix_subject(string_or_callable.presence || "#{order_items.
|
55
|
+
prefix_subject(string_or_callable.presence || "#{order_items.length} of your products #{order_items.length > 1 ? 'have' : 'has'} been purchased")
|
55
56
|
end
|
56
57
|
|
57
58
|
def prefix_subject(text)
|
@@ -51,15 +51,15 @@ module Effective
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def subtotal
|
54
|
-
cart_items.map
|
54
|
+
cart_items.map { |ci| ci.subtotal }.sum
|
55
55
|
end
|
56
56
|
|
57
57
|
def tax
|
58
|
-
cart_items.map
|
58
|
+
cart_items.map { |ci| ci.tax }.sum
|
59
59
|
end
|
60
60
|
|
61
61
|
def total
|
62
|
-
cart_items.map
|
62
|
+
cart_items.map { |ci| ci.total }.sum
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -2,9 +2,14 @@
|
|
2
2
|
|
3
3
|
%p.text-right= link_to 'Stripe Dashboard: Customers', 'https://manage.stripe.com/customers', :class => 'btn btn-primary'
|
4
4
|
|
5
|
-
|
6
|
-
%p
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
- if @datatable.nil?
|
6
|
+
%p
|
7
|
+
Please install
|
8
|
+
= link_to 'effective_datatables', 'https://github.com/code-and-effect/effective_datatables'
|
9
|
+
to see this page.
|
10
|
+
- elsif @datatable.present?
|
11
|
+
= render_datatable @datatable
|
12
|
+
- else
|
13
|
+
%p There are no customers present
|
10
14
|
|
15
|
+
%p.text-right= link_to 'Stripe Dashboard: Customers', 'https://manage.stripe.com/customers', :class => 'btn btn-primary'
|
@@ -5,6 +5,7 @@
|
|
5
5
|
Please install
|
6
6
|
= link_to 'effective_datatables', 'https://github.com/code-and-effect/effective_datatables'
|
7
7
|
to see this page.
|
8
|
+
- elsif @datatable.present?
|
9
|
+
= render_datatable @datatable
|
8
10
|
- else
|
9
|
-
|
10
|
-
%p There are no order items
|
11
|
+
%p There are no order items present
|
@@ -5,6 +5,7 @@
|
|
5
5
|
Please install
|
6
6
|
= link_to 'effective_datatables', 'https://github.com/code-and-effect/effective_datatables'
|
7
7
|
to see this page.
|
8
|
+
- elsif @datatable.present?
|
9
|
+
= render_datatable @datatable
|
8
10
|
- else
|
9
|
-
|
10
|
-
%p There are no orders
|
11
|
+
%p There are no orders present
|
@@ -2,7 +2,7 @@
|
|
2
2
|
%table.table
|
3
3
|
%thead
|
4
4
|
%tr
|
5
|
-
%th.quantity
|
5
|
+
%th.quantity Qty
|
6
6
|
%th.item Item
|
7
7
|
%th.price Price
|
8
8
|
%tbody
|
@@ -15,19 +15,23 @@
|
|
15
15
|
= ' - '
|
16
16
|
= link_to_remove_from_cart(item)
|
17
17
|
%td.price
|
18
|
-
= price_to_currency(item.
|
18
|
+
= price_to_currency(item.price)
|
19
19
|
- if cart.empty?
|
20
20
|
%tr
|
21
21
|
%td.quantity
|
22
22
|
%td.item There are no items in your shopping cart
|
23
23
|
%td.price
|
24
24
|
%tfoot
|
25
|
+
- if cart.tax > 0
|
26
|
+
%tr
|
27
|
+
%th.quantity
|
28
|
+
%th.subtotal Subtotal
|
29
|
+
%td.price.subtotal-price= price_to_currency(cart.subtotal)
|
30
|
+
%tr
|
31
|
+
%th.quantity
|
32
|
+
%th.tax Tax
|
33
|
+
%td.price.tax-price= price_to_currency(cart.tax)
|
25
34
|
%tr
|
26
|
-
%th
|
27
|
-
%
|
28
|
-
|
29
|
-
%th{:colspan => 2} Tax
|
30
|
-
%td.price= price_to_currency(cart.tax)
|
31
|
-
%tr
|
32
|
-
%th{:colspan => 2} Total Due
|
33
|
-
%td.price= price_to_currency(cart.total)
|
35
|
+
%th.quantity
|
36
|
+
%th.total Total Due
|
37
|
+
%td.price.total-price= price_to_currency(cart.total)
|
@@ -38,6 +38,6 @@
|
|
38
38
|
|
39
39
|
.text-right
|
40
40
|
- if order.total == 0 && EffectiveOrders.allow_free_orders
|
41
|
-
= f.submit
|
41
|
+
= f.submit order_checkout_label(:free), :class => 'btn btn-primary pull-right', :rel => :nofollow, :data => {'disable_with' => 'Processing...' }
|
42
42
|
- else
|
43
43
|
= f.submit 'Save and Continue', :class => 'btn btn-primary pull-right', :rel => :nofollow, :data => {'disable_with' => 'Saving...' }
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
.effective-order.effective-order-purchase-actions
|
4
4
|
- if (Rails.env.production? == false && EffectiveOrders.allow_pretend_purchase_in_development)
|
5
|
-
= render :partial => '/effective/orders/pretend/form', locals: {
|
5
|
+
= render :partial => '/effective/orders/pretend/form', locals: {order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
|
6
6
|
|
7
7
|
- if (Rails.env.production? == true && EffectiveOrders.allow_pretend_purchase_in_production)
|
8
|
-
= render :partial => '/effective/orders/pretend/form', locals: {
|
8
|
+
= render :partial => '/effective/orders/pretend/form', locals: {order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
|
9
9
|
|
10
10
|
- if EffectiveOrders.moneris_enabled
|
11
11
|
= render :partial => '/effective/orders/moneris/form', locals: {order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
|
@@ -44,4 +44,4 @@
|
|
44
44
|
= hidden_field_tag(:ship_postal_code, address.postal_code)
|
45
45
|
= hidden_field_tag(:ship_country, address.country)
|
46
46
|
|
47
|
-
= submit_tag
|
47
|
+
= submit_tag order_checkout_label(:moneris), :class => 'btn btn-primary', :data => {'disable_with' => 'Continuing...' }
|
@@ -2,4 +2,4 @@
|
|
2
2
|
= hidden_field_tag :cmd, '_s-xclick'
|
3
3
|
= hidden_field_tag :encrypted, paypal_encrypted_payload(order)
|
4
4
|
|
5
|
-
= submit_tag
|
5
|
+
= submit_tag order_checkout_label(:paypal), :class => 'btn btn-primary', :data => {'disable_with' => 'Continuing...' }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
= form_tag(effective_orders.pretend_purchase_path(order, :purchased_redirect_url => purchased_redirect_url, :declined_redirect_url => declined_redirect_url), method: :post) do
|
2
|
-
= submit_tag
|
2
|
+
= submit_tag order_checkout_label(:pretend), :class => 'btn btn-primary', :data => {'disable_with' => 'Continuing...' }
|
@@ -4,4 +4,4 @@
|
|
4
4
|
= simple_form_for(@stripe_charge || Effective::StripeCharge.new(order), (EffectiveOrders.simple_form_options || {}).merge(:url => effective_orders.stripe_charges_path)) do |f|
|
5
5
|
= f.input :effective_order_id, :as => :hidden
|
6
6
|
= f.input :token, :as => :hidden
|
7
|
-
= f.submit
|
7
|
+
= f.submit order_checkout_label(:stripe), :class => 'stripe-button', :data => {'disable_with' => 'Continuing...' }
|
@@ -21,10 +21,10 @@
|
|
21
21
|
%tfoot
|
22
22
|
%tr
|
23
23
|
%th Subtotal
|
24
|
-
%td= price_to_currency(@order_items.sum
|
24
|
+
%td= price_to_currency(@order_items.map { |oi| oi.subtotal }.sum)
|
25
25
|
%tr
|
26
26
|
%th Tax
|
27
|
-
%td= price_to_currency(@order_items.sum
|
27
|
+
%td= price_to_currency(@order_items.map { |oi| oi.tax }.sum)
|
28
28
|
%tr
|
29
29
|
%th Total
|
30
|
-
%td= price_to_currency(@order_items.sum
|
30
|
+
%td= price_to_currency(@order_items.map { |oi| oi.total }.sum)
|
data/lib/effective_orders.rb
CHANGED
@@ -96,6 +96,10 @@ module EffectiveOrders
|
|
96
96
|
use_active_admin && defined?(ActiveAdmin)
|
97
97
|
end
|
98
98
|
|
99
|
+
def self.single_payment_processor?
|
100
|
+
[moneris_enabled, paypal_enabled, stripe_enabled].select { |enabled| enabled }.length == 1
|
101
|
+
end
|
102
|
+
|
99
103
|
class SoldOutException < Exception; end
|
100
104
|
class AlreadyPurchasedException < Exception; end
|
101
105
|
class AlreadyDeclinedException < Exception; end
|
@@ -19,6 +19,16 @@ module EffectiveOrders
|
|
19
19
|
template "effective_orders.rb", "config/initializers/effective_orders.rb"
|
20
20
|
end
|
21
21
|
|
22
|
+
def copy_mailer_preview
|
23
|
+
mailer_preview_path = (Rails.application.config.action_mailer.preview_path rescue nil)
|
24
|
+
|
25
|
+
if mailer_preview_path.present?
|
26
|
+
template 'effective_orders_mailer_preview.rb', File.join(mailer_preview_path, 'effective_orders_mailer_preview.rb')
|
27
|
+
else
|
28
|
+
puts "couldn't find action_mailer.preview_path. Skipping effective_orders_mailer_preview."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
22
32
|
def create_migration_file
|
23
33
|
@orders_table_name = ':' + EffectiveOrders.orders_table_name.to_s
|
24
34
|
@order_items_table_name = ':' + EffectiveOrders.order_items_table_name.to_s
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# In Rails 4.1 and above, visit:
|
2
|
+
# http://localhost:3000/rails/mailers
|
3
|
+
# to see a preview of the following 3 emails:
|
4
|
+
|
5
|
+
class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
6
|
+
def order_receipt_to_buyer
|
7
|
+
Effective::OrdersMailer.order_receipt_to_buyer(build_preview_order)
|
8
|
+
end
|
9
|
+
|
10
|
+
def order_receipt_to_admin
|
11
|
+
Effective::OrdersMailer.order_receipt_to_admin(build_preview_order)
|
12
|
+
end
|
13
|
+
|
14
|
+
# This email is only sent to sellers having sold items via StripeConnect
|
15
|
+
def order_receipt_to_seller
|
16
|
+
order = build_preview_order
|
17
|
+
Effective::OrdersMailer.order_receipt_to_seller(order, preview_customer, order.order_items)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def build_preview_order
|
23
|
+
order = Effective::Order.new()
|
24
|
+
order.user = preview_user
|
25
|
+
preview_order_items.each { |atts| order.order_items.build(atts) }
|
26
|
+
order
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# We're building Effective::OrderItems directly rather than creating acts_as_purchasable objects
|
32
|
+
# so that this mailer will not have to guess at your app's acts_as_purchasable objects
|
33
|
+
def preview_order_items
|
34
|
+
tax_rate = (EffectiveOrders.tax_rate_method.call(Object.new()) rescue -1)
|
35
|
+
tax_rate = 0.05 if tax_rate < 0.0
|
36
|
+
|
37
|
+
[
|
38
|
+
{title: 'Item One', quantity: 2, price: 999, tax_exempt: false, tax_rate: tax_rate},
|
39
|
+
{title: 'Item Two', quantity: 1, price: 25000, tax_exempt: false, tax_rate: tax_rate},
|
40
|
+
{title: 'Item Three', quantity: 1, price: 8999, tax_exempt: false, tax_rate: tax_rate},
|
41
|
+
{title: 'Item Four', quantity: 1, price: 100000, tax_exempt: false, tax_rate: tax_rate}
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
def preview_user
|
46
|
+
User.new(email: 'buyer@example.com').tap do |user|
|
47
|
+
user.name = 'Valued Customer' if user.respond_to?(:name=)
|
48
|
+
user.full_name = 'Valued Customer' if user.respond_to?(:full_name=)
|
49
|
+
|
50
|
+
if user.respond_to?(:first_name=) && user.respond_to?(:last_name=)
|
51
|
+
user.first_name = 'Valued'
|
52
|
+
user.last_name = 'Customer'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def preview_customer
|
58
|
+
Effective::Customer.new(user: preview_user)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -30,7 +30,7 @@ describe Effective::OrdersController, type: :controller do
|
|
30
30
|
|
31
31
|
describe 'moneris_postback' do
|
32
32
|
before do
|
33
|
-
subject.
|
33
|
+
allow(subject).to receive(:send_moneris_verify_request).and_return('') # Don't actually make Moneris requests
|
34
34
|
sign_in order.user
|
35
35
|
end
|
36
36
|
|
@@ -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
|
-
subject.
|
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
|
-
subject.
|
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
|
|
@@ -91,7 +91,7 @@ describe Effective::OrdersController, type: :controller do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'marks order declined when response_code blank' do
|
94
|
-
subject.
|
94
|
+
allow(subject).to receive(:parse_moneris_response).and_return({}) # failure
|
95
95
|
|
96
96
|
post :moneris_postback, moneris_params
|
97
97
|
|
@@ -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
|
-
subject.
|
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
|
-
subject.
|
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
|
-
subject.
|
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
|
-
subject.
|
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
|
@@ -52,7 +52,10 @@ describe Effective::OrdersController, type: :controller do
|
|
52
52
|
|
53
53
|
it 'redirects if order total is less than minimum charge' do
|
54
54
|
sign_in cart.user
|
55
|
-
|
55
|
+
|
56
|
+
cart.cart_items.each do |cart_item|
|
57
|
+
cart_item.purchasable.update_column(:price, 10)
|
58
|
+
end
|
56
59
|
|
57
60
|
get :new
|
58
61
|
|
@@ -29,7 +29,7 @@ describe Effective::OrdersController, type: :controller do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'renders the :create action on validation failure' do
|
32
|
-
subject.
|
32
|
+
expect(subject).not_to receive(:process_stripe_charge)
|
33
33
|
|
34
34
|
post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_stripe_charge]['token'] = nil }
|
35
35
|
|
@@ -58,7 +58,7 @@ describe Effective::OrdersController, type: :controller do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'calls process_stripe_charge when the stripe_charge form object is valid' do
|
61
|
-
subject.
|
61
|
+
expect(subject).to receive(:process_stripe_charge)
|
62
62
|
post :stripe_charge, stripe_charge_params
|
63
63
|
end
|
64
64
|
|
@@ -15,7 +15,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
15
15
|
let(:event) { StripeMock.mock_webhook_event('customer.subscription.created') }
|
16
16
|
|
17
17
|
it 'retrieves the real event from Stripe based on passed ID' do
|
18
|
-
Stripe::Event.
|
18
|
+
expect(Stripe::Event).to receive(:retrieve) { event_hash[:id] }
|
19
19
|
post :stripe, event_hash
|
20
20
|
response.code.should eq '200'
|
21
21
|
end
|
@@ -96,7 +96,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'should invoke subscription_deleted_callback' do
|
99
|
-
controller.
|
99
|
+
expect(controller).to receive(:subscription_deleted_callback)
|
100
100
|
post :stripe, event_hash
|
101
101
|
end
|
102
102
|
end
|
@@ -107,7 +107,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should not invoke subscription_deleted_callback' do
|
110
|
-
controller.
|
110
|
+
expect(controller).not_to receive(:subscription_deleted_callback)
|
111
111
|
post :stripe, event_hash
|
112
112
|
end
|
113
113
|
end
|
@@ -124,7 +124,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
124
124
|
let(:subscription_mock) { double('subscription', status: 'active', start: 1383672652) }
|
125
125
|
let(:subscriptions) { double('subscriptions', retrieve: subscription_mock) }
|
126
126
|
|
127
|
-
before { Stripe::Customer.
|
127
|
+
before { allow(Stripe::Customer).to receive(:retrieve).and_return(double('customer', subscriptions: subscriptions)) }
|
128
128
|
|
129
129
|
it 'assigns the existing customer, if exists' do
|
130
130
|
post :stripe, event_hash
|
@@ -144,7 +144,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
144
144
|
before { Stripe::Customer.should_receive(:retrieve).and_return(double('customer', subscriptions: subscriptions)) }
|
145
145
|
|
146
146
|
it 'should not invoke subscription_renewed_callback' do
|
147
|
-
controller.
|
147
|
+
expect(controller).not_to receive(:subscription_renewed_callback)
|
148
148
|
post :stripe, event_hash
|
149
149
|
end
|
150
150
|
end
|
@@ -154,7 +154,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
154
154
|
let(:event) { StripeMock.mock_webhook_event('invoice.payment_succeeded.without_renewals') }
|
155
155
|
|
156
156
|
it 'should not invoke subscription_renewed_callback' do
|
157
|
-
controller.
|
157
|
+
expect(controller).not_to receive(:subscription_renewed_callback)
|
158
158
|
post :stripe, event_hash
|
159
159
|
end
|
160
160
|
end
|
@@ -162,7 +162,7 @@ describe Effective::WebhooksController, type: :controller do
|
|
162
162
|
|
163
163
|
context 'when customer does not exist' do
|
164
164
|
it 'should not invoke subscription_renewed_callback' do
|
165
|
-
controller.
|
165
|
+
expect(controller).not_to receive(:subscription_renewed_callback)
|
166
166
|
post :stripe, event_hash
|
167
167
|
end
|
168
168
|
end
|
@@ -37,7 +37,7 @@ EffectiveOrders.setup do |config|
|
|
37
37
|
config.obfuscate_order_ids = true
|
38
38
|
|
39
39
|
# Silence the price deprecation warnings
|
40
|
-
config.silence_deprecation_warnings =
|
40
|
+
config.silence_deprecation_warnings = true
|
41
41
|
|
42
42
|
# Require these addresses when creating a new Order. Works with effective_addresses gem
|
43
43
|
config.require_billing_address = true
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# Use this setup block to configure all options available in SimpleForm.
|
2
|
+
SimpleForm.setup do |config|
|
3
|
+
config.error_notification_class = 'alert alert-danger'
|
4
|
+
config.button_class = 'btn btn-primary'
|
5
|
+
config.boolean_label_class = nil
|
6
|
+
|
7
|
+
config.boolean_style = :nested
|
8
|
+
config.browser_validations = true
|
9
|
+
|
10
|
+
config.default_form_class = ''
|
11
|
+
config.default_wrapper = :vertical_form
|
12
|
+
|
13
|
+
config.wrapper_mappings = {
|
14
|
+
:boolean => :vertical_boolean,
|
15
|
+
:check_boxes => :vertical_radio_and_checkboxes,
|
16
|
+
:radio_buttons => :vertical_radio_and_checkboxes,
|
17
|
+
|
18
|
+
:horizontal_form => {
|
19
|
+
:boolean => :horizontal_boolean,
|
20
|
+
:check_boxes => :horizontal_radio_and_checkboxes,
|
21
|
+
:radio_buttons => :horizontal_radio_and_checkboxes
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
27
|
+
b.use :html5
|
28
|
+
b.use :placeholder
|
29
|
+
b.optional :maxlength
|
30
|
+
b.optional :pattern
|
31
|
+
b.optional :min_max
|
32
|
+
b.optional :readonly
|
33
|
+
b.use :label, class: 'control-label'
|
34
|
+
|
35
|
+
b.use :input, class: 'form-control'
|
36
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
37
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
38
|
+
end
|
39
|
+
|
40
|
+
config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
41
|
+
b.use :html5
|
42
|
+
b.use :placeholder
|
43
|
+
b.optional :maxlength
|
44
|
+
b.optional :readonly
|
45
|
+
b.use :label, class: 'control-label'
|
46
|
+
|
47
|
+
b.use :input
|
48
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
49
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
50
|
+
end
|
51
|
+
|
52
|
+
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
53
|
+
b.use :html5
|
54
|
+
b.optional :readonly
|
55
|
+
|
56
|
+
b.wrapper tag: 'div', class: 'checkbox' do |ba|
|
57
|
+
ba.use :label_input
|
58
|
+
end
|
59
|
+
|
60
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
61
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
62
|
+
end
|
63
|
+
|
64
|
+
config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
65
|
+
b.use :html5
|
66
|
+
b.optional :readonly
|
67
|
+
b.use :label_input, :class => 'control-label'
|
68
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
69
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
70
|
+
end
|
71
|
+
|
72
|
+
config.wrappers :vertical_inline_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
73
|
+
b.use :html5
|
74
|
+
b.optional :readonly
|
75
|
+
|
76
|
+
b.use :label, class: 'control-label'
|
77
|
+
|
78
|
+
b.wrapper tag: 'div', class: 'inline-radio-or-checkboxes' do |ba|
|
79
|
+
ba.use :input
|
80
|
+
end
|
81
|
+
|
82
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
83
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
84
|
+
end
|
85
|
+
|
86
|
+
config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
87
|
+
b.use :html5
|
88
|
+
b.use :placeholder
|
89
|
+
b.optional :maxlength
|
90
|
+
b.optional :pattern
|
91
|
+
b.optional :min_max
|
92
|
+
b.optional :readonly
|
93
|
+
b.use :label, class: 'col-sm-3 control-label'
|
94
|
+
|
95
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
96
|
+
ba.use :input, class: 'form-control'
|
97
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
98
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
config.wrappers :form_3columns, tag: 'div', class: 'col-sm-4' do |b|
|
103
|
+
b.use :html5
|
104
|
+
b.use :placeholder
|
105
|
+
b.optional :maxlength
|
106
|
+
b.optional :pattern
|
107
|
+
b.optional :min_max
|
108
|
+
b.optional :readonly
|
109
|
+
|
110
|
+
b.wrapper tag: 'div', class: 'form-group', error_class: 'has-error' do |ba|
|
111
|
+
ba.use :label
|
112
|
+
ba.use :input, class: 'form-control'
|
113
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
114
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
119
|
+
b.use :html5
|
120
|
+
b.use :placeholder
|
121
|
+
b.optional :maxlength
|
122
|
+
b.optional :readonly
|
123
|
+
b.use :label, class: 'col-sm-3 control-label'
|
124
|
+
|
125
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
126
|
+
ba.use :input
|
127
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
128
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
133
|
+
b.use :html5
|
134
|
+
b.optional :readonly
|
135
|
+
|
136
|
+
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
|
137
|
+
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
|
138
|
+
ba.use :label_input, class: 'col-sm-9'
|
139
|
+
end
|
140
|
+
|
141
|
+
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
142
|
+
wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
147
|
+
b.use :html5
|
148
|
+
b.optional :readonly
|
149
|
+
|
150
|
+
b.use :label, class: 'col-sm-3 control-label'
|
151
|
+
|
152
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
153
|
+
ba.use :input
|
154
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
155
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
config.wrappers :horizontal_inline_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
160
|
+
b.use :html5
|
161
|
+
b.optional :readonly
|
162
|
+
|
163
|
+
b.use :label, class: 'col-sm-3 control-label'
|
164
|
+
|
165
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
166
|
+
ba.wrapper tag: 'div', :class => 'inline-radio-or-checkboxes' do |bb|
|
167
|
+
bb.use :input
|
168
|
+
end
|
169
|
+
|
170
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
171
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
176
|
+
b.use :html5
|
177
|
+
b.use :placeholder
|
178
|
+
b.optional :maxlength
|
179
|
+
b.optional :pattern
|
180
|
+
b.optional :min_max
|
181
|
+
b.optional :readonly
|
182
|
+
b.use :label, class: 'sr-only'
|
183
|
+
|
184
|
+
b.use :input, class: 'form-control'
|
185
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
186
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
data/spec/dummy/log/test.log
CHANGED
@@ -182,3 +182,26 @@
|
|
182
182
|
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
183
183
|
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
184
184
|
[1m[36m (0.3ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
185
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
186
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
187
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
188
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
189
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
190
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
191
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
192
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
193
|
+
[1m[36m (0.3ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
194
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
195
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
196
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
197
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
198
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
199
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
200
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
201
|
+
[1m[36m (0.3ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
202
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
203
|
+
[1m[36m (0.3ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
204
|
+
[1m[36m (0.3ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
205
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
206
|
+
[1m[36m (0.3ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
207
|
+
[1m[36m (0.4ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
@@ -11,11 +11,11 @@ describe EffectiveOrdersHelper, :type => :helper do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'raises an error when passed a decimal' do
|
14
|
-
expect { price_to_currency(10.00) }.to raise_exception
|
14
|
+
expect { price_to_currency(10.00) }.to raise_exception(Exception)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'raises an error when passed nil' do
|
18
|
-
expect { price_to_currency(nil) }.to raise_exception
|
18
|
+
expect { price_to_currency(nil) }.to raise_exception(Exception)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/spec/models/order_spec.rb
CHANGED
@@ -58,21 +58,21 @@ describe Effective::Order do
|
|
58
58
|
|
59
59
|
describe 'minimum zero math' do
|
60
60
|
it 'has a minimum order total of 0' do
|
61
|
-
order.order_items.each { |order_item| order_item.
|
61
|
+
order.order_items.each { |order_item| allow(order_item).to receive(:total).and_return(-1000) }
|
62
62
|
|
63
63
|
order.order_items.collect(&:total).sum.should eq -3000
|
64
64
|
order.total.should eq 0
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'has no minimum subtotal' do
|
68
|
-
order.order_items.each { |order_item| order_item.
|
68
|
+
order.order_items.each { |order_item| allow(order_item).to receive(:subtotal).and_return(-1000) }
|
69
69
|
|
70
70
|
order.order_items.collect(&:subtotal).sum.should eq -3000
|
71
71
|
order.subtotal.should eq -3000
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'has a minimum order tax of 0.00' do
|
75
|
-
order.order_items.each { |order_item| order_item.
|
75
|
+
order.order_items.each { |order_item| allow(order_item).to receive(:tax).and_return(-1000) }
|
76
76
|
|
77
77
|
order.order_items.collect(&:tax).sum.should eq -3000
|
78
78
|
order.tax.should eq 0
|
@@ -112,21 +112,21 @@ describe Effective::Order do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should be invalid when user is invalid' do
|
115
|
-
order.user.
|
115
|
+
allow(order.user).to receive(:valid?).and_return(false)
|
116
116
|
order.valid?.should eq false
|
117
117
|
|
118
118
|
order.errors[:user].present?.should eq true
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'should be invalid when an order_item is invalid' do
|
122
|
-
order.order_items.first.
|
122
|
+
allow(order.order_items.first).to receive(:valid?).and_return(false)
|
123
123
|
order.valid?.should eq false
|
124
124
|
|
125
125
|
order.errors[:order_items].present?.should eq true
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'should be invalid when less than the minimum charge' do
|
129
|
-
order.
|
129
|
+
allow(order).to receive(:total).and_return(49)
|
130
130
|
|
131
131
|
order.valid?.should eq false
|
132
132
|
|
@@ -135,15 +135,15 @@ describe Effective::Order do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'should be valid when >= minimum charge' do
|
138
|
-
order.
|
138
|
+
allow(order).to receive(:total).and_return(50)
|
139
139
|
order.valid?.should eq true
|
140
140
|
|
141
|
-
order.
|
141
|
+
allow(order).to receive(:total).and_return(51)
|
142
142
|
order.valid?.should eq true
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'should be valid for a free order' do
|
146
|
-
order.order_items.each { |order_item| order_item.
|
146
|
+
order.order_items.each { |order_item| allow(order_item).to receive(:total).and_return(0) }
|
147
147
|
|
148
148
|
order.valid?.should eq true
|
149
149
|
order.errors[:total].present?.should eq false
|
@@ -203,12 +203,12 @@ describe Effective::Order do
|
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'should return false when the Order is invalid' do
|
206
|
-
order.
|
207
|
-
expect { order.purchase!('by a test') }.to raise_exception
|
206
|
+
allow(order).to receive(:valid?).and_return(false)
|
207
|
+
expect { order.purchase!('by a test') }.to raise_exception(Exception)
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should return true when the Order is invalid and :validate => false is passed' do
|
211
|
-
order.
|
211
|
+
allow(order).to receive(:valid?).and_return(false)
|
212
212
|
order.purchase!('by a test', :validate => false).should eq true
|
213
213
|
end
|
214
214
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -392,6 +392,7 @@ files:
|
|
392
392
|
- lib/generators/effective_orders/upgrade_price_column_generator.rb
|
393
393
|
- lib/generators/templates/README
|
394
394
|
- lib/generators/templates/effective_orders.rb
|
395
|
+
- lib/generators/templates/effective_orders_mailer_preview.rb
|
395
396
|
- spec/controllers/carts_controller_spec.rb
|
396
397
|
- spec/controllers/moneris_orders_controller_spec.rb
|
397
398
|
- spec/controllers/orders_controller_spec.rb
|
@@ -427,6 +428,7 @@ files:
|
|
427
428
|
- spec/dummy/config/initializers/inflections.rb
|
428
429
|
- spec/dummy/config/initializers/mime_types.rb
|
429
430
|
- spec/dummy/config/initializers/session_store.rb
|
431
|
+
- spec/dummy/config/initializers/simple_form.rb
|
430
432
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
431
433
|
- spec/dummy/config/locales/en.yml
|
432
434
|
- spec/dummy/config/routes.rb
|
@@ -469,7 +471,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
469
471
|
version: '0'
|
470
472
|
requirements: []
|
471
473
|
rubyforge_project:
|
472
|
-
rubygems_version: 2.
|
474
|
+
rubygems_version: 2.5.0
|
473
475
|
signing_key:
|
474
476
|
specification_version: 4
|
475
477
|
summary: Quickly build an online store with carts, orders, automatic email receipts
|
@@ -507,6 +509,7 @@ test_files:
|
|
507
509
|
- spec/dummy/config/initializers/inflections.rb
|
508
510
|
- spec/dummy/config/initializers/mime_types.rb
|
509
511
|
- spec/dummy/config/initializers/session_store.rb
|
512
|
+
- spec/dummy/config/initializers/simple_form.rb
|
510
513
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
511
514
|
- spec/dummy/config/locales/en.yml
|
512
515
|
- spec/dummy/config/routes.rb
|