<commit_before>require 'spec_helper'
require 'active_record'

ActiveRecord::Base.establish_connection(QUE_URL)
Que.connection = ActiveRecord
QUE_ADAPTERS[:active_record] = Que.adapter

describe "Que using the ActiveRecord adapter" do
  before { Que.adapter = QUE_ADAPTERS[:active_record] }

  it_behaves_like "a Que adapter"
  it_behaves_like "a multithreaded Que adapter"

  it "should use the same connection that ActiveRecord does" do
    class ActiveRecordJob < Que::Job
      def run
        $pid1 = Que.execute("SELECT pg_backend_pid()").first['pg_backend_pid'].to_i
        $pid2 = ActiveRecord::Base.connection.select_all("select pg_backend_pid()").rows.first.first.to_i
      end
    end

    ActiveRecordJob.queue
    Que::Job.work

    $pid1.should == $pid2
  end

  it "should instantiate args as ActiveSupport::HashWithIndifferentAccess" do
    class HWIAJob < Que::Job
      def run(args)
        $passed_args = args
      end
    end

    $passed_args = nil
    HWIAJob.queue :param => 2
    Que::Job.work
    $passed_args[:param].should == 2
    $passed_args.should be_an_instance_of ActiveSupport::HashWithIndifferentAccess
  end
end<commit_msg>Minor spec cleanup.<commit_after>require 'spec_helper'
require 'active_record'

ActiveRecord::Base.establish_connection(QUE_URL)
Que.connection = ActiveRecord
QUE_ADAPTERS[:active_record] = Que.adapter

describe "Que using the ActiveRecord adapter" do
  before { Que.adapter = QUE_ADAPTERS[:active_record] }

  it_behaves_like "a Que adapter"
  it_behaves_like "a multithreaded Que adapter"

  it "should use the same connection that ActiveRecord does" do
    class ActiveRecordJob < Que::Job
      def run
        $pid1 = Que.execute("SELECT pg_backend_pid()").first['pg_backend_pid'].to_i
        $pid2 = ActiveRecord::Base.connection.select_all("select pg_backend_pid()").rows.first.first.to_i
      end
    end

    ActiveRecordJob.queue
    Que::Job.work

    $pid1.should == $pid2
  end

  it "should instantiate args as ActiveSupport::HashWithIndifferentAccess" do
    ArgsJob.queue :param => 2
    Que::Job.work
    $passed_args.first[:param].should == 2
    $passed_args.first.should be_an_instance_of ActiveSupport::HashWithIndifferentAccess
  end
end
{'fraction_non_alphanumeric': 0.09446693657219973, 'fraction_numerical': 0.005398110661268556, 'mean_word_length': 4.1600928074245935, 'pattern_counts': {'":': 0, '<': 6, '<?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': '7302263', 'n_tokens_mistral': 725, 'n_tokens_neox': 689, 'n_words': 160}