<commit_before>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
  
  it 'should output all the attributes for an item for Ohm' do
    item = Fabricate.build(ActivityFeed::Ohm::Item)
    
    hash = JSON.parse(JSON.generate(item))
    hash.keys.size.should be(8)
  end
end<commit_msg>Use the to_json on the ActivityFeed::Ohm::Item object<commit_after>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
  
  it 'should output all the attributes for an item for Ohm' do
    item = Fabricate.build(ActivityFeed::Ohm::Item)
    
    hash = JSON.parse(item.to_json)
    hash.keys.size.should be(8)
  end
end
{'fraction_non_alphanumeric': 0.11229813664596273, 'fraction_numerical': 0.0084472049689441, 'mean_word_length': 3.7420494699646643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2801500', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1370, 'n_words': 287}