Sha256: fa45d001d2daf4ba77238153a3a2f6a16390d0e6865d888049c05abf2365079e

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Mongoid::Liker do
  describe User do
    before :all do
      @joe = User.create(name: 'Joe')
      @max = User.create(name: 'Max')
    end

    it "should have no likes" do
      [@joe, @max].each {|u| u.all_likes.should be_empty}
    end

    describe Track do
      before :all do
        @track1 = Track.create
        @track2 = Track.create
      end

      it "should have no likers" do
        [@track1, @track2].each { |t| t.all_likers.should be_empty }
      end

      it "should be likeable" do
        @joe.like(@track1)
      end

      it "should be liked by liker" do
        @track1.liker?(@joe).should be_true
      end

      it "should not be liked by others" do
        @track1.liker?(@max).should_not be_true
      end

      it "should have the liker as liker" do
        @track1.all_likers.should include @joe
      end

      it "should not have others as liker" do
        @track1.all_likers.should_not include @max
      end

      it "should be likeable by multiple likers" do
        @max.like(@track1)
      end

      it "should be liked by multiple likers" do
        @track1.all_likers.should include @joe, @max
      end

      it "should have the correct likers count" do
        @track1.likers_count.should be 2
        @max.likes_count.should be 1
        @joe.likes_count.should be 1
      end

      it "should be unlikable" do
        @max.unlike(@track1)
      end

      it "should not include former liker" do
        @track1.all_likers.should_not include @max
      end

      it "should not be included in former likes" do
        @max.all_likes.should_not include @track1
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid_likes-0.1.1 spec/mongoid/mongoid_likes/likes_spec.rb