kosher 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/kosher/offer.rb CHANGED
@@ -6,8 +6,7 @@ module Kosher
6
6
  if self.kosher? != other.kosher?
7
7
  self.kosher? ? -1 : 1
8
8
  else
9
- currency = base_currency
10
- self.price.exchange_to(currency) <=> other.price.exchange_to(currency)
9
+ self.price.exchange_to(base_currency) <=> other.price.exchange_to(base_currency)
11
10
  end
12
11
  end
13
12
 
@@ -1,4 +1,9 @@
1
1
  module Kosher
2
2
  class Snapshot < Struct.new(:venue, :isbn, :asin, :sales_rank, :offers_count, :offers, :created_at)
3
+ def best_kosher_offer
4
+ offer = offers.sort.first
5
+
6
+ offer.kosher? ? offer : nil
7
+ end
3
8
  end
4
9
  end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.2.10'
2
+ VERSION = '0.2.11'
3
3
  end
@@ -1,5 +1,71 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Kosher
4
- describe Snapshot
4
+ describe Snapshot do
5
+ describe "#best_kosher_offer" do
6
+ before do
7
+ @snapshot = Snapshot.new
8
+ @snapshot.offers = []
9
+
10
+ @offer1 = Offer.new
11
+ @offer2 = Offer.new
12
+ end
13
+
14
+ context "when there are more than one kosher offers" do
15
+ before do
16
+ @offer1.stub!(:kosher?).and_return(true)
17
+ @offer1.stub!(:price).and_return(Money.new(200, 'EUR'))
18
+ @snapshot.offers << @offer1
19
+
20
+ @offer2.stub!(:kosher?).and_return(true)
21
+ @offer2.stub!(:price).and_return(Money.new(100, 'EUR'))
22
+ @snapshot.offers << @offer2
23
+ end
24
+
25
+ it "returns the kosher offer with the lower price" do
26
+ @snapshot.best_kosher_offer.should eql @offer2
27
+ end
28
+ end
29
+
30
+ context "when there is one kosher and one unkosher offer" do
31
+ before do
32
+ @offer1.stub!(:kosher?).and_return(true)
33
+ @offer1.stub!(:price).and_return(Money.new(200, 'EUR'))
34
+ @snapshot.offers << @offer1
35
+
36
+ @offer2.stub!(:kosher?).and_return(false)
37
+ @offer2.stub!(:price).and_return(Money.new(100, 'EUR'))
38
+ @snapshot.offers << @offer2
39
+ end
40
+
41
+ it "returns the best kosher offer" do
42
+ @snapshot.best_kosher_offer.should eql @offer1
43
+ end
44
+ end
45
+
46
+ context "when there is one kosher offer" do
47
+ before do
48
+ @offer1.stub!(:kosher?).and_return(true)
49
+ @offer1.stub!(:price).and_return(Money.new(100, 'EUR'))
50
+ @snapshot.offers << @offer1
51
+ end
52
+
53
+ it "returns the kosher offer" do
54
+ @snapshot.best_kosher_offer.should eql @offer1
55
+ end
56
+ end
57
+
58
+ context "when there is one unkosher offer" do
59
+ before do
60
+ @offer1.stub!(:kosher?).and_return(false)
61
+ @offer1.stub!(:price).and_return(Money.new(100, 'EUR'))
62
+ @snapshot.offers << @offer1
63
+ end
64
+
65
+ it "returns nil" do
66
+ @snapshot.best_kosher_offer.should be_nil
67
+ end
68
+ end
69
+ end
70
+ end
5
71
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.10
5
+ version: 0.2.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-10 00:00:00 +00:00
13
+ date: 2011-03-16 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency