acts_as_shopping_cart 0.4.0 → 0.4.1

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: f4f7ed62db4ed5b247d005dcafc10eb7ebdb3773
4
- data.tar.gz: 68c2a98c28d253d7077e1d0b93d1054f9c3c0820
3
+ metadata.gz: ad7a330566d80daae15b2607ef62db7371fbf587
4
+ data.tar.gz: 659618258dcadb593cf915635152735229849f57
5
5
  SHA512:
6
- metadata.gz: 4d841c20dcd7cd9344422fb99b95248dd1f92bb02ab0b8335de1b97f4b4d6b43ba6329332f04d7423d0ec7123ffebb5066a9db547a8f332476ec1fecb00748b0
7
- data.tar.gz: 63e9b2b8e4e2df46e1efd4db8afe96933336c51d57ee7136e251a184eff66b438080d9618f72624bbdbc869c83fbc3b922bc5c9399715cfcc6df17f03f3b4979
6
+ metadata.gz: 32aa00ad9d7adaca7d5a67b2bf449387f97a38ff46d4f7014d1975092310775ce30d8310e08c28825812f9c60874d646099a9d4dff0282a6e4fe59cb7c01018e
7
+ data.tar.gz: 77f185dcee1546399da192d341eaf84ad141c2f9bdb72dd620e811fd1a33d67d294bd8d6797a04f338cbbe72e42bae5824632e99e2691015309e02279ee58647
@@ -1,5 +1,7 @@
1
+ Rails:
2
+ Enabled: true
3
+
1
4
  AllCops:
2
- RunRailsCops: true
3
5
  DisplayCopNames: true
4
6
  DisplayStyleGuide: true
5
7
  StyleGuideCopsOnly: true
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.1
4
+
5
+ - Renamed the items? methods to `items?` and `no_items?`
6
+
3
7
  ## 0.4.0
4
8
 
5
9
  - Updated dependencies to use it on Rails 5
@@ -5,6 +5,7 @@ A simple shopping cart implementation.
5
5
  [![Build Status](https://secure.travis-ci.org/dabit/acts_as_shopping_cart.png?branch=master)](http://travis-ci.org/dabit/acts_as_shopping_cart)
6
6
  [![Code Climate](https://codeclimate.com/github/dabit/acts_as_shopping_cart/badges/gpa.svg)](https://codeclimate.com/github/dabit/acts_as_shopping_cart)
7
7
  [![Test Coverage](https://codeclimate.com/github/dabit/acts_as_shopping_cart/badges/coverage.svg)](https://codeclimate.com/github/dabit/acts_as_shopping_cart/coverage)
8
+ [![Gem Version](https://badge.fury.io/rb/acts_as_shopping_cart.svg)](https://badge.fury.io/rb/acts_as_shopping_cart)
8
9
 
9
10
  You can find an example application [here](https://github.com/dabit/acts_as_shopping_cart_app).
10
11
 
@@ -27,7 +28,7 @@ And run bundler
27
28
 
28
29
  Just include it in your Gemfile as:
29
30
 
30
- gem 'acts_as_shopping_cart', '~> 0.2.1'
31
+ gem 'acts_as_shopping_cart', '~> 0.4.0'
31
32
 
32
33
  And run bundle install
33
34
 
@@ -35,7 +36,7 @@ And run bundle install
35
36
 
36
37
  ## Usage
37
38
 
38
- You need two models, one to hold the Shopping Carts and another to hold the Items
39
+ You need two models, one to hold the `Shopping Carts` and another to hold the `Items`
39
40
 
40
41
  You can use any name for the models, you just have to let each model know about each other.
41
42
 
@@ -54,8 +55,8 @@ For the items:
54
55
  acts_as_shopping_cart_item_for :cart
55
56
  end
56
57
 
57
- or, if you want to use convention over configuration, make sure your models are called *ShoppingCart* and *ShoppingCartItem*,
58
- then just use the shortcuts:
58
+ or, if you want to use convention over configuration, make sure your models are
59
+ named `ShoppingCart` and `ShoppingCartItem`, then just use the shortcuts:
59
60
 
60
61
  class ShoppingCart < ActiveRecord::Base
61
62
  acts_as_shopping_cart
@@ -75,14 +76,15 @@ In order for this to work, the Shopping Cart Item model should have the followin
75
76
 
76
77
  ### Shopping Cart Items
77
78
 
78
- Your ShoppingCart class will have a _shopping_cart_items_ association
79
- that returns all the ShoppingCartItem objects in your cart.
79
+ Your `ShoppingCart` class will have a `shopping_cart_items` association
80
+ that returns all the `ShoppingCartItem` objects in your cart.
80
81
 
81
82
  ### Add Items
82
83
 
83
- 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.
84
+ To add an item to the cart you use the add method. You have to send the object
85
+ and the price of the object as parameters.
84
86
 
85
- So, if you had a Product class, you would do something like this:
87
+ So, if you had a `Product` class, you would do something like this:
86
88
 
87
89
  @cart = Cart.create
88
90
  @product = Product.find(1)
@@ -93,38 +95,41 @@ In the case where your product has a price field you could do something like:
93
95
 
94
96
  @cart.add(@product, @product.price)
95
97
 
96
- I tried to make it independent to the models in case you calculate discounts, sale prices or anything customized.
98
+ I tried to make it independent to the models in case you calculate discounts,
99
+ sale prices or anything customized.
97
100
 
98
101
  You can include a quantity parameter too.
99
102
 
100
103
  @cart.add(@product, 99.99, 5)
101
104
 
102
- In that case, you would add 5 of the same products to the shopping cart. If you don't specify the quantity 1 will be assumed.
105
+ In that case, you would add 5 of the same products to the shopping cart. If you
106
+ don't specify the quantity `1` will be assumed.
103
107
 
104
108
  ### Remove Items
105
109
 
106
- To remove an item from the cart you can use the remove method. You just have to send the object and the quantity you want to remove.
110
+ To remove an item from the cart you can use the remove method. You just have to
111
+ send the object and the quantity you want to remove.
107
112
 
108
113
  @cart.remove(@product, 1)
109
114
 
110
115
  ### Empty the cart
111
116
 
112
- To remove all the items in the cart at once, just use the _clear_ method
117
+ To remove all the items in the cart at once, just use the `clear` method
113
118
 
114
119
  @cart.clear
115
120
 
116
121
  ### Total
117
122
 
118
- You can find out about the total using the _total_ method:
123
+ You can find out about the total using the `total` method:
119
124
 
120
125
  @cart.total # => 99.99
121
126
 
122
127
  ### Taxes
123
128
 
124
- Taxes by default are calculated by multiplying subtotal times 8.25
129
+ Taxes by default are calculated by multiplying subtotal times `8.25`
125
130
 
126
- If you want to change the way taxes are calculated, override the taxes
127
- method on your class that acts_as_shopping_cart.
131
+ If you want to change the way taxes are calculated, override the `taxes`
132
+ method on your class that `acts_as_shopping_cart`.
128
133
 
129
134
  Example:
130
135
 
@@ -136,7 +141,7 @@ Example:
136
141
  end
137
142
  end
138
143
 
139
- If you just want to update the percentage, just override the tax_pct
144
+ If you just want to update the `percentage`, override the `tax_pct`
140
145
  method.
141
146
 
142
147
  class ShoppingCart < ActiveRecord::Base
@@ -163,9 +168,9 @@ class depending on your needs.
163
168
 
164
169
  ### Total unique items
165
170
 
166
- You can find out how many unique items you have on your cart using the _total_unique_items_ method.
171
+ You can find out how many unique items you have on your cart using the `total_unique_items` method.
167
172
 
168
- So, if you had something like:
173
+ So, if you have something like:
169
174
 
170
175
  @cart.add(@product, 99.99, 5)
171
176
 
@@ -28,16 +28,18 @@ module ActiveRecord
28
28
  #
29
29
  # Returns true when the cart has items
30
30
  #
31
- def has_items?
31
+ def items?
32
32
  shopping_cart_items.any?
33
33
  end
34
+ alias :has_items? :items?
34
35
 
35
36
  #
36
37
  # Returns true when the cart is empty
37
38
  #
38
- def has_no_items?
39
+ def no_items?
39
40
  shopping_cart_items.empty?
40
41
  end
42
+ alias :has_no_items? :no_items?
41
43
 
42
44
 
43
45
  #
@@ -1,3 +1,3 @@
1
1
  module ActsAsShoppingCart
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -77,42 +77,42 @@ describe ActiveRecord::Acts::ShoppingCart::Collection do
77
77
 
78
78
  it "clears all the items in the cart" do
79
79
  subject.clear
80
- expect(subject.has_no_items?).to be true
80
+ expect(subject.no_items?).to be true
81
81
  end
82
82
  end
83
83
 
84
- describe "has_items?" do
84
+ describe "items?" do
85
85
  context "cart has items" do
86
86
  before do
87
87
  subject.shopping_cart_items << double
88
88
  end
89
89
 
90
90
  it "returns true" do
91
- expect(subject.has_items?).to be true
91
+ expect(subject.items?).to be true
92
92
  end
93
93
  end
94
94
 
95
95
  context "cart is empty" do
96
96
  it "returns false" do
97
- expect(subject.has_items?).to be false
97
+ expect(subject.items?).to be false
98
98
  end
99
99
  end
100
100
  end
101
101
 
102
- describe "has_no_items?" do
102
+ describe "no_items?" do
103
103
  context "cart has items" do
104
104
  before do
105
105
  subject.shopping_cart_items << double
106
106
  end
107
107
 
108
108
  it "returns false" do
109
- expect(subject.has_no_items?).to be false
109
+ expect(subject.no_items?).to be false
110
110
  end
111
111
  end
112
112
 
113
113
  context "cart is empty" do
114
114
  it "returns true" do
115
- expect(subject.has_no_items?).to be true
115
+ expect(subject.no_items?).to be true
116
116
  end
117
117
  end
118
118
  end
@@ -170,7 +170,7 @@ describe ActiveRecord::Acts::ShoppingCart::Collection do
170
170
 
171
171
  it "returns the sum of the price * quantity for all items" do
172
172
  expect(subject.subtotal).to be_an_instance_of(Money)
173
- expect(subject.subtotal).to eq(Money.new(11397))
173
+ expect(subject.subtotal).to eq(Money.new(11_397))
174
174
  end
175
175
  end
176
176
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_shopping_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Padilla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-25 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails