active_cart 0.0.17 → 0.0.18
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/acts_as_cart.rb +6 -7
- data/test/fixtures/cart_item.rb +2 -0
- data/test/fixtures/item.rb +1 -0
- data/test/unit/acts_as_cart_test.rb +8 -8
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.18
|
@@ -74,7 +74,7 @@ module ActiveCart
|
|
74
74
|
cart_item.quantity += quantity
|
75
75
|
cart_item.save!
|
76
76
|
else
|
77
|
-
cart_item = self.send(:cart_items).create!(self.aac_config[:cart_items].to_s.classify.constantize.new_from_item(item, { :quantity => quantity }.merge(options)).attributes.
|
77
|
+
cart_item = self.send(:cart_items).create!(self.aac_config[:cart_items].to_s.classify.constantize.new_from_item(item, { :quantity => quantity }.merge(options)).attributes.delete_if {|key, value| value == nil})
|
78
78
|
end
|
79
79
|
self.reload
|
80
80
|
end
|
@@ -114,8 +114,8 @@ module ActiveCart
|
|
114
114
|
|
115
115
|
aasm_column self.aac_config[:state_column]
|
116
116
|
|
117
|
-
has_many self.aac_config[:cart_items]
|
118
|
-
has_many self.aac_config[:order_totals]
|
117
|
+
has_many self.aac_config[:cart_items], :dependent => :destroy
|
118
|
+
has_many self.aac_config[:order_totals], :dependent => :destroy
|
119
119
|
|
120
120
|
extend Forwardable
|
121
121
|
def_delegators self.aac_config[:cart_items], :[], :<<, :[]=, :at, :clear, :collect, :map, :delete, :delete_at, :each, :each_index, :empty?, :eql?, :first, :include?, :index, :inject, :last, :length, :pop, :push, :shift, :size, :unshift
|
@@ -198,12 +198,11 @@ module ActiveCart
|
|
198
198
|
|
199
199
|
# Creates a new cart_item item for the passed in concrete item
|
200
200
|
#
|
201
|
-
# The default copies all the common attributes from the passed in item to new cart_item (Except id). Override it if you want to do something special.
|
201
|
+
# The default copies all the common attributes from the passed in item to new cart_item (Except id and timestamps). Override it if you want to do something special.
|
202
202
|
#
|
203
203
|
def new_from_item(item, options = {})
|
204
|
-
cart_item = self.
|
205
|
-
|
206
|
-
cart_item.original = item
|
204
|
+
cart_item = item.send(self.to_s.tableize).build(options)
|
205
|
+
cart_item.attributes.map {|attribute| attribute if item.respond_to?(attribute[0].to_s) && !attribute[0].to_s.include?("_at") }.compact.each {|attribute| cart_item.send("#{attribute[0]}=", item.send(attribute[0].to_s))}
|
207
206
|
# TODO Add a callback
|
208
207
|
cart_item
|
209
208
|
# TODO Add a callback
|
data/test/fixtures/cart_item.rb
CHANGED
data/test/fixtures/item.rb
CHANGED
@@ -11,8 +11,8 @@ class ActsAsCartTest < ActiveSupport::TestCase
|
|
11
11
|
context 'configuration' do
|
12
12
|
should 'set defaults' do
|
13
13
|
Cart.expects(:aasm_column).with(:state)
|
14
|
-
Cart.expects(:has_many).with(:cart_items)
|
15
|
-
Cart.expects(:has_many).with(:order_totals)
|
14
|
+
Cart.expects(:has_many).with(:cart_items, {:dependent => :destroy})
|
15
|
+
Cart.expects(:has_many).with(:order_totals, {:dependent => :destroy})
|
16
16
|
|
17
17
|
Cart.acts_as_cart
|
18
18
|
|
@@ -26,8 +26,8 @@ class ActsAsCartTest < ActiveSupport::TestCase
|
|
26
26
|
context 'override' do
|
27
27
|
should 'change state' do
|
28
28
|
Cart.expects(:aasm_column).with(:dummy)
|
29
|
-
Cart.expects(:has_many).with(:cart_items)
|
30
|
-
Cart.expects(:has_many).with(:order_totals)
|
29
|
+
Cart.expects(:has_many).with(:cart_items, {:dependent => :destroy})
|
30
|
+
Cart.expects(:has_many).with(:order_totals, {:dependent => :destroy})
|
31
31
|
|
32
32
|
Cart.acts_as_cart :state_column => :dummy
|
33
33
|
|
@@ -53,8 +53,8 @@ class ActsAsCartTest < ActiveSupport::TestCase
|
|
53
53
|
|
54
54
|
should 'change cart_items' do
|
55
55
|
Cart.expects(:aasm_column).with(:state)
|
56
|
-
Cart.expects(:has_many).with(:test)
|
57
|
-
Cart.expects(:has_many).with(:order_totals)
|
56
|
+
Cart.expects(:has_many).with(:test, {:dependent => :destroy})
|
57
|
+
Cart.expects(:has_many).with(:order_totals, {:dependent => :destroy})
|
58
58
|
|
59
59
|
Cart.acts_as_cart :cart_items => :test
|
60
60
|
|
@@ -66,8 +66,8 @@ class ActsAsCartTest < ActiveSupport::TestCase
|
|
66
66
|
|
67
67
|
should 'change order_totals' do
|
68
68
|
Cart.expects(:aasm_column).with(:state)
|
69
|
-
Cart.expects(:has_many).with(:cart_items)
|
70
|
-
Cart.expects(:has_many).with(:test)
|
69
|
+
Cart.expects(:has_many).with(:cart_items, {:dependent => :destroy})
|
70
|
+
Cart.expects(:has_many).with(:test, {:dependent => :destroy})
|
71
71
|
|
72
72
|
Cart.acts_as_cart :order_totals => :test
|
73
73
|
|
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.18
|
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-
|
12
|
+
date: 2010-08-04 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|