cartman 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cartman/cart.rb +3 -3
- data/lib/cartman/version.rb +1 -1
- data/spec/item_collection_spec.rb +11 -5
- metadata +1 -1
data/lib/cartman/cart.rb
CHANGED
@@ -29,11 +29,11 @@ module Cartman
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def items(type=nil)
|
32
|
-
items = ItemCollection.new(line_item_ids.collect{ |item_id| get_item(item_id)})
|
33
32
|
if type
|
34
|
-
|
33
|
+
items = line_item_ids.collect{ |item_id| get_item(item_id)}.select{ |item| item.type == type }
|
34
|
+
return ItemCollection.new(items)
|
35
35
|
else
|
36
|
-
return
|
36
|
+
return ItemCollection.new(line_item_ids.collect{ |item_id| get_item(item_id)})
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/cartman/version.rb
CHANGED
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cartman do
|
4
4
|
describe Cartman::ItemCollection do
|
5
|
-
|
6
|
-
end
|
5
|
+
let(:cart) { Cartman::Cart.new(1) }
|
7
6
|
|
8
7
|
before(:each) do
|
9
8
|
Cartman.config.redis.flushdb
|
@@ -11,14 +10,21 @@ describe Cartman do
|
|
11
10
|
Bottle = double
|
12
11
|
Bottle.stub(:find).and_return(bottle)
|
13
12
|
end
|
14
|
-
|
13
|
+
|
15
14
|
describe "#each_with_object" do
|
16
15
|
let(:bottle) { double("Bottle") }
|
16
|
+
|
17
17
|
it "should be magical" do
|
18
|
-
cart
|
19
|
-
cart.add_item(id: 17, type: "Bottle", name: "Bordeux", unit_cost: 92.12, cost: 184.24, quantity: 2)
|
18
|
+
cart.add_item(id: 17, type: "Bottle", name: "Bordeux", unit_cost: 92.12, cost: 184.24, quantity: 2)
|
20
19
|
expect { |b| cart.items.each_with_object(&b)}.to yield_successive_args([cart.items.first, bottle])
|
21
20
|
end
|
21
|
+
|
22
|
+
it "should work with items('Type')" do
|
23
|
+
cart.add_item(id: 17, type: "Bottle", name: "Bordeux", unit_cost: 92.12, cost: 184.24, quantity: 2)
|
24
|
+
cart.add_item(id: 27, type: "UserGiftCard", unit_cost: 25, quantity: 1)
|
25
|
+
expect { |b| cart.items("Bottle").each_with_object(&b)}.to_not raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|