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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f85f11cafab5fc9f037e657dbbdcbd035445d530
4
- data.tar.gz: cdbe305d67dd94f1123dfa266a60cf87c951e541
3
+ metadata.gz: f09938fd8e7495c32243f0cb4a69d70fe5aff445
4
+ data.tar.gz: 7c8104c31546c9e5c01f3e4679139877acb5965b
5
5
  SHA512:
6
- metadata.gz: 214a68adaac36287bc20b766e8fce424f3064b97942628099cffb7ede9ff3acaba7f9d01242653d79eab09d1349dd363cf4be2257a9ef759293ef162477943aa
7
- data.tar.gz: 71106c56751b7a8d41517fff58806123a8e6669af43a745720c074f374b979ddf042ff06f42349ef72e1b2a3e61b4d731229261c867b6fa18e07ca02d166b994
6
+ metadata.gz: 3d13a26996a653514f856f2b5ae21f36f880406404abbd2de4c22771139c3439b702d634f6d7a4c2750f570312d17b32c9bd82b70d32298ea32cc012b926eb5e
7
+ data.tar.gz: 468552fcf3518fbfc9ffb6f2db9d1a8efed4ca28d5aa0e9e44385e441a4aa06a977163b5b91a8680dce88abce76623c1473249ea04b9e8123234a7deb715513e
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  rvm:
2
2
  - 2.0.0
3
- - 2.1.0
3
+ - 2.1.5
4
4
 
5
5
  gemfile:
6
6
  - Gemfile.4.0
7
7
  - Gemfile.4.1
8
+ - Gemfile.4.2
data/Gemfile.4.2 ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in acts_as_shopping_cart.gemspec
4
+ gemspec
5
+
6
+ gem 'activerecord', '~> 4.2.0'
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 *ShoppingCartItems*,
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 'activerecord', '~> 4'
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|
@@ -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'
@@ -1,4 +1,5 @@
1
1
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
2
+ #ActiveRecord::Base.logger = Logger.new(STDOUT)
2
3
 
3
4
  ActiveRecord::Schema.define(:version => 1) do
4
5
  create_table :shopping_carts
@@ -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 items in the cart
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
- ("%.2f" % shopping_cart_items.inject(0) { |sum, item| sum += (item.price * item.quantity) }).to_f
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
- ("%.2f" % (self.subtotal + self.taxes + self.shipping_cost)).to_f
73
+ self.subtotal + self.taxes + self.shipping_cost
73
74
  end
74
75
 
75
76
  #
@@ -20,6 +20,7 @@ module ActiveRecord
20
20
  self.send :include, ActiveRecord::Acts::ShoppingCartItem::InstanceMethods
21
21
  belongs_to :owner, :polymorphic => true
22
22
  belongs_to :item, :polymorphic => true
23
+ monetize :price_cents
23
24
  end
24
25
 
25
26
  #
@@ -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 # 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
- float :price # Holds the price of the item
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
@@ -1,3 +1,3 @@
1
1
  module ActsAsShoppingCart
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,4 +1,6 @@
1
1
  require 'acts_as_shopping_cart/version'
2
+ require 'rails'
3
+ require 'money-rails'
2
4
  require 'active_record/acts/shopping_cart'
3
5
  require 'active_record/acts/shopping_cart_item'
4
6
  require 'acts_as_shopping_cart/schema'
@@ -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 eq(0)
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 => 33.99), stub(:quantity => 1, :price => 45.99)]
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(100)
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(10.99)
184
- subject.stub(:taxes).and_return(13.99)
185
- subject.stub(:shipping_cost).and_return(12.99)
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.2.2
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: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activerecord
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.0
181
+ rubygems_version: 2.2.2
167
182
  signing_key:
168
183
  specification_version: 4
169
184
  summary: Simple Shopping Cart implementation