acts_as_shopping_cart 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # acts_as_shopping_cart
2
2
 
3
- A simple shopping cart implementation. Still on Alpha, use it at your own risk.
3
+ A simple shopping cart implementation.
4
4
 
5
5
  ## Install
6
6
 
@@ -51,14 +51,14 @@ then just use the shortcuts:
51
51
  In order for this to work, the Shopping Cart Item model should have the following fields:
52
52
 
53
53
  create_table :cart_items do |t|
54
- t.integer :owner_id # Holds the owner id, for polymorphism
55
- t.integer :owner_type # Holds the type of the owner, for polymorphism
56
- t.integer :quantity # Holds the quantity of the object
57
- t.integer :item_id # Holds the object id
58
- t.string :item_type # Holds the type of the object, for polymorphism
59
- t.float :price # Holds the price of the item
54
+ t.shopping_cart_item_fields # Creates the cart items fields
60
55
  end
61
56
 
57
+ ### Shopping Cart Items
58
+
59
+ Your ShoppingCart class will have a _shopping_cart_items_ association
60
+ that returns all the ShoppingCartItem objects in your cart.
61
+
62
62
  ### Add Items
63
63
 
64
64
  To add an item to the cart you use the add method. You have to send the object and the price of the object as parameters.
@@ -162,7 +162,11 @@ Run rspec
162
162
 
163
163
  Run cucumber features
164
164
 
165
- bundle exec cucumber
165
+ cucumber
166
+
167
+ Both:
168
+
169
+ rake
166
170
 
167
171
  # About the Author
168
172
 
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'cucumber/rake/task'
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = %w{--format progress}
6
+ end
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.skip_bundler = true
11
+ t.fail_on_error = true
12
+ end
13
+
14
+ task :default => [:spec, :cucumber]
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "rspec"
25
25
  s.add_development_dependency "sqlite3"
26
26
  s.add_development_dependency "simplecov"
27
+ s.add_development_dependency "rake"
27
28
  end
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  Then /^cart should be empty$/ do
32
32
  @cart.reload
33
- @cart.cart_items.should be_empty
33
+ @cart.shopping_cart_items.should be_empty
34
34
  end
35
35
 
