active_cart 0.0.7 → 0.0.8
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.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/active_cart/cart.rb +22 -23
- data/lib/active_cart/cart_storage.rb +61 -30
- data/test/unit/cart_storage_test.rb +108 -2
- data/test/unit/cart_test.rb +80 -34
- metadata +2 -2
data/.gitignore
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.8
|
data/lib/active_cart/cart.rb
CHANGED
|
@@ -78,9 +78,16 @@ module ActiveCart
|
|
|
78
78
|
# @cart[0].size # => 7
|
|
79
79
|
# @cart[1].size # => 4
|
|
80
80
|
#
|
|
81
|
+
# Callbacks:
|
|
82
|
+
#
|
|
83
|
+
# Calls the storage engines before_add_to_cart(item, quantity) and after_add_to_cart(item, quantity) methods (if they exist). If before_add_to_cart returns false, the add will be halted.
|
|
84
|
+
# Calls the items before_add_to_item(quantity) and after_add_to_cart(quantity) methods (if they exist). If before_add_to_cart returns false, the add will be halted.
|
|
85
|
+
#
|
|
81
86
|
def add_to_cart(item, quantity = 1)
|
|
82
87
|
return false unless item.before_add_to_cart(quantity) if item.respond_to?(:before_add_to_cart)
|
|
88
|
+
return false unless @storage_engine.before_add_to_cart(item, quantity) if @storage_engine.respond_to?(:before_add_to_cart)
|
|
83
89
|
@storage_engine.add_to_cart(item, quantity)
|
|
90
|
+
@storage_engine.after_add_to_cart(item, quantity) if @storage_engine.respond_to?(:after_add_to_cart)
|
|
84
91
|
item.after_add_to_cart(quantity) if item.respond_to?(:after_add_to_cart)
|
|
85
92
|
end
|
|
86
93
|
|
|
@@ -93,9 +100,16 @@ module ActiveCart
|
|
|
93
100
|
# @cart.remove_from_cart(item, 2)
|
|
94
101
|
# @cart[0] # => nil
|
|
95
102
|
#
|
|
103
|
+
# Callbacks:
|
|
104
|
+
#
|
|
105
|
+
# Calls the storage engines before_remove_from_cart(item, quantity) and after_remove_from_cart(item, quantity) methods (if they exist). If before_remove_from_cart returns false, the remove will be halted.
|
|
106
|
+
# Calls the items before_remove_from_item(quantity) and after_remove_from_cart(quantity) methods (if they exist). If before_remove_from_cart returns false, the remove will be halted.
|
|
107
|
+
#
|
|
96
108
|
def remove_from_cart(item, quantity = 1)
|
|
97
109
|
return false unless item.before_remove_from_cart(quantity) if item.respond_to?(:before_remove_from_cart)
|
|
110
|
+
return false unless @storage_engine.before_remove_from_cart(item, quantity) if @storage_engine.respond_to?(:before_remove_from_cart)
|
|
98
111
|
@storage_engine.remove_from_cart(item, quantity)
|
|
112
|
+
@storage_engine.after_remove_from_cart(item, quantity) if @storage_engine.respond_to?(:after_remove_from_cart)
|
|
99
113
|
item.after_remove_from_cart(quantity) if item.respond_to?(:after_remove_from_cart)
|
|
100
114
|
end
|
|
101
115
|
|
|
@@ -111,29 +125,14 @@ module ActiveCart
|
|
|
111
125
|
storage_engine.state
|
|
112
126
|
end
|
|
113
127
|
|
|
114
|
-
#
|
|
115
|
-
def
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Transitions to the cart's :verifying_payment state
|
|
125
|
-
def check_payment!
|
|
126
|
-
storage_engine.check_payment!
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# Transitions to the cart's :successful state
|
|
130
|
-
def payment_successful!
|
|
131
|
-
storage_engine.payment_successful!
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Transitions to the cart's :failed state
|
|
135
|
-
def payment_failed!
|
|
136
|
-
storage_engine.payment_failed!
|
|
128
|
+
# :nodoc
|
|
129
|
+
def method_missing(symbol, *args)
|
|
130
|
+
# This allows developers to add extra aasm event transaction, and still allow them to called from the cart
|
|
131
|
+
if @storage_engine.class.aasm_events.keys.include?(symbol.to_s[0..-2].to_sym)
|
|
132
|
+
@storage_engine.send(symbol)
|
|
133
|
+
else
|
|
134
|
+
super
|
|
135
|
+
end
|
|
137
136
|
end
|
|
138
137
|
end
|
|
139
138
|
end
|
|
@@ -15,73 +15,104 @@ module ActiveCart
|
|
|
15
15
|
module CartStorage
|
|
16
16
|
def self.included(base) #:nodoc:
|
|
17
17
|
base.send :include, AASM
|
|
18
|
+
|
|
18
19
|
base.aasm_initial_state :shopping
|
|
19
|
-
base.aasm_state :shopping
|
|
20
|
-
base.aasm_state :checkout
|
|
21
|
-
base.aasm_state :verifying_payment
|
|
22
|
-
base.aasm_state :completed
|
|
23
|
-
base.aasm_state :failed
|
|
20
|
+
base.aasm_state :shopping, :enter => :enter_shopping, :exit => :exit_shopping
|
|
21
|
+
base.aasm_state :checkout, :enter => :enter_checkout, :exit => :exit_checkout
|
|
22
|
+
base.aasm_state :verifying_payment, :enter => :enter_verifying_payment, :exit => :exit_verifying_payment
|
|
23
|
+
base.aasm_state :completed, :enter => :enter_completed, :ext => :exit_completed
|
|
24
|
+
base.aasm_state :failed, :enter => :enter_failed, :exit => :exit_failed
|
|
24
25
|
|
|
25
26
|
base.aasm_event :continue_shopping do
|
|
26
|
-
transitions :from => [ :checkout, :verifying_payment ], :to => :shopping, :
|
|
27
|
+
transitions :from => [ :checkout, :verifying_payment ], :to => :shopping, :guard => :guard_continue_shopping
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
base.aasm_event :checkout do
|
|
30
|
-
transitions :from => [ :shopping, :verifying_payment ], :to => :checkout, :
|
|
31
|
+
transitions :from => [ :shopping, :verifying_payment ], :to => :checkout, :guard => :guard_checkout
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
base.aasm_event :check_payment do
|
|
34
|
-
transitions :from => :checkout, :to => :verifying_payment, :
|
|
35
|
+
transitions :from => :checkout, :to => :verifying_payment, :guard => :guard_check_payment
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
base.aasm_event :payment_successful do
|
|
38
|
-
transitions :from => :verifying_payment, :to => :completed, :
|
|
39
|
+
transitions :from => :verifying_payment, :to => :completed, :guard => :guard_payment_successful
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
base.aasm_event :payment_failed do
|
|
42
|
-
transitions :from => :verifying_payment, :to => :failed, :
|
|
43
|
+
transitions :from => :verifying_payment, :to => :failed, :guard => :guard_payment_failed
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
#
|
|
47
|
+
# Guard continue shopping. If this method returns false, the transition will be halted
|
|
48
|
+
#
|
|
49
|
+
def guard_continue_shopping
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Guard checkout. If this method returns false, the transition will be halted
|
|
54
|
+
#
|
|
55
|
+
def guard_checkout
|
|
56
|
+
true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Guard check payment. If this method returns false, the transition will be halted
|
|
60
|
+
#
|
|
61
|
+
def guard_check_payment
|
|
62
|
+
true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Guard payment successful. If this method returns false, the transition will be halted
|
|
66
|
+
#
|
|
67
|
+
def guard_payment_successful
|
|
68
|
+
true
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Guard payment failed. If this method returns false, the transition will be halted
|
|
72
|
+
#
|
|
73
|
+
def guard_payment_failed
|
|
74
|
+
true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Called when entering the shopping state
|
|
47
78
|
#
|
|
48
|
-
def
|
|
79
|
+
def enter_shopping; end
|
|
49
80
|
|
|
50
|
-
# Called
|
|
81
|
+
# Called when exiting the shopping state
|
|
51
82
|
#
|
|
52
|
-
def
|
|
83
|
+
def exit_shopping; end
|
|
53
84
|
|
|
54
|
-
# Called
|
|
85
|
+
# Called when entering the checkout state
|
|
55
86
|
#
|
|
56
|
-
def
|
|
87
|
+
def enter_checkout; end
|
|
57
88
|
|
|
58
|
-
# Called
|
|
89
|
+
# Called when existing the checkout state
|
|
59
90
|
#
|
|
60
|
-
def
|
|
91
|
+
def exit_checkout; end
|
|
61
92
|
|
|
62
|
-
# Called
|
|
93
|
+
# Called when entering the verifying_payment state
|
|
63
94
|
#
|
|
64
|
-
def
|
|
95
|
+
def enter_verifying_payment; end
|
|
65
96
|
|
|
66
|
-
# Called
|
|
97
|
+
# Called when exiting the verifying_payment state
|
|
67
98
|
#
|
|
68
|
-
def
|
|
99
|
+
def exit_verifying_payment; end
|
|
69
100
|
|
|
70
|
-
# Called
|
|
101
|
+
# Called when entering the completed state
|
|
71
102
|
#
|
|
72
|
-
def
|
|
103
|
+
def enter_completed; end
|
|
73
104
|
|
|
74
|
-
# Called
|
|
105
|
+
# Called when existing the completed state
|
|
75
106
|
#
|
|
76
|
-
def
|
|
107
|
+
def exit_completed; end
|
|
77
108
|
|
|
78
|
-
# Called
|
|
109
|
+
# Called when entering the failed state
|
|
79
110
|
#
|
|
80
|
-
def
|
|
111
|
+
def enter_failed; end
|
|
81
112
|
|
|
82
|
-
# Called
|
|
113
|
+
# Called when existing the failed state
|
|
83
114
|
#
|
|
84
|
-
def
|
|
115
|
+
def exit_failed; end
|
|
85
116
|
|
|
86
117
|
# Returns the unique invoice_id for this cart instance. This MUST be overriden by the concrete class this module is mixed into, otherwise you
|
|
87
118
|
# will get a NotImplementedError
|
|
@@ -14,13 +14,33 @@ class CartStorageTest < ActiveSupport::TestCase
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
should 'transition from shopping to checkout' do
|
|
17
|
+
@cart_storage_engine.expects(:exit_shopping)
|
|
18
|
+
@cart_storage_engine.expects(:enter_checkout)
|
|
19
|
+
@cart_storage_engine.expects(:guard_checkout).returns(true)
|
|
20
|
+
|
|
17
21
|
assert_nothing_raised do
|
|
18
22
|
@cart_storage_engine.checkout!
|
|
19
23
|
end
|
|
20
24
|
assert_equal :checkout, @cart_storage_engine.state
|
|
21
25
|
end
|
|
22
26
|
|
|
27
|
+
should 'not transition from shopping to checkout if guard_checkout is false' do
|
|
28
|
+
@cart_storage_engine.expects(:guard_checkout).returns(false)
|
|
29
|
+
@cart_storage_engine.expects(:exit_shopping)
|
|
30
|
+
@cart_storage_engine.expects(:enter_shopping)
|
|
31
|
+
@cart_storage_engine.expects(:enter_checkout).never
|
|
32
|
+
|
|
33
|
+
assert_nothing_raised do
|
|
34
|
+
@cart_storage_engine.checkout!
|
|
35
|
+
end
|
|
36
|
+
assert_equal :shopping, @cart_storage_engine.state
|
|
37
|
+
end
|
|
38
|
+
|
|
23
39
|
should 'transition from checkout to check_payment' do
|
|
40
|
+
@cart_storage_engine.expects(:enter_verifying_payment)
|
|
41
|
+
@cart_storage_engine.expects(:exit_checkout)
|
|
42
|
+
@cart_storage_engine.expects(:guard_check_payment).returns(true)
|
|
43
|
+
|
|
24
44
|
@cart_storage_engine.checkout!
|
|
25
45
|
assert_nothing_raised do
|
|
26
46
|
@cart_storage_engine.check_payment!
|
|
@@ -28,7 +48,24 @@ class CartStorageTest < ActiveSupport::TestCase
|
|
|
28
48
|
assert_equal :verifying_payment, @cart_storage_engine.state
|
|
29
49
|
end
|
|
30
50
|
|
|
51
|
+
should 'not transition from checkout to check_payment if guard_check_payment is false' do
|
|
52
|
+
@cart_storage_engine.expects(:enter_verifying_payment).never
|
|
53
|
+
@cart_storage_engine.expects(:exit_checkout)
|
|
54
|
+
@cart_storage_engine.expects(:enter_checkout)
|
|
55
|
+
@cart_storage_engine.expects(:guard_check_payment).returns(false)
|
|
56
|
+
|
|
57
|
+
@cart_storage_engine.checkout!
|
|
58
|
+
assert_nothing_raised do
|
|
59
|
+
@cart_storage_engine.check_payment!
|
|
60
|
+
end
|
|
61
|
+
assert_equal :checkout, @cart_storage_engine.state
|
|
62
|
+
end
|
|
63
|
+
|
|
31
64
|
should 'transition from verifying_payment to completed' do
|
|
65
|
+
@cart_storage_engine.expects(:enter_completed)
|
|
66
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
67
|
+
@cart_storage_engine.expects(:guard_payment_successful).returns(true)
|
|
68
|
+
|
|
32
69
|
@cart_storage_engine.checkout!
|
|
33
70
|
@cart_storage_engine.check_payment!
|
|
34
71
|
assert_nothing_raised do
|
|
@@ -37,7 +74,25 @@ class CartStorageTest < ActiveSupport::TestCase
|
|
|
37
74
|
assert_equal :completed, @cart_storage_engine.state
|
|
38
75
|
end
|
|
39
76
|
|
|
77
|
+
should 'not transition from verifying_payment to completed if guard payment_successful is false' do
|
|
78
|
+
@cart_storage_engine.expects(:enter_completed).never
|
|
79
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
80
|
+
@cart_storage_engine.expects(:enter_verifying_payment)
|
|
81
|
+
@cart_storage_engine.expects(:guard_payment_successful).returns(false)
|
|
82
|
+
|
|
83
|
+
@cart_storage_engine.checkout!
|
|
84
|
+
@cart_storage_engine.check_payment!
|
|
85
|
+
assert_nothing_raised do
|
|
86
|
+
@cart_storage_engine.payment_successful!
|
|
87
|
+
end
|
|
88
|
+
assert_equal :verifying_payment, @cart_storage_engine.state
|
|
89
|
+
end
|
|
90
|
+
|
|
40
91
|
should 'transition from verifying_payment to shopping' do
|
|
92
|
+
@cart_storage_engine.expects(:enter_shopping).twice
|
|
93
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
94
|
+
@cart_storage_engine.expects(:guard_continue_shopping).returns(true)
|
|
95
|
+
|
|
41
96
|
@cart_storage_engine.checkout!
|
|
42
97
|
@cart_storage_engine.check_payment!
|
|
43
98
|
assert_nothing_raised do
|
|
@@ -46,16 +101,52 @@ class CartStorageTest < ActiveSupport::TestCase
|
|
|
46
101
|
assert_equal :shopping, @cart_storage_engine.state
|
|
47
102
|
end
|
|
48
103
|
|
|
104
|
+
should 'not transition from verifying_payment to shopping if guard_continue_shopping is false' do
|
|
105
|
+
@cart_storage_engine.expects(:enter_shopping).once
|
|
106
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
107
|
+
@cart_storage_engine.expects(:enter_verifying_payment)
|
|
108
|
+
@cart_storage_engine.expects(:guard_continue_shopping).returns(false)
|
|
109
|
+
|
|
110
|
+
@cart_storage_engine.checkout!
|
|
111
|
+
@cart_storage_engine.check_payment!
|
|
112
|
+
assert_nothing_raised do
|
|
113
|
+
@cart_storage_engine.continue_shopping!
|
|
114
|
+
end
|
|
115
|
+
assert_equal :verifying_payment, @cart_storage_engine.state
|
|
116
|
+
end
|
|
117
|
+
|
|
49
118
|
should 'transition from verifying_payment to checkout' do
|
|
119
|
+
@cart_storage_engine.expects(:enter_completed)
|
|
120
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
121
|
+
@cart_storage_engine.expects(:guard_payment_successful).returns(true)
|
|
122
|
+
|
|
50
123
|
@cart_storage_engine.checkout!
|
|
51
124
|
@cart_storage_engine.check_payment!
|
|
52
125
|
assert_nothing_raised do
|
|
53
|
-
@cart_storage_engine.
|
|
126
|
+
@cart_storage_engine.payment_successful!
|
|
54
127
|
end
|
|
55
|
-
assert_equal :
|
|
128
|
+
assert_equal :completed, @cart_storage_engine.state
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
should 'not transition from verifying_payment to checkout if guard_payment_successful is false' do
|
|
132
|
+
@cart_storage_engine.expects(:enter_completed).never
|
|
133
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
134
|
+
@cart_storage_engine.expects(:enter_verifying_payment)
|
|
135
|
+
@cart_storage_engine.expects(:guard_payment_successful).returns(false)
|
|
136
|
+
|
|
137
|
+
@cart_storage_engine.checkout!
|
|
138
|
+
@cart_storage_engine.check_payment!
|
|
139
|
+
assert_nothing_raised do
|
|
140
|
+
@cart_storage_engine.payment_successful!
|
|
141
|
+
end
|
|
142
|
+
assert_equal :verifying_payment, @cart_storage_engine.state
|
|
56
143
|
end
|
|
57
144
|
|
|
58
145
|
should 'transition from verifying_payment to failed' do
|
|
146
|
+
@cart_storage_engine.expects(:enter_failed)
|
|
147
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
148
|
+
@cart_storage_engine.expects(:guard_payment_failed).returns(true)
|
|
149
|
+
|
|
59
150
|
@cart_storage_engine.checkout!
|
|
60
151
|
@cart_storage_engine.check_payment!
|
|
61
152
|
assert_nothing_raised do
|
|
@@ -63,6 +154,21 @@ class CartStorageTest < ActiveSupport::TestCase
|
|
|
63
154
|
end
|
|
64
155
|
assert_equal :failed, @cart_storage_engine.state
|
|
65
156
|
end
|
|
157
|
+
|
|
158
|
+
should 'not transition from verifying_payment to failed if guard_payment_failed if false' do
|
|
159
|
+
@cart_storage_engine.expects(:enter_failed).never
|
|
160
|
+
@cart_storage_engine.expects(:exit_verifying_payment)
|
|
161
|
+
@cart_storage_engine.expects(:enter_verifying_payment)
|
|
162
|
+
@cart_storage_engine.expects(:guard_payment_failed).returns(false)
|
|
163
|
+
|
|
164
|
+
@cart_storage_engine.checkout!
|
|
165
|
+
@cart_storage_engine.check_payment!
|
|
166
|
+
assert_nothing_raised do
|
|
167
|
+
@cart_storage_engine.payment_failed!
|
|
168
|
+
end
|
|
169
|
+
assert_equal :verifying_payment, @cart_storage_engine.state
|
|
170
|
+
end
|
|
171
|
+
|
|
66
172
|
end
|
|
67
173
|
end
|
|
68
174
|
|
data/test/unit/cart_test.rb
CHANGED
|
@@ -9,46 +9,92 @@ class CartTest < ActiveSupport::TestCase
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
context 'callbacks' do
|
|
12
|
-
|
|
13
|
-
item
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
context 'items' do
|
|
13
|
+
should 'fire the item before_add_to_cart callback on add to cart' do
|
|
14
|
+
item = TestItem.new
|
|
15
|
+
item.expects(:before_add_to_cart).with(1).returns(true)
|
|
16
|
+
@cart.add_to_cart(item, 1)
|
|
17
|
+
assert_equal 1, @cart.quantity
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
should 'halt and return false if beforee_add_to_cart returnds false' do
|
|
21
|
+
item = TestItem.new
|
|
22
|
+
item.expects(:before_add_to_cart).with(1).returns(false)
|
|
23
|
+
assert !@cart.add_to_cart(item, 1)
|
|
24
|
+
assert_equal 0, @cart.quantity
|
|
25
|
+
end
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
should 'fire the item after_add_to_cart callback' do
|
|
28
|
+
item = TestItem.new
|
|
29
|
+
item.expects(:after_add_to_cart).with(1)
|
|
30
|
+
@cart.add_to_cart(item, 1)
|
|
31
|
+
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
should 'fire the item before_remove_from_cart callback on add to cart' do
|
|
34
|
+
item = TestItem.new
|
|
35
|
+
item.expects(:before_remove_from_cart).with(1).returns(true)
|
|
36
|
+
@cart.remove_from_cart(item, 1)
|
|
37
|
+
assert_equal 0, @cart.quantity
|
|
38
|
+
end
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
should 'halt and return false if beforee_add_to_cart returns false' do
|
|
41
|
+
item = TestItem.new
|
|
42
|
+
@cart.add_to_cart(item, 1)
|
|
43
|
+
assert_equal 1, @cart.quantity
|
|
44
|
+
item.expects(:before_remove_from_cart).with(1).returns(false)
|
|
45
|
+
assert !@cart.remove_from_cart(item, 1)
|
|
46
|
+
assert_equal 1, @cart.quantity
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should 'fire the item after_remove_from_cart callback' do
|
|
50
|
+
item = TestItem.new
|
|
51
|
+
item.expects(:after_remove_from_cart).with(1)
|
|
52
|
+
@cart.remove_from_cart(item, 1)
|
|
53
|
+
end
|
|
46
54
|
end
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
context 'storage engines' do
|
|
57
|
+
should 'fire the storage engines before_add_to_cart callback on add to cart' do
|
|
58
|
+
item = TestItem.new
|
|
59
|
+
@cart_storage_engine.expects(:before_add_to_cart).with(item, 1).returns(true)
|
|
60
|
+
@cart.add_to_cart(item, 1)
|
|
61
|
+
assert_equal 1, @cart.quantity
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
should 'halt and return false if before_add_to_cart returns false' do
|
|
65
|
+
item = TestItem.new
|
|
66
|
+
@cart_storage_engine.expects(:before_add_to_cart).with(item, 1).returns(false)
|
|
67
|
+
assert !@cart.add_to_cart(item, 1)
|
|
68
|
+
assert_equal 0, @cart.quantity
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
should 'fire the storage engines after_add_to_cart callback' do
|
|
72
|
+
item = TestItem.new
|
|
73
|
+
@cart_storage_engine.expects(:after_add_to_cart).with(item, 1)
|
|
74
|
+
@cart.add_to_cart(item, 1)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
should 'fire the storage engines before_remove_from_cart callback on add to cart' do
|
|
78
|
+
item = TestItem.new
|
|
79
|
+
@cart_storage_engine.expects(:before_remove_from_cart).with(item, 1).returns(true)
|
|
80
|
+
@cart.remove_from_cart(item, 1)
|
|
81
|
+
assert_equal 0, @cart.quantity
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
should 'halt and return false if beforee_add_to_cart returns false' do
|
|
85
|
+
item = TestItem.new
|
|
86
|
+
@cart.add_to_cart(item, 1)
|
|
87
|
+
assert_equal 1, @cart.quantity
|
|
88
|
+
@cart_storage_engine.expects(:before_remove_from_cart).with(item, 1).returns(false)
|
|
89
|
+
assert !@cart.remove_from_cart(item, 1)
|
|
90
|
+
assert_equal 1, @cart.quantity
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
should 'fire the storage engines after_remove_from_cart callback' do
|
|
94
|
+
item = TestItem.new
|
|
95
|
+
@cart_storage_engine.expects(:after_remove_from_cart).with(item, 1)
|
|
96
|
+
@cart.remove_from_cart(item, 1)
|
|
97
|
+
end
|
|
52
98
|
end
|
|
53
99
|
end
|
|
54
100
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_cart
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Myles Eftos
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2010-03-
|
|
12
|
+
date: 2010-03-13 00:00:00 +08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|