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

describe InfoRequestEvent do 
    
    describe "when storing serialized parameters" do

        it "should convert event parameters into YAML and back successfully" do
            ire = InfoRequestEvent.new 
            example_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" }
            ire.params = example_params
            ire.params_yaml.should == example_params.to_yaml
            ire.params.should == example_params
        end
        
    end

    describe 'when saving' do 
  
        it 'should mark the model for reindexing in xapian if there is no no_xapian_reindex flag on the object' do
            event = InfoRequestEvent.new(:info_request => mock_model(InfoRequest), 
                                         :event_type => 'sent', 
                                         :params => {}) 
            event.should_receive(:xapian_mark_needs_index)
            event.save!
        end
    
    end

    describe "should know" do
        
        it "that it's an incoming message" do
            event = InfoRequestEvent.new(:incoming_message => mock_model(IncomingMessage))
            event.is_incoming_message?.should be_true
            event.is_outgoing_message?.should be_false
            event.is_comment?.should be_false
        end
        
        it "that it's an outgoing message" do
            event = InfoRequestEvent.new(:outgoing_message => mock_model(OutgoingMessage))
            event.is_incoming_message?.should be_false
            event.is_outgoing_message?.should be_true
            event.is_comment?.should be_false
        end
        
        it "that it's a comment" do
            event = InfoRequestEvent.new(:comment => mock_model(Comment))<commit_msg>Running the callbacks more specific than calling save! here and avoids having to handle foreign key references<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe InfoRequestEvent do

    describe "when storing serialized parameters" do

        it "should convert event parameters into YAML and back successfully" do
            ire = InfoRequestEvent.new
            example_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" }
            ire.params = example_params
            ire.params_yaml.should == example_params.to_yaml
            ire.params.should == example_params
        end

    end

    describe 'after saving' do

        it 'should mark the model for reindexing in xapian if there is no no_xapian_reindex flag on the object' do
            event = InfoRequestEvent.new(:info_request => mock_model(InfoRequest),
                                         :event_type => 'sent',
                                         :params => {})
            event.should_receive(:xapian_mark_needs_index)
            event.run_callbacks(:after_save)
        end

    end

    describe "should know" do

        it "that it's an incoming message" do
            event = InfoRequestEvent.new(:incoming_message => mock_model(IncomingMessage))
            event.is_incoming_message?.should be_true
            event.is_outgoing_message?.should be_false
            event.is_comment?.should be_false
        end

        it "that it's an outgoing message" do
            event = InfoRequestEvent.new(:outgoing_message => mock_model(OutgoingMessage))
            event.is_incoming_message?.should be_false
            event.is_outgoing_message?.should be_true
            event.is_comment?.should be_false
        end

        it "that it's a comment" do
            event = InfoRequestEvent.new(:comment => mock_model(Comment))
{'fraction_non_alphanumeric': 0.07700621453661173, 'fraction_numerical': 0.0010807889759524452, 'mean_word_length': 2.1083123425692696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5816516', 'n_tokens_mistral': 978, 'n_tokens_neox': 937, 'n_words': 259}