Sha256: 2f43e334eb4b6bc5054273e49b7b249b173ecfd4889e36aa9f666b31f82ffbaa
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
require 'spec_helper' describe SeemsRateable::Rating do let(:rated_rateable) { FactoryGirl.create(:post) } let(:unrated_rateable) { FactoryGirl.create(:post) } let(:stars) { [1, 5, 4, 3, 5] } let(:rates) { rated_rateable.rates } let(:no_rates) { unrated_rateable.rates } before do stars.each do |value| FactoryGirl.create(:rate, stars: value, rateable: rated_rateable) end end def rating(rates) SeemsRateable::Rating.new(rates) end subject { rating(rates) } describe "#rates" do subject { super().rates } it { should be_a(ActiveRecord::Relation) } its(:model) { should equal(SeemsRateable::Rate) } end describe "#stars" do it "plucks rates for stars" do subject.rates.should_receive(:pluck).with(:stars) subject.stars end end describe "#count" do it "returns length of the plucked stars array" do subject.stars.should_receive(:length) subject.count end end describe "#sum" do it "sums the plucked stars array" do subject.stars.should_receive(:inject).with(:+) subject.sum end end describe "average" do context "with any rates" do it "divides the sum by the length of stars" do sum = subject.sum count = subject.count subject.average.should == sum/count end end context "without any rate" do subject { rating(no_rates) } it "returns zero" do subject.average.should == 0 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
seems_rateable-2.0.0 | spec/rating_spec.rb |