acts_as_shopping_cart 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile.4.2 +6 -0
- data/README.markdown +1 -1
- data/acts_as_shopping_cart.gemspec +4 -2
- data/features/step_definitions/shopping_cart_steps.rb +2 -2
- data/features/support/env.rb +7 -0
- data/features/support/rails_env.rb +1 -0
- data/lib/active_record/acts/shopping_cart/collection.rb +5 -4
- data/lib/active_record/acts/shopping_cart_item.rb +1 -0
- data/lib/acts_as_shopping_cart/schema.rb +7 -6
- data/lib/acts_as_shopping_cart/version.rb +1 -1
- data/lib/acts_as_shopping_cart.rb +2 -0
- data/spec/active_record/acts/shopping_cart/collection_spec.rb +11 -6
- data/spec/spec_helper.rb +5 -0
- metadata +33 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f09938fd8e7495c32243f0cb4a69d70fe5aff445
|
4
|
+
data.tar.gz: 7c8104c31546c9e5c01f3e4679139877acb5965b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d13a26996a653514f856f2b5ae21f36f880406404abbd2de4c22771139c3439b702d634f6d7a4c2750f570312d17b32c9bd82b70d32298ea32cc012b926eb5e
|
7
|
+
data.tar.gz: 468552fcf3518fbfc9ffb6f2db9d1a8efed4ca28d5aa0e9e44385e441a4aa06a977163b5b91a8680dce88abce76623c1473249ea04b9e8123234a7deb715513e
|
data/.travis.yml
CHANGED
data/Gemfile.4.2
ADDED
data/README.markdown
CHANGED
@@ -52,7 +52,7 @@ For the items:
|
|
52
52
|
acts_as_shopping_cart_item_for :cart
|
53
53
|
end
|
54
54
|
|
55
|
-
or, if you want to use convention over configuration, make sure your models are called *ShoppingCart* and *
|
55
|
+
or, if you want to use convention over configuration, make sure your models are called *ShoppingCart* and *ShoppingCartItem*,
|
56
56
|
then just use the shortcuts:
|
57
57
|
|
58
58
|
class ShoppingCart < ActiveRecord::Base
|
@@ -18,11 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency '
|
21
|
+
s.add_dependency 'rails', '~> 4'
|
22
|
+
s.add_dependency 'money-rails', '~> 1.3'
|
23
|
+
|
22
24
|
s.add_development_dependency "cucumber", '~> 1.3.14'
|
23
25
|
s.add_development_dependency "database_cleaner"
|
26
|
+
s.add_development_dependency "rake", "~> 10.0.0"
|
24
27
|
s.add_development_dependency "rspec", "~> 2.12.0"
|
25
28
|
s.add_development_dependency "sqlite3", "~> 1.3.0"
|
26
29
|
s.add_development_dependency "simplecov"
|
27
|
-
s.add_development_dependency "rake", "~> 10.0.0"
|
28
30
|
end
|
@@ -4,12 +4,12 @@ end
|
|
4
4
|
|
5
5
|
Then /^the total for the cart should be "([^"]*)"$/ do |total|
|
6
6
|
@cart.reload
|
7
|
-
@cart.total.should eq(total.to_f)
|
7
|
+
@cart.total.should eq(Money.new(total.to_f * 100))
|
8
8
|
end
|
9
9
|
|
10
10
|
Then /^the subtotal for the cart should be "([^"]*)"$/ do |subtotal|
|
11
11
|
@cart.reload
|
12
|
-
@cart.subtotal.should eq(subtotal.to_f)
|
12
|
+
@cart.subtotal.should eq(Money.new(subtotal.to_f * 100))
|
13
13
|
end
|
14
14
|
|
15
15
|
When /^I add product "([^"]*)" to cart with price "([^"]*)"$/ do |product_name, price|
|
data/features/support/env.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
1
3
|
require 'active_record'
|
2
4
|
require 'database_cleaner'
|
5
|
+
require 'money-rails'
|
3
6
|
|
4
7
|
$: << './lib'
|
5
8
|
|
6
9
|
require 'acts_as_shopping_cart'
|
7
10
|
|
11
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
12
|
+
|
13
|
+
MoneyRails::Hooks.init
|
14
|
+
|
8
15
|
require 'simplecov'
|
9
16
|
|
10
17
|
SimpleCov.coverage_dir 'coverage.features'
|
@@ -47,14 +47,15 @@ module ActiveRecord
|
|
47
47
|
end
|
48
48
|
|
49
49
|
#
|
50
|
-
# Returns the subtotal by summing the price times quantity for all the
|
50
|
+
# Returns the subtotal by summing the price times quantity for all the
|
51
|
+
# items in the cart
|
51
52
|
#
|
52
53
|
def subtotal
|
53
|
-
|
54
|
+
shopping_cart_items.inject(Money.new(0)) { |sum, item| sum += (item.price * item.quantity) }
|
54
55
|
end
|
55
56
|
|
56
57
|
def shipping_cost
|
57
|
-
0
|
58
|
+
Money.new(0)
|
58
59
|
end
|
59
60
|
|
60
61
|
def taxes
|
@@ -69,7 +70,7 @@ module ActiveRecord
|
|
69
70
|
# Returns the total by summing the subtotal, taxes and shipping_cost
|
70
71
|
#
|
71
72
|
def total
|
72
|
-
|
73
|
+
self.subtotal + self.taxes + self.shipping_cost
|
73
74
|
end
|
74
75
|
|
75
76
|
#
|
@@ -3,12 +3,13 @@ require 'active_record/connection_adapters/abstract/schema_definitions'
|
|
3
3
|
module ActsAsShoppingCart
|
4
4
|
module Schema
|
5
5
|
def shopping_cart_item_fields
|
6
|
-
integer :owner_id
|
7
|
-
string :owner_type
|
8
|
-
integer :quantity
|
9
|
-
integer :item_id
|
10
|
-
string :item_type
|
11
|
-
|
6
|
+
integer :owner_id # Holds the owner id, for polymorphism
|
7
|
+
string :owner_type # Holds the type of the owner, for polymorphism
|
8
|
+
integer :quantity # Holds the quantity of the object
|
9
|
+
integer :item_id # Holds the object id
|
10
|
+
string :item_type # Holds the type of the object, for polymorphism
|
11
|
+
integer :price_cents, default: 0, null: false # Holds the price of the item
|
12
|
+
string :price_currency, default: "USD", null: false # Holds the currency for the price
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -138,17 +138,19 @@ describe ActiveRecord::Acts::ShoppingCart::Collection do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it "returns 0" do
|
141
|
-
subject.subtotal.should
|
141
|
+
subject.subtotal.should be_an_instance_of(Money)
|
142
|
+
subject.subtotal.should eq(Money.new(0))
|
142
143
|
end
|
143
144
|
end
|
144
145
|
|
145
146
|
context "cart has items" do
|
146
147
|
before do
|
147
|
-
items = [stub(:quantity => 2, :price =>
|
148
|
+
items = [stub(:quantity => 2, :price => Money.new(3399)), stub(:quantity => 1, :price => Money.new(4599))]
|
148
149
|
subject.stub(:shopping_cart_items).and_return(items)
|
149
150
|
end
|
150
151
|
|
151
152
|
it "returns the sum of the price * quantity for all items" do
|
153
|
+
subject.subtotal.should be_an_instance_of(Money)
|
152
154
|
subject.subtotal.should eq(113.97)
|
153
155
|
end
|
154
156
|
end
|
@@ -156,6 +158,7 @@ describe ActiveRecord::Acts::ShoppingCart::Collection do
|
|
156
158
|
|
157
159
|
describe :shipping_cost do
|
158
160
|
it "returns 0" do
|
161
|
+
subject.shipping_cost.should be_an_instance_of Money
|
159
162
|
subject.shipping_cost.should eq(0)
|
160
163
|
end
|
161
164
|
end
|
@@ -163,10 +166,11 @@ describe ActiveRecord::Acts::ShoppingCart::Collection do
|
|
163
166
|
describe :taxes do
|
164
167
|
context "subtotal is 100" do
|
165
168
|
before do
|
166
|
-
subject.stub(:subtotal).and_return(
|
169
|
+
subject.stub(:subtotal).and_return(Money.new(10000))
|
167
170
|
end
|
168
171
|
|
169
172
|
it "returns 8.25" do
|
173
|
+
subject.taxes.should be_an_instance_of Money
|
170
174
|
subject.taxes.should eq(8.25)
|
171
175
|
end
|
172
176
|
end
|
@@ -180,12 +184,13 @@ describe ActiveRecord::Acts::ShoppingCart::Collection do
|
|
180
184
|
|
181
185
|
describe :total do
|
182
186
|
before do
|
183
|
-
subject.stub(:subtotal).and_return(
|
184
|
-
subject.stub(:taxes).and_return(
|
185
|
-
subject.stub(:shipping_cost).and_return(
|
187
|
+
subject.stub(:subtotal).and_return(Money.new(1099))
|
188
|
+
subject.stub(:taxes).and_return(Money.new(1399))
|
189
|
+
subject.stub(:shipping_cost).and_return(Money.new(1299))
|
186
190
|
end
|
187
191
|
|
188
192
|
it "returns subtotal + taxes + shipping_cost" do
|
193
|
+
subject.total.should be_an_instance_of Money
|
189
194
|
subject.total.should eq(37.97)
|
190
195
|
end
|
191
196
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,8 +5,13 @@ require 'rubygems'
|
|
5
5
|
require 'bundler/setup'
|
6
6
|
|
7
7
|
require 'simplecov'
|
8
|
+
require 'rails'
|
8
9
|
require 'active_record'
|
10
|
+
require 'money-rails'
|
9
11
|
|
12
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
13
|
+
|
14
|
+
MoneyRails::Hooks.init
|
10
15
|
require 'acts_as_shopping_cart'
|
11
16
|
|
12
17
|
SimpleCov.start
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_shopping_cart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Padilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: money-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: cucumber
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.0.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rspec
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +122,6 @@ dependencies:
|
|
94
122
|
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 10.0.0
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 10.0.0
|
111
125
|
description: Simple Shopping Cart implementation
|
112
126
|
email:
|
113
127
|
- david@crowdint.com
|
@@ -121,6 +135,7 @@ files:
|
|
121
135
|
- Gemfile
|
122
136
|
- Gemfile.4.0
|
123
137
|
- Gemfile.4.1
|
138
|
+
- Gemfile.4.2
|
124
139
|
- LICENSE
|
125
140
|
- README.markdown
|
126
141
|
- Rakefile
|
@@ -163,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
178
|
version: '0'
|
164
179
|
requirements: []
|
165
180
|
rubyforge_project: acts_as_shopping_cart
|
166
|
-
rubygems_version: 2.2.
|
181
|
+
rubygems_version: 2.2.2
|
167
182
|
signing_key:
|
168
183
|
specification_version: 4
|
169
184
|
summary: Simple Shopping Cart implementation
|