require 'rails_helper'

RSpec.describe 'Candidate offer application' do
  let(:candidate) { FactoryGirl.create(:candidate) }
  let!(:offer) { FactoryGirl.create(:offer, :published) }

  before do
    login_as(candidate, scope: :candidate)
    visit jobs_abroad_path
  end

  describe 'applying for offer through application form' do
    it "creates an Application" do
      expect(page).to have_selector(dom_id(offer))
      click_link offer.title
      expect(current_path).to eq(offer_path(offer))
      click_link_or_button I18n.t('offers.apply_now')
      expect(current_path).to eq(new_offer_application_path(offer_id: offer))
      find('#application_memo').set('Zażółć gęślą jaźń')
      expect { submit_form }.to change { Application.count }

      expect(ActionMailer::Base.deliveries).not_to be_empty
    end
  end
end

require 'rails_helper'

RSpec.describe 'Candidate offer application' do
  let(:candidate) { FactoryGirl.create(:candidate) }
  let!(:offer) { FactoryGirl.create(:offer, :published) }

  describe 'applying for offer through application form' do
    before do
      login_as(candidate, scope: :candidate)
      visit jobs_abroad_path
    end

    it "creates an Application" do
      expect(page).to have_selector(dom_id(offer))
      click_link offer.title
      expect(current_path).to eq(offer_path(offer))
      click_link_or_button I18n.t('offers.apply_now')
      expect(current_path).to eq(new_offer_application_path(offer_id: offer))
      find('#application_memo').set('Zażółć gęślą jaźń')
      expect { submit_form }.to change { Application.count }

      expect(ActionMailer::Base.deliveries).not_to be_empty
    end
  end

  context "when Candidate has no CandidateProfile" do
    let(:no_profile_candidate) { FactoryGirl.create(:candidate, :only_login_credentials) }

    before do
      login_as(no_profile_candidate, scope: :candidate)
      visit new_offer_application_path(offer)
    end

    it "redirects to edit_candidate_profile_path" do
      expect(current_path).to eq(edit_candidate_profile_path)
    end

    it "displays an alert callout" do
      expect(page).to have_selector('.alert')
    end
  end
end

Fix specs for candidate offer application
Fix specs for candidate offer application

A Candidate should not be able to post an offer application without a
filled out profile, as this causes a fatal error when sending the
application via e-mail to the employer.
[ad69651] added a redirect to prevent application when the profile is
not present. This commit adds working specs for this behavior.