36
36
  Given /^I add (\d+) "([^"]*)" products to cart with price "([^"]*)"$/ do |quantity, product_name, price|
@@ -1,5 +1,8 @@
1
1
  require 'active_record'
2
2
  require 'database_cleaner'
3
+
4
+ $: << './lib'
5
+
3
6
  require 'acts_as_shopping_cart'
4
7
 
5
8
  require 'simplecov'
@@ -19,7 +19,7 @@ module ActiveRecord
19
19
  def acts_as_shopping_cart_using(item_class)
20
20
  self.send :include, ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods
21
21
  self.send :include, ActiveRecord::Acts::ShoppingCart::Item::InstanceMethods
22
- has_many :cart_items, :class_name => item_class.to_s.classify, :as => :owner
22
+ has_many :shopping_cart_items, :class_name => item_class.to_s.classify, :as => :owner
23
23
  end
24
24
 
25
25
  #
@@ -10,7 +10,7 @@ module ActiveRecord
10
10
  cart_item = item_for(object)
11
11
 
12
12
  unless cart_item
13
- cart_items.create(:item => object, :price => price, :quantity => quantity)
13
+ shopping_cart_items.create(:item => object, :price => price, :quantity => quantity)
14
14
  else
15
15
  cart_item.quantity = (cart_item.quantity + quantity)
16
16
  cart_item.save
@@ -35,7 +35,7 @@ module ActiveRecord
35
35
  # Returns the subtotal by summing the price times quantity for all the items in the cart
36
36
  #
37
37
  def subtotal
38
- ("%.2f" % cart_items.inject(0) { |sum, item| sum += (item.price * item.quantity) }).to_f
38
+ ("%.2f" % shopping_cart_items.inject(0) { |sum, item| sum += (item.price * item.quantity) }).to_f
39
39
  end
40
40
 
41
41
  def shipping_cost
@@ -61,7 +61,12 @@ module ActiveRecord
61
61
  # Return the number of unique items in the cart
62
62
  #
63
63
  def total_unique_items
64
- cart_items.inject(0) { |sum, item| sum += item.quantity }
64
+ shopping_cart_items.inject(0) { |sum, item| sum += item.quantity }
65
+ end
66
+
67
+ def cart_items
68
+ warn "ShoppingCart#cart_items WILL BE DEPRECATED IN LATER VERSIONS OF acts_as_shopping_cart, please use ShoppingCart#shopping_cart_items instead"
69
+ self.shopping_cart_items
65
70
  end
66
71
  end
67
72
  end
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  # Returns the cart item for the specified object
9
9
  #
10
10
  def item_for(object)
11
- cart_items.where(:item_id => object.id).first
11
+ shopping_cart_items.where(:item_id => object.id).first
12
12
  end
13
13
 
14
14
  #
@@ -1,3 +1,3 @@
1
1
  module ActsAsShoppingCart
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -9,7 +9,7 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
9
9
 
10
10
  let(:subject) do
11
11
  subject = klass.new
12
- subject.stub(:cart_items).and_return([])
12
+ subject.stub(:shopping_cart_items).and_return([])
13
13
  subject
14
14
  end
15
15
 
@@ -26,7 +26,7 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
26
26
  end
27
27
 
28
28
  it "creates a new shopping cart item" do
29
- subject.cart_items.should_receive(:create).with(:item => object, :price => 19.99, :quantity => 3)
29
+ subject.shopping_cart_items.should_receive(:create).with(:item => object, :price => 19.99, :quantity => 3)
30
30
  subject.add(object, 19.99, 3)
31
31
  end
32
32
  end
@@ -78,7 +78,7 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
78
78
  describe :subtotal do
79
79
  context "cart has no items" do
80
80
  before do
81
- subject.stub(:cart_items).and_return([])
81
+ subject.stub(:shopping_cart_items).and_return([])
82
82
  end
83
83
 
84
84
  it "returns 0" do
@@ -89,7 +89,7 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
89
89
  context "cart has items" do
90
90
  before do
91
91
  items = [stub(:quantity => 2, :price => 33.99), stub(:quantity => 1, :price => 45.99)]
92
- subject.stub(:cart_items).and_return(items)
92
+ subject.stub(:shopping_cart_items).and_return(items)
93
93
  end
94
94
 
95
95
  it "returns the sum of the price * quantity for all items" do
@@ -144,7 +144,7 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
144
144
  context "cart has some items" do
145
145
  before do
146
146
  items = [stub(:quantity => 2, :price => 33.99), stub(:quantity => 1, :price => 45.99)]
147
- subject.stub(:cart_items).and_return(items)
147
+ subject.stub(:shopping_cart_items).and_return(items)
148
148
  end
149
149
 
150
150
  it "returns the sum of the quantities of all shopping cart items" do
@@ -7,11 +7,11 @@ describe ActiveRecord::Acts::ShoppingCart::Item::InstanceMethods do
7
7
  klass
8
8
  end
9
9
 
10
- let(:cart_items) { stub }
10
+ let(:shopping_cart_items) { stub }
11
11
 
12
12
  let(:subject) do
13
13
  subject = klass.new
14
- subject.stub(:cart_items).and_return(cart_items)
14
+ subject.stub(:shopping_cart_items).and_return(shopping_cart_items)
15
15
  subject
16
16
  end
17
17
 
@@ -21,7 +21,7 @@ describe ActiveRecord::Acts::ShoppingCart::Item::InstanceMethods do
21
21
  describe :item_for do
22
22
  context "no cart item exists for the object" do
23
23
  before do
24
- cart_items.should_receive(:where).with(:item_id => object.id).and_return([])
24
+ shopping_cart_items.should_receive(:where).with(:item_id => object.id).and_return([])
25
25
  end
26
26
 
27
27
  it "returns the shopping cart item object for the requested object" do
@@ -31,7 +31,7 @@ describe ActiveRecord::Acts::ShoppingCart::Item::InstanceMethods do
31
31
 
32
32
  context "a cart item exists for the object" do
33
33
  before do
34
- cart_items.should_receive(:where).with(:item_id => object.id).and_return([ item ])
34
+ shopping_cart_items.should_receive(:where).with(:item_id => object.id).and_return([ item ])
35
35
  end
36
36
 
37
37
  it "returns that item" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_shopping_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-27 00:00:00.000000000 Z
12
+ date: 2011-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70130533045720 !ruby/object:Gem::Requirement
16
+ requirement: &70301979448540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70130533045720
24
+ version_requirements: *70301979448540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cucumber
27
- requirement: &70130533045220 !ruby/object:Gem::Requirement
27
+ requirement: &70301979448100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70130533045220
35
+ version_requirements: *70301979448100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: database_cleaner
38
- requirement: &70130533044740 !ruby/object:Gem::Requirement
38
+ requirement: &70301979447640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70130533044740
46
+ version_requirements: *70301979447640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70130533044320 !ruby/object:Gem::Requirement
49
+ requirement: &70301979447200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70130533044320
57
+ version_requirements: *70301979447200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &70130533043880 !ruby/object:Gem::Requirement
60
+ requirement: &70301979446740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70130533043880
68
+ version_requirements: *70301979446740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &70130533043300 !ruby/object:Gem::Requirement
71
+ requirement: &70301979446280 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,18 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70130533043300
79
+ version_requirements: *70301979446280
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: &70301979445840 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70301979445840
80
91
  description: Simple Shopping Cart implementation
81
92
  email:
82
93
  - david@crowdint.com