require 'rails_helper'

RSpec.describe Base::FuncoesController, type: :controller do
	sign_in_admin

	let(:valid_attributes) {
		FactoryBot.attributes_for( :funcao_saude )
	}

	describe "GET #index" do
		it "retorna apenas as funções do orçamento atual da sessão" do
			orcamento = FactoryBot.create(:orcamento_2016)
			allow( controller ).to receive( :orcamento_atual ).and_return( orcamento )
			resultado = Base::Funcao.where(modulo_id: orcamento.id).order(:id)
			get :index
			expect(assigns(:base_funcoes).to_json).to eq(resultado.to_json)
		end
	end

	describe "GET #show" do
		it "assigns the requested ppa_funcao as @ppa_funcao" do
			orcamento = FactoryBot.create(:orcamento_2016)
			funcao_id = orcamento.funcoes.first.id
			get :show, params: {:id => funcao_id}
			expect(assigns(:base_funcao)).to eq(orcamento.funcoes.first)
		end
	end

end