Sha256: 7548f4a57d81b2a7384cf0a62cde9f967b70e9d690c0bd2d1565d962b7906552

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe 'ActivityFeed::Item' do
  it 'should allow you to create a new Item' do
    item = Fabricate.build(ActivityFeed.persistence)
    item.save.should be_true
  end
  
  it 'should allow for a large amount of text' do
    item = Fabricate.build(ActivityFeed.persistence, :text => '*' * 8192)
    item.text.should eql('*' * 8192)
  end
  
  it 'should add the feed item ID to redis' do
    item = Fabricate.build(ActivityFeed.persistence)
          
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(0)
    item.save
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(1)
    ActivityFeed.aggregate_item(item)
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id, true)).should be(1)
  end
  
  it 'should have default attributes for .title .url .icon and .sticky' do
    item = Fabricate.build(ActivityFeed.persistence)
    
    item.title.should eql('item title')
    item.url.should eql('http://url')
    item.icon.should eql('http://icon')
    item.sticky.should be_false
  end
  
  it 'should not create a new item in Redis after saving, only on create' do
    item = Fabricate.build(ActivityFeed::Memory::Item)
    
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(0)
    item.save
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(1)
    ActivityFeed.aggregate_item(item)
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id, true)).should be(1)
    
    item.text = 'updated text'
    item.save
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(1)
    ActivityFeed.aggregate_item(item)
    ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id, true)).should be(1)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activity_feed-1.2 spec/item_spec.rb