Permalink
Browse files

should not explode if trying to get recommendations for a non-existin…

…g item
  • Loading branch information...
1 parent f0bbe9a commit 57f38137694f10bc5acaf2a6e8b86e989e45fc6e @egze committed Feb 25, 2012
Showing with 6 additions and 0 deletions.
  1. +1 −0 lib/recommendify/similarity_matrix.rb
  2. +5 −0 spec/base_spec.rb
@@ -44,6 +44,7 @@ def commit_item!(item_id)
# use activesupport's orderedhash?
def retrieve_item(item_id)
data = Recommendify.redis.hget(redis_key, item_id)
+ return {} if data.nil?
Hash[data.split("|").map{ |i| (k,s=i.split(":")) && [k,s.to_f] }]
end
View
@@ -133,6 +133,11 @@
sm.similarity_matrix.should_receive(:[]).with("fnorditem").and_return({:fooitem => 0.4, :baritem => 1.5})
sm.for("fnorditem").length.should == 2
end
+
+ it "should not throw exception for non existing items" do
+ sm = Recommendify::Base.new
+ sm.for("not_existing_item").length.should == 0
+ end
it "should retrieve the n-most similar neighbors as Recommendify::Neighbor objects" do
sm = Recommendify::Base.new

1 comment on commit 57f3813

@paulasmuth

With specs -> awesome. Thanks! :)

Please sign in to comment.