Sha256: 3692bfcaf5c10caa00934bead9af22ace9cf2ec6a83c6721da8e4df6b70bd1cc

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Que::Web::Helpers do
  let(:search) { '' }
  let(:params) { { 'search' => search } }

  subject do
    # Capture the params into an ivar so the params method block below captures it
    params_to_use = params

    Class.new do
      include Que::Web::Helpers

      define_method(:params) { params_to_use }
    end.new
  end

  def error_job(last_error)
    Que::Web::Viewmodels::Job.new(last_error_message: last_error)
  end

  describe '#format_error' do
    it 'returns the truncated first line of the last error' do
      message = 'This is a really long exception message that should get truncated'
      last_error = ([message] + caller).join("\n")
      _(subject.format_error(
        error_job(last_error)
      )).must_equal 'This is a really long exception...'
    end

    it 'handles empty strings as the last error' do
      _(subject.format_error(error_job(''))).must_equal ''
    end
  end

  describe '#search_running' do
    let(:jobs) do
      [
        { job_class: 'JobClassA' },
        { job_class: 'JobClassB' },
        { job_class: 'JobClassA2' },
        { job_class: 'JobClassC' }
      ]
    end

    describe 'when the search param is not supplied' do
      let(:params) { {} }

      it 'returns all the jobs' do
        _(subject.search_running(jobs)).must_equal(jobs)
      end
    end

    describe 'when the search param is blank' do
      let(:search) { '' }

      it 'returns all the jobs' do
        _(subject.search_running(jobs)).must_equal(jobs)
      end
    end

    describe 'when the search param is present' do
      let(:search) { 'A' }

      it 'returns only the jobs whose class matches the search' do
        _(subject.search_running(jobs)).must_equal(
          [
            { job_class: 'JobClassA' },
            { job_class: 'JobClassA2' }
          ]
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
que-web-0.10.0 spec/web_spec.rb
que-web-0.9.4 spec/web_spec.rb
que-web-0.9.3 spec/web_spec.rb
que-web-0.9.2 spec/web_spec.rb
que-web-0.9.1 spec/web_spec.rb
que-web-0.9.0 spec/web_spec.rb