Sha256: 0b87ae683466b1efd75596c17d07b6b4952c07c927f1dc0d3c04b462664837c0

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'
describe Likeable::Like do
  before do
    @time = Time.now
    @user = User.new
  end
  describe 'attributes' do
    it 'stores target, user, and created_at' do
      like = Likeable::Like.new(:target => @target, :user => @user, :time => @time)
      like.user.should        eq(@user)
      like.target.should      eq(@target)
      # Times often fail equality checks due to microsec precision
      like.created_at.should  be_within(1).of(@time)
    end

    it 'converts float time to propper Time object' do
      like = Likeable::Like.new(:time => @time.to_f)
      like.created_at.should be_within(1).of(@time)
    end
  end
  describe "#user" do
    it "returns like_user if available" do
      like = Likeable::Like.new(:target => @target, :user => @user, :time => @time)
      like.user.should == @user
    end
    it "finds the user in the Likeable::user_model if the like was initialized without a user" do
      like = Likeable::Like.new(:target => @target, :user => nil, :user_id => 100, :time => @time)
      Account = stub()
      Likeable.stub(:user_class).and_return(Account)
      Likeable.should_receive(:find_one).with(Account, 100)
      like.user
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
likeable-0.1.2 spec/likeable/like_spec.rb