Skip to content

Commit

Permalink
We want the best offer not the worst offer!
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Apr 28, 2012
1 parent a2da949 commit c356add
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/octopart/part.rb
Expand Up @@ -129,7 +129,7 @@ def best_offer(quantity = 1)
p = offer.prices.select { |p| p[0] <= quantity }.last
prices << { sku: offer.sku, price: p[1] } if p
end
best = prices.max_by { |p| p[:price] }
best = prices.min_by { |p| p[:price] }
offers.find { |offer| offer.sku == best[:sku] }
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion spec/lib/part_spec.rb
Expand Up @@ -96,7 +96,14 @@
use_vcr_cassette
subject { described_class.find(39619421).best_offer.sku }

it { should eq('1693062') }
it { should eq('H466A') }
end

context "for a quantity of 100" do
use_vcr_cassette
subject { described_class.find(39619421).best_offer.sku }

it { should eq('H466A') }
end
end
end

0 comments on commit c356add

Please sign in to comment.