require 'rails_helper'

RSpec.describe Ppa::FuncoesController, type: :controller do
	sign_in_admin
	set_ppa_id_na_sessao
	# This should return the minimal set of attributes required to create a valid
	# Ppa::Funcao. As you add validations to Ppa::Funcao, be sure to
	# adjust the attributes here as well.
	let(:valid_attributes) {
		FactoryBot.attributes_for( :funcao_educacao, :ppa_2014 )
	}

	let(:invalid_attributes) {
		{ nome: '' }
	}

	# This should return the minimal set of values that should be in the session
	# in order to pass any filters (e.g. authentication) defined in
	# Ppa::FuncoesController. Be sure to keep this updated too.
	let(:valid_session) { {} }

	it{ is_expected.to use_before_action(:verifica_se_tem_ppa_na_sessao!) }

	describe "GET #index" do
		it "retorna apenas as funções do ppa atual da sessão" do
			ppa = Ppa::Ppa.first
			funcao_2010 = FactoryBot.create(:funcao_educacao, :ppa_2010 )
			allow( controller ).to receive( :ppa_atual ).and_return( ppa )
			get :index
			expect( assigns[:ppa_funcoes]).to eq( ppa.funcoes )
			expect( assigns[:ppa_funcoes]).to_not include( funcao_2010 )
		end
	end

	describe "GET #show" do
		it "assigns the requested ppa_funcao as @ppa_funcao" do
			funcao = Ppa::Funcao.create! valid_attributes
			get :show, params: {:id => funcao.to_param}, valid_session
			expect(assigns(:ppa_funcao)).to eq(funcao)
		end
	end
end
