Sha256: ee148870cb79eb007bd1d5a1f9360af4007010640571acb6db089c28429e50a9

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

class LikeSpec < MiniTest::Spec
  describe Recommendable::Like do
    before :each do
      @user = User.create(:username => "dave")
    end
    
    it "should not be created for an object that does not act_as_recommendedable" do
      cake = PhpFramework.create(:name => "CakePHP")
      proc { @user.like(cake) }.must_raise Recommendable::UnrecommendableError
    end
    
    it "should be created for an object that does act_as_recommendable" do
      movie = Movie.create(:title => "2001: A Space Odyssey", :year => 1968)
      
      @user.like(movie).must_equal true
    end
    
    it "should not be created twice for the same user-object pair" do
      movie = Movie.create(:title => "2001: A Space Odyssey", :year => 1968)
      
      @user.like(movie).must_equal true
      @user.like(movie).must_be_nil
      Recommendable::Like.count.must_equal 1
    end

    it "should cache the number of likes" do
      movie = Movie.create(:title => "2001: A Space Odyssey", :year => 1968)
      @user2 = User.create(:username => "frank")

      @user.like(movie)
      movie.like_count.must_equal 1

      @user2.like(movie)
      movie.like_count.must_equal 2

      @user.unlike(movie)
      movie.like_count.must_equal 1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
recommendable-1.1.7 spec/models/like_spec.rb
recommendable-1.1.6 spec/models/like_spec.rb
recommendable-1.1.5 spec/models/like_spec.rb
recommendable-1.1.4 spec/models/like_spec.rb