<commit_before># encoding: utf-8

require 'spec_helper'

module Adhearsion
  class PunchblockPlugin
    describe Initializer do

      def reset_default_config
        Adhearsion.config.punchblock do |config|
          config.platform           = :xmpp
          config.username           = "usera@127.0.0.1"
          config.password           = "1"
          config.host               = nil
          config.port               = nil
          config.root_domain        = nil
          config.calls_domain       = nil
          config.mixers_domain      = nil
          config.connection_timeout = 60
          config.reconnect_attempts = 1.0/0.0
          config.reconnect_timer    = 5
          config.media_engine       = nil
          config.default_voice      = nil
        end
      end

      def initialize_punchblock(options = {})
        reset_default_config
        Initializer.stub(:connect)
        Adhearsion.config.punchblock do |config|
          config.platform           = options[:platform] if options.has_key?(:platform)
          config.username           = options[:username] if options.has_key?(:username)
          config.password           = options[:password] if options.has_key?(:password)
          config.host               = options[:host] if options.has_key?(:host)
          config.port               = options[:port] if options.has_key?(:port)
          config.root_domain        = options[:root_domain] if options.has_key?(:root_domain)
          config.calls_domain       = options[:calls_domain] if options.has_key?(:calls_domain)
          config.mixers_domain      = options[:mixers_domain] if options.has_key?(:mixers_domain)
          config.connection_timeout = options[:connection_timeout] if options.has_key?(:connection_timeout)
          config.reconnect_attempts = options[:reconnect_attempts] if options.has_key?(:reconnect_attempts)
          config.reconnect_timer    = options[:reconnect_timer] if options.has_key?(:reconnect_timer)
          config.media_engine       = options[:media_engine] if options.has_key?(:media_engine)
          config.default_voice      = options[:default_voice] if options.has_key?(:default_voice)
        end

        Initializer.init
        Adhearsion.config[:punchblock]
      end

      let(:call_id)     { rand }
      let(:offer)       { Punchblock::Event::Offer.new :target_call_id => call_id }
      let(:mock_call)   { Call.new }
      let(:mock_client) { mock 'Client' }

      before do
        mock_call.stub :id => call_id
        mock_client.stub :event_handler= => true
        Events.refresh!
        Adhearsion::Process.stub :fqdn => 'hostname'
        ::Process.stub :pid => 1234
      end

      describe "starts the client with the default values" do
        subject { initialize_punchblock }

        it "should set properly the username value" do
          subject.username.should be == 'usera@127.0.0.1'
        end

        it "should set properly the password value" do
          subject.password.should be == '1'
        end

        it "should set properly the host value" do
          subject.host.should be_nil
        end

        it "should set properly the port value" do
          subject.port.should be_nil<commit_msg>[BUGFIX] Don't allow PB plugin specs to fail on irrelevant points<commit_after># encoding: utf-8

require 'spec_helper'

module Adhearsion
  class PunchblockPlugin
    describe Initializer do

      def reset_default_config
        Adhearsion.config.punchblock do |config|
          config.platform           = :xmpp
          config.username           = "usera@127.0.0.1"
          config.password           = "1"
          config.host               = nil
          config.port               = nil
          config.root_domain        = nil
          config.calls_domain       = nil
          config.mixers_domain      = nil
          config.connection_timeout = 60
          config.reconnect_attempts = 1.0/0.0
          config.reconnect_timer    = 5
          config.media_engine       = nil
          config.default_voice      = nil
        end
      end

      def initialize_punchblock(options = {})
        reset_default_config
        Initializer.stub(:connect)
        Adhearsion.config.punchblock do |config|
          config.platform           = options[:platform] if options.has_key?(:platform)
          config.username           = options[:username] if options.has_key?(:username)
          config.password           = options[:password] if options.has_key?(:password)
          config.host               = options[:host] if options.has_key?(:host)
          config.port               = options[:port] if options.has_key?(:port)
          config.root_domain        = options[:root_domain] if options.has_key?(:root_domain)
          config.calls_domain       = options[:calls_domain] if options.has_key?(:calls_domain)
          config.mixers_domain      = options[:mixers_domain] if options.has_key?(:mixers_domain)
          config.connection_timeout = options[:connection_timeout] if options.has_key?(:connection_timeout)
          config.reconnect_attempts = options[:reconnect_attempts] if options.has_key?(:reconnect_attempts)
          config.reconnect_timer    = options[:reconnect_timer] if options.has_key?(:reconnect_timer)
          config.media_engine       = options[:media_engine] if options.has_key?(:media_engine)
          config.default_voice      = options[:default_voice] if options.has_key?(:default_voice)
        end

        Initializer.init
        Adhearsion.config[:punchblock]
      end

      let(:call_id)     { rand }
      let(:offer)       { Punchblock::Event::Offer.new :target_call_id => call_id }
      let(:mock_call)   { Call.new }
      let(:mock_client) { mock 'Client' }

      before do
        mock_call.stub :id => call_id
        mock_client.as_null_object
        mock_client.stub :event_handler= => true
        Events.refresh!
        Adhearsion::Process.stub :fqdn => 'hostname'
        ::Process.stub :pid => 1234
      end

      describe "starts the client with the default values" do
        subject { initialize_punchblock }

        it "should set properly the username value" do
          subject.username.should be == 'usera@127.0.0.1'
        end

        it "should set properly the password value" do
          subject.password.should be == '1'
        end

        it "should set properly the host value" do
          subject.host.should be_nil
        end

        it "should set properly the port value" do
          subject.port.should be_nil
{'fraction_non_alphanumeric': 0.08789867236380283, 'fraction_numerical': 0.007935296810621089, 'mean_word_length': 2.0900518623290902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '131862', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1823, 'n_words': 392}