active_cart 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
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.merge(:quantity => quantity, :original_id => item.id, :original_type => item.class.to_s))
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.new
205
- item.class.columns.map {|col| col.name }.each { |col| cart_item.send((col.to_s + "=").to_sym, item.send(col)) if cart_item.respond_to?((col.to_s + "=").to_sym) }
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
@@ -1,3 +1,5 @@
1
1
  class CartItem < ActiveRecord::Base
2
2
  acts_as_cart_item
3
+
4
+ attr_accessor :options
3
5
  end
@@ -1,2 +1,3 @@
1
1
  class Item < ActiveRecord::Base
2
+ has_many :cart_items, :as => :original
2
3
  end
@@ -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.17
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-07-11 00:00:00 +08:00
12
+ date: 2010-08-04 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency