<commit_before># Encoding: utf-8

require 'spec_helper'
require 'qless/job'

module Qless
  describe Job do
    class JobClass
      class Nested
      end
    end

    module SomeJobMiddleware
      def around_perform(job)
        super
      end
    end

    let(:client) { double('client').as_null_object }

    describe '.build' do
      it 'creates a job instance' do
        Job.build(client, JobClass).should be_a(Job)
      end

      it 'honors attributes passed as a symbol' do
        job = Job.build(client, JobClass, data: { 'a' => 5 })
        job.data.should eq('a' => 5)
      end

      it 'round-trips data through JSON to mimic real jobs' do
        time = Time.new(2012, 5, 3, 12, 30)
        job = Job.build(client, JobClass, data: { a: 5, timestamp: time })
        job.data.keys.should =~ %w[ a timestamp ]
        job.data['timestamp'].should be_a(String)
        job.data['timestamp'].should include('2012-05-03')
      end
    end

    describe '.build_opts_array' do
      it 'should return a correctly built array' do
        # [data, delay, priority, priority_value, tags, tags_value, retries, retries_value, depends, depends_value,
        #  throttles, throttles_value]
        expected = ["{}", 0, "priority", 0, "tags", "[]", "retries", 5, "depends", "[]", "throttles", "[]"]
        job = Job.build(client, JobClass)
        expect(Job.build_opts_array(job.enqueue_opts)).to eq(expected)
      end
    end

    describe '.enqueue_opts' do
      it 'return available fields for enqueuing the job' do
        job = Job.build(client, JobClass)
        opts = job.enqueue_opts
        [:data, :priority, :tags, :retries, :depends, :throttles].each do |k|
          expect(opts.has_key?(k)).to(be(true))
        end
      end
    end

    describe '#klass' do
      it 'returns the class constant' do
        job = Job.build(client, JobClass, data: {})
        expect(job.klass).to be(JobClass)
      end

      it 'raises a useful error when the class constant is not loaded' do
        stub_const('MyJobClass', Class.new)
        job = Job.build(client, ::MyJobClass, data: {})
        hide_const('MyJobClass')<commit_msg>strong test<commit_after># Encoding: utf-8

require 'spec_helper'
require 'qless/job'

module Qless
  describe Job do
    class JobClass
      class Nested
      end
    end

    module SomeJobMiddleware
      def around_perform(job)
        super
      end
    end

    let(:client) { double('client').as_null_object }

    describe '.build' do
      it 'creates a job instance' do
        Job.build(client, JobClass).should be_a(Job)
      end

      it 'honors attributes passed as a symbol' do
        job = Job.build(client, JobClass, data: { 'a' => 5 })
        job.data.should eq('a' => 5)
      end

      it 'round-trips data through JSON to mimic real jobs' do
        time = Time.new(2012, 5, 3, 12, 30)
        job = Job.build(client, JobClass, data: { a: 5, timestamp: time })
        job.data.keys.should =~ %w[ a timestamp ]
        job.data['timestamp'].should be_a(String)
        job.data['timestamp'].should include('2012-05-03')
      end
    end

    describe '.build_opts_array' do
      it 'should return a correctly built array' do
        # [data, delay, priority, priority_value, tags, tags_value, retries, retries_value, depends, depends_value,
        #  throttles, throttles_value]
        expected = ["{}", 0, "priority", 0, "tags", "[]", "retries", 5, "depends", "[]", "throttles", "[]"]
        job = Job.build(client, JobClass)
        expect(Job.build_opts_array(job.enqueue_opts)).to eq(expected)
      end
    end

    describe '.enqueue_opts' do
      it 'return available fields for enqueuing the job' do
        expected_fields = [:data, :priority, :tags, :retries, :depends, :throttles]
        job = Job.build(client, JobClass)
        opts = job.enqueue_opts
        expected_fields.each do |k|
          expect(opts.has_key?(k)).to(be(true))
        end

        expect(opts.keys.length).to(equal(expected_fields.length))
      end
    end

    describe '#klass' do
      it 'returns the class constant' do
        job = Job.build(client, JobClass, data: {})
        expect(job.klass).to be(JobClass)
      end

      it 'raises a useful error when the class constant is not loaded' do
        stub_const('MyJobClass', Class.new)
        job = Job.build(client, ::MyJobClass, data: {})
        hide_const('MyJobClass')
{'fraction_non_alphanumeric': 0.12256456728590848, 'fraction_numerical': 0.011327594019030359, 'mean_word_length': 2.501189532117367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '621231', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1388, 'n_words': 395}