Sha256: 689f0601e49f7da48bdc9db793b46454fb3dc0af62e46c8c0225e5f4926b2a32

Contents?: true

Size: 1.92 KB

Versions: 8

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

class MovieSpec < MiniTest::Spec
  describe Movie do
    describe "before_destroy filters" do
      before :each do
        Recommendable.redis.flushdb

        @user1 = Factory(:user)

        @movie1 = Factory(:movie)
        @movie2 = Factory(:movie)
      end

      it "should be removed from scores" do
        @user1.like @movie1
        @user1.like @movie2

        @movie2.destroy

        Movie.top(2).wont_include @movie2
      end

      it "should be removed from recommendations" do
        @user2 = Factory(:user)
        @user1.like @movie1
        @user2.like @movie1
        @user2.like @movie2

        @user1.send :update_recommendations
        @movie2.destroy

        @user2.liked.size.must_equal 1
        @user1.recommendations.size.must_equal 0
      end
    end

    describe ".top" do
      before :each do
        Recommendable.redis.flushdb

        @user1 = Factory(:user)
        @user2 = Factory(:user)
        @user3 = Factory(:user)
        @user4 = Factory(:user)
        @user5 = Factory(:user)

        @movie1 = Factory(:movie)
        @movie2 = Factory(:movie)
        @movie3 = Factory(:movie)
        @movie4 = Factory(:movie)
        @movie5 = Factory(:movie)
      end

      it "should sort movies accordingly" do
        movies = Movie.all

        movies.each { |m| @user1.like m }
        movies.pop
        movies.each { |m| @user2.like m }
        movies.pop
        movies.each { |m| @user3.like m }
        movies.pop
        movies.each { |m| @user4.dislike m }

        @user5.dislike @movie1
        @user5.dislike @movie2
        @user5.dislike @movie3
        @user5.like @movie4
        @user5.like @movie5

        top_movies = Movie.top(5)

        top_movies[0].must_equal @movie4
        top_movies[1].must_equal @movie5
        top_movies[2].must_equal @movie3
        top_movies[3].must_equal @movie2
        top_movies[4].must_equal @movie1
      end
    end    
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
recommendable-1.1.7 spec/models/movie_spec.rb
recommendable-1.1.6 spec/models/movie_spec.rb
recommendable-1.1.5 spec/models/movie_spec.rb
recommendable-1.1.4 spec/models/movie_spec.rb
recommendable-1.1.3 spec/models/movie_spec.rb
recommendable-1.1.2 spec/models/movie_spec.rb
recommendable-1.1.1 spec/models/movie_spec.rb
recommendable-1.0.0 spec/models/movie_spec.rb