acts_as_shopping_cart 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/README.markdown +11 -5
- data/Rakefile +0 -1
- data/features/shopping_cart.feature +13 -0
- data/features/step_definitions/shopping_cart_steps.rb +5 -0
- data/lib/active_record/acts/shopping_cart/cart/instance_methods.rb +3 -2
- data/lib/acts_as_shopping_cart/version.rb +1 -1
- data/script/build.sh +18 -0
- data/spec/active_record/acts/shopping_cart/cart/instance_methods_spec.rb +22 -0
- metadata +60 -17
data/.travis.yml
ADDED
data/README.markdown
CHANGED
@@ -2,13 +2,17 @@
|
|
2
2
|
|
3
3
|
A simple shopping cart implementation.
|
4
4
|
|
5
|
+
[![Build Status](https://secure.travis-ci.org/crowdint/acts_as_shopping_cart.png?branch=master)](http://travis-ci.org/crowdint/acts_as_shopping_cart)
|
6
|
+
|
7
|
+
You can find an example application [here](https://github.com/crowdint/acts_as_shopping_cart_app).
|
8
|
+
|
5
9
|
## Install
|
6
10
|
|
7
11
|
### Rails 3
|
8
12
|
|
9
13
|
Include it in your Gemfile
|
10
14
|
|
11
|
-
gem 'acts_as_shopping_cart',
|
15
|
+
gem 'acts_as_shopping_cart', '~> 0.1.4'
|
12
16
|
|
13
17
|
And run bundler
|
14
18
|
|
@@ -174,8 +178,10 @@ Both:
|
|
174
178
|
|
175
179
|
rake
|
176
180
|
|
177
|
-
# About the
|
181
|
+
# About the author
|
178
182
|
|
179
|
-
[Crowd Interactive](http://www.crowdint.com) is
|
180
|
-
|
181
|
-
|
183
|
+
[Crowd Interactive](http://www.crowdint.com) is a leading Ruby and Rails
|
184
|
+
consultancy firm based in Mexico currently doing business with startups in the
|
185
|
+
United States. We specialize in building and growing Rails applications, by increasing
|
186
|
+
your IT crew onsite or offsite. We pick our projects carefully, as we only work
|
187
|
+
with companies we believe in.
|
data/Rakefile
CHANGED
@@ -10,6 +10,11 @@ Feature: Shopping Cart
|
|
10
10
|
And the total for the cart should be "108.24"
|
11
11
|
And the total unique items on the cart should be "1"
|
12
12
|
|
13
|
+
Scenario: Cart Totals when cart is empty
|
14
|
+
Then the subtotal for the cart should be "0"
|
15
|
+
And the total for the cart should be "0"
|
16
|
+
And the total unique items on the cart should be "0"
|
17
|
+
|
13
18
|
Scenario: Add a product to cart twice
|
14
19
|
When I add product "Apple" to cart with price "99.99"
|
15
20
|
And I add product "Apple" to cart with price "99.99"
|
@@ -17,6 +22,14 @@ Feature: Shopping Cart
|
|
17
22
|
Then the total for the cart should be "216.48"
|
18
23
|
And the total unique items on the cart should be "2"
|
19
24
|
|
25
|
+
Scenario: Add a product to cart twice non-cumulatively
|
26
|
+
When I add product "Apple" to cart with price "99.99"
|
27
|
+
And I add product "Apple" to cart with price "99.99"
|
28
|
+
And I non-cumulatively add product "Apple" to cart with price "99.99"
|
29
|
+
Then the subtotal for the cart should be "99.99"
|
30
|
+
Then the total for the cart should be "108.24"
|
31
|
+
And the total unique items on the cart should be "1"
|
32
|
+
|
20
33
|
Scenario: Remove products from cart
|
21
34
|
Given I add 3 "Apple" products to cart with price "99.99"
|
22
35
|
When I remove 1 "Apple" unit from cart
|
@@ -17,6 +17,11 @@ When /^I add product "([^"]*)" to cart with price "([^"]*)"$/ do |product_name,
|
|
17
17
|
@cart.add(product, price)
|
18
18
|
end
|
19
19
|
|
20
|
+
When /^I non-cumulatively add product "([^"]*)" to cart with price "([^"]*)"$/ do |product_name, price|
|
21
|
+
product = Product.find_by_name(product_name)
|
22
|
+
@cart.add(product, price, 1, false)
|
23
|
+
end
|
24
|
+
|
20
25
|
Then /^the total unique items on the cart should be "([^"]*)"$/ do |total|
|
21
26
|
@cart.reload
|
22
27
|
@cart.total_unique_items.should eq(total.to_i)
|
@@ -6,13 +6,14 @@ module ActiveRecord
|
|
6
6
|
#
|
7
7
|
# Adds a product to the cart
|
8
8
|
#
|
9
|
-
def add(object, price, quantity = 1)
|
9
|
+
def add(object, price, quantity = 1, cumulative = true)
|
10
10
|
cart_item = item_for(object)
|
11
11
|
|
12
12
|
unless cart_item
|
13
13
|
shopping_cart_items.create(:item => object, :price => price, :quantity => quantity)
|
14
14
|
else
|
15
|
-
|
15
|
+
cumulative = cumulative == true ? cart_item.quantity : 0
|
16
|
+
cart_item.quantity = (cumulative + quantity)
|
16
17
|
cart_item.save
|
17
18
|
end
|
18
19
|
end
|
data/script/build.sh
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
|
3
|
+
CC_RUBY=1.9.3
|
4
|
+
CC_GEMSET=aasc
|
5
|
+
|
6
|
+
# Initialize RVM
|
7
|
+
source "$HOME/.rvm/scripts/rvm"
|
8
|
+
|
9
|
+
# Change gemset
|
10
|
+
rvm $CC_RUBY@$CC_GEMSET --create
|
11
|
+
|
12
|
+
# Is bundler installed?
|
13
|
+
bundle -v || gem install bundler
|
14
|
+
|
15
|
+
# Go get the dependencies
|
16
|
+
bundle install
|
17
|
+
|
18
|
+
bundle exec rake
|
@@ -31,6 +31,17 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
context "item is not in cart" do
|
35
|
+
before do
|
36
|
+
subject.stub(:item_for).with(object)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "creates a new shopping cart item non-cumulatively" do
|
40
|
+
subject.shopping_cart_items.should_receive(:create).with(:item => object, :price => 19.99, :quantity => 3)
|
41
|
+
subject.add(object, 19.99, 3, false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
34
45
|
context "item is already on cart" do
|
35
46
|
before do
|
36
47
|
subject.stub(:item_for).with(object).and_return(shopping_cart_item)
|
@@ -41,6 +52,17 @@ describe ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods do
|
|
41
52
|
subject.add(object, 19.99, 3)
|
42
53
|
end
|
43
54
|
end
|
55
|
+
|
56
|
+
context "item is already in cart" do
|
57
|
+
before do
|
58
|
+
subject.stub(:item_for).with(object).and_return(shopping_cart_item)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "updates the quantity for the item non-cumulatively" do
|
62
|
+
shopping_cart_item.should_receive(:quantity=).with(3) # not 5
|
63
|
+
subject.add(object, 19.99, 3, false)
|
64
|
+
end
|
65
|
+
end
|
44
66
|
end
|
45
67
|
|
46
68
|
describe :clear 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.
|
4
|
+
version: 0.1.5
|
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:
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: cucumber
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: database_cleaner
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rspec
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: sqlite3
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: simplecov
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: rake
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,7 +117,12 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
description: Simple Shopping Cart implementation
|
92
127
|
email:
|
93
128
|
- david@crowdint.com
|
@@ -97,6 +132,7 @@ extra_rdoc_files: []
|
|
97
132
|
files:
|
98
133
|
- .document
|
99
134
|
- .gitignore
|
135
|
+
- .travis.yml
|
100
136
|
- Gemfile
|
101
137
|
- LICENSE
|
102
138
|
- README.markdown
|
@@ -115,6 +151,7 @@ files:
|
|
115
151
|
- lib/acts_as_shopping_cart.rb
|
116
152
|
- lib/acts_as_shopping_cart/schema.rb
|
117
153
|
- lib/acts_as_shopping_cart/version.rb
|
154
|
+
- script/build.sh
|
118
155
|
- spec/active_record/acts/shopping_cart/cart/instance_methods_spec.rb
|
119
156
|
- spec/active_record/acts/shopping_cart/item/instance_methods_spec.rb
|
120
157
|
- spec/active_record/acts/shopping_cart_item/instance_methods_spec.rb
|
@@ -132,15 +169,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
169
|
- - ! '>='
|
133
170
|
- !ruby/object:Gem::Version
|
134
171
|
version: '0'
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
hash: -3420096489731286519
|
135
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
176
|
none: false
|
137
177
|
requirements:
|
138
178
|
- - ! '>='
|
139
179
|
- !ruby/object:Gem::Version
|
140
180
|
version: '0'
|
181
|
+
segments:
|
182
|
+
- 0
|
183
|
+
hash: -3420096489731286519
|
141
184
|
requirements: []
|
142
185
|
rubyforge_project: acts_as_shopping_cart
|
143
|
-
rubygems_version: 1.8.
|
186
|
+
rubygems_version: 1.8.23
|
144
187
|
signing_key:
|
145
188
|
specification_version: 3
|
146
189
|
summary: Simple Shopping Cart implementation
|