acts_as_shopping_cart 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,3 +44,9 @@ Feature: Shopping Cart
44
44
  When I update the "Apple" price to "10.99"
45
45
  Then the price for "Apple" on the cart should be "10.99"
46
46
 
47
+ Scenario: Empty the shopping cart
48
+ Given I add 99 "Apple" products to cart with price "99.99"
49
+ When I empty the cart
50
+ Then cart should be empty
51
+ And the total for the cart should be "0"
52
+
@@ -28,9 +28,13 @@ When /^I remove (\d+) "([^"]*)" unit(s?) from cart$/ do |quantity, product_name,
28
28
  @cart.remove(product, quantity.to_i)
29
29
  end
30
30
 
31
+ When /^I empty the cart$/ do
32
+ @cart.clear
33
+ end
34
+
31
35
  Then /^cart should be empty$/ do
32
36
  @cart.reload
33
- @cart.shopping_cart_items.should be_empty
37
+ @cart.should be_empty
34
38
  end
35
39
 
36
40
  Given /^I add (\d+) "([^"]*)" products to cart with price "([^"]*)"$/ do |quantity, product_name, price|
@@ -17,6 +17,20 @@ module ActiveRecord
17
17
  end
18
18
  end
19
19
 
20
+ #
21
+ # Deletes all shopping_cart_items in the shopping_cart
22
+ #
23
+ def clear
24
+ shopping_cart_items.clear
25
+ end
26
+
27
+ #
28
+ # Returns true when the cart is empty
29
+ #
30
+ def empty?
31
+ shopping_cart_items.empty?
32
+ end
33
+
20
34
  #
21
35
  # Remove an item from the cart
22
36
  #
@@ -1,3 +1,3 @@
1
1
  module ActsAsShoppingCart
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -43,6 +43,35 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
43
43
  end
44
44
  end
45
45
 
46
+ describe :clear do
47
+ before do
48
+ subject.shopping_cart_items.should_receive(:clear)
49
+ end
50
+
51
+ it "clears all the items in the cart" do
52
+ subject.clear
53
+ subject.empty?.should be_true
54
+ end
55
+ end
56
+
57
+ describe "empty?" do
58
+ context "cart has items" do
59
+ before do
60
+ subject.shopping_cart_items << mock
61
+ end
62
+
63
+ it "returns false" do
64
+ subject.empty?.should be_false
65
+ end
66
+ end
67
+
68
+ context "cart is empty" do
69
+ it "returns true" do
70
+ subject.empty?.should be_true
71
+ end
72
+ end
73
+ end
74
+
46
75
  describe :remove do
47
76
  context "item is not on cart" do
48
77
  before 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.1
4
+ version: 0.1.2
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-30 00:00:00.000000000 Z
12
+ date: 2011-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70301979448540 !ruby/object:Gem::Requirement
16
+ requirement: &70145238308060 !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: *70301979448540
24
+ version_requirements: *70145238308060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cucumber
27
- requirement: &70301979448100 !ruby/object:Gem::Requirement
27
+ requirement: &70145238307620 !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: *70301979448100
35
+ version_requirements: *70145238307620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: database_cleaner
38
- requirement: &70301979447640 !ruby/object:Gem::Requirement
38
+ requirement: &70145238307160 !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: *70301979447640
46
+ version_requirements: *70145238307160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70301979447200 !ruby/object:Gem::Requirement
49
+ requirement: &70145238306720 !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: *70301979447200
57
+ version_requirements: *70145238306720
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &70301979446740 !ruby/object:Gem::Requirement
60
+ requirement: &70145238306260 !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: *70301979446740
68
+ version_requirements: *70145238306260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &70301979446280 !ruby/object:Gem::Requirement
71
+ requirement: &70145238305800 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70301979446280
79
+ version_requirements: *70145238305800
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &70301979445840 !ruby/object:Gem::Requirement
82
+ requirement: &70145238305360 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70301979445840
90
+ version_requirements: *70145238305360
91
91
  description: Simple Shopping Cart implementation
92
92
  email:
93
93
  - david@crowdint.com