active_cart 0.0.12 → 0.0.13
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/VERSION +1 -1
- data/lib/active_cart/cart.rb +2 -2
- data/test/unit/cart_test.rb +6 -6
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/lib/active_cart/cart.rb
CHANGED
@@ -178,11 +178,11 @@ module ActiveCart
|
|
178
178
|
private
|
179
179
|
def with_callbacks(type, item, quantity, options, &blk)
|
180
180
|
return false unless item.send("before_#{type}".to_sym, quantity, options) if item.respond_to?("before_#{type}".to_sym)
|
181
|
-
return false unless @storage_engine.send("before_#{type}".to_sym, quantity, options) if @storage_engine.respond_to?("before_#{type}".to_sym)
|
181
|
+
return false unless @storage_engine.send("before_#{type}".to_sym, item, quantity, options) if @storage_engine.respond_to?("before_#{type}".to_sym)
|
182
182
|
|
183
183
|
yield
|
184
184
|
|
185
|
-
@storage_engine.send("after_#{type}".to_sym, quantity, options) if @storage_engine.respond_to?("after_#{type}".to_sym)
|
185
|
+
@storage_engine.send("after_#{type}".to_sym, item, quantity, options) if @storage_engine.respond_to?("after_#{type}".to_sym)
|
186
186
|
item.send("after_#{type}".to_sym, quantity, options) if item.respond_to?("after_#{type}".to_sym)
|
187
187
|
end
|
188
188
|
end
|
data/test/unit/cart_test.rb
CHANGED
@@ -138,27 +138,27 @@ class CartTest < ActiveSupport::TestCase
|
|
138
138
|
context 'storage engines' do
|
139
139
|
should 'fire the storage engines before_add_to_cart callback on add to cart' do
|
140
140
|
item = TestItem.new
|
141
|
-
@cart_storage_engine.expects(:before_add_to_cart).with(1, { :option => 'value' }).returns(true)
|
141
|
+
@cart_storage_engine.expects(:before_add_to_cart).with(item, 1, { :option => 'value' }).returns(true)
|
142
142
|
@cart.add_to_cart(item, 1, { :option => 'value' })
|
143
143
|
assert_equal 1, @cart.quantity
|
144
144
|
end
|
145
145
|
|
146
146
|
should 'halt and return false if before_add_to_cart returns false' do
|
147
147
|
item = TestItem.new
|
148
|
-
@cart_storage_engine.expects(:before_add_to_cart).with(1, { :option => 'value' }).returns(false)
|
148
|
+
@cart_storage_engine.expects(:before_add_to_cart).with(item, 1, { :option => 'value' }).returns(false)
|
149
149
|
assert !@cart.add_to_cart(item, 1, { :option => 'value' })
|
150
150
|
assert_equal 0, @cart.quantity
|
151
151
|
end
|
152
152
|
|
153
153
|
should 'fire the storage engines after_add_to_cart callback' do
|
154
154
|
item = TestItem.new
|
155
|
-
@cart_storage_engine.expects(:after_add_to_cart).with(1, {})
|
155
|
+
@cart_storage_engine.expects(:after_add_to_cart).with(item, 1, {})
|
156
156
|
@cart.add_to_cart(item, 1)
|
157
157
|
end
|
158
158
|
|
159
159
|
should 'fire the storage engines before_remove_from_cart callback on add to cart' do
|
160
160
|
item = TestItem.new
|
161
|
-
@cart_storage_engine.expects(:before_remove_from_cart).with(1, {}).returns(true)
|
161
|
+
@cart_storage_engine.expects(:before_remove_from_cart).with(item, 1, {}).returns(true)
|
162
162
|
@cart.remove_from_cart(item, 1)
|
163
163
|
assert_equal 0, @cart.quantity
|
164
164
|
end
|
@@ -167,14 +167,14 @@ class CartTest < ActiveSupport::TestCase
|
|
167
167
|
item = TestItem.new
|
168
168
|
@cart.add_to_cart(item, 1)
|
169
169
|
assert_equal 1, @cart.quantity
|
170
|
-
@cart_storage_engine.expects(:before_remove_from_cart).with(1, { :option => 'value' }).returns(false)
|
170
|
+
@cart_storage_engine.expects(:before_remove_from_cart).with(item, 1, { :option => 'value' }).returns(false)
|
171
171
|
assert !@cart.remove_from_cart(item, 1, { :option => 'value' })
|
172
172
|
assert_equal 1, @cart.quantity
|
173
173
|
end
|
174
174
|
|
175
175
|
should 'fire the storage engines after_remove_from_cart callback' do
|
176
176
|
item = TestItem.new
|
177
|
-
@cart_storage_engine.expects(:after_remove_from_cart).with(1, { :option => 'value' })
|
177
|
+
@cart_storage_engine.expects(:after_remove_from_cart).with(item, 1, { :option => 'value' })
|
178
178
|
@cart.remove_from_cart(item, 1, { :option => 'value' })
|
179
179
|
end
|
180
180
|
end
|