require "spec_helper" describe Recommendations::Item do subject {Recommendations::Item.new("1", violent: 100, romantic: 25)} describe "#initialize" do its(:id) {should == "1"} its(:categories) {should == {violent: 100, romantic: 25}} end describe "#similars" do context "when count was not specified" do let(:count) {Recommendations.configuration.similar_items_count - 1} it "gets sorted set range from similar count configuration" do Recommendations.redis.should_receive(:zrange) .with("recommendations:similars:item:1", 0, count) .and_return ["2", "3", "4"] subject.similars.should == ["2", "3", "4"] end end context "when count was specified" do it "gets sorted set range until count" do Recommendations.redis.should_receive(:zrange) .with("recommendations:similars:item:1", 0, 9) .and_return ["2", "3", "4"] subject.similars(10).should == ["2", "3", "4"] end end end end