cartman 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- return items.select{ |item| item.type == type }
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 items
36
+ return ItemCollection.new(line_item_ids.collect{ |item_id| get_item(item_id)})
37
37
  end
38
38
  end
39
39
 
@@ -1,3 +1,3 @@
1
1
  module Cartman
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -2,8 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Cartman do
4
4
  describe Cartman::ItemCollection do
5
- before(:all) do
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 = Cartman::Cart.new(1)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartman
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: