Sha256: 6bc4eeb67336b29bcda16cd03c43e1d0cf15eb2b15c57c6a400ee8d87e808202

Contents?: true

Size: 1.63 KB

Versions: 15

Compression:

Stored size: 1.63 KB

Contents

require "rails_helper"

RSpec.describe Fe::UpdateReferenceSheetVisibilityJob, type: :job do
  it "matches with enqueued job" do
    expect {
      Fe::UpdateReferenceSheetVisibilityJob.perform_later(create(:application), [1])
    }.to have_enqueued_job(Fe::UpdateReferenceSheetVisibilityJob)
  end

  context '#perform' do
    let(:qs) { create(:question_sheet_with_pages) }
    let(:qs2) { create(:question_sheet_with_pages) }
    let(:p) { qs.pages.first }
    let(:p2) { qs.pages.first }
    let(:ref_el) { create(:reference_element) }
    let(:ref_el2) { create(:reference_element) }
    let(:ref_el3) { create(:reference_element) }
    let(:app) { create(:application) }
    let(:affecting_el) { create(:text_field_element) }

    before do
      p.elements << ref_el
      p2.elements << ref_el2
      app.question_sheets << qs << qs2
    end

    it "calls update_visible for all refs whose visibility_affecting_element_ids include the answer's question" do
      expect(app).to receive(:question_sheets_all_reference_elements).and_return([ref_el, ref_el2])
      expect(ref_el).to receive(:visibility_affecting_element_ids).and_return([affecting_el.id])
      expect(ref_el).to receive(:update_visible)
      ref_el_arr = [ref_el]
      allow(app).to receive(:all_references).and_return(ref_el_arr)
      allow(ref_el_arr).to receive(:where).with(question_id: ref_el.id).and_return(ref_el_arr)
      expect(ref_el2).to receive(:visibility_affecting_element_ids).and_return([])
      qs = Fe::QuestionSet.new([affecting_el], app)
      puts app.object_id
      Fe::UpdateReferenceSheetVisibilityJob.new.perform(app, qs.questions.collect(&:id))
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fe-2.1.6.1 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.1.6 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.1.5 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.1.4 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.1.3 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.1.2 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.1.1 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.8 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.6 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.5 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.4 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.3 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.2 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.1 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb
fe-2.0.0 spec/jobs/fe/update_reference_sheet_visibility_job_spec.rb