Created
June 20, 2013 20:31
-
-
Save guipdutra/5826336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'controller_helper' | |
describe BudgetRevenueDeductionsController do | |
let(:detran_2012) { Descriptor.make!(:detran_2012) } | |
let(:secretaria_educacao_2012) { Descriptor.make!(:secretaria_de_educacao_2012) } | |
let(:bank_account) { BankAccount.make!(:itau_tributos) } | |
let(:main_nature) { RevenueNature.make!(:receitas_correntes) } | |
let(:revenue_nature) { RevenueNature.make!(:receitas_correntes, :main_nature => main_nature, :prefix => "93", :kind => RevenueNatureKind::ANALYTICAL) } | |
let(:budget_revenue) { BudgetRevenue.make!(:reforma, :code => 2, :revenue_nature => revenue_nature) } | |
before do | |
controller.stub(:authenticate_user!) | |
controller.stub(:authorize_resource!) | |
controller.stub(:current_descriptor => detran_2012) | |
end | |
context 'GET #index' do | |
it "returns all the budget revenue deductions with the current descriptor" do | |
deduction_detran_2012 = FactoryGirl.create(:budget_revenue_deduction, | |
:descriptor => detran_2012, | |
:code => 1, | |
:bank_account => bank_account, | |
:budget_revenue => budget_revenue | |
) | |
deduction_secretaria_educacao_2012 = FactoryGirl.create(:budget_revenue_deduction, | |
:descriptor => secretaria_educacao_2012, | |
:code => 2, | |
:bank_account => bank_account, | |
:budget_revenue => budget_revenue | |
) | |
get :index | |
expect(assigns(:budget_revenue_deductions)).to include deduction_detran_2012 | |
expect(assigns(:budget_revenue_deductions)).to_not include deduction_secretaria_educacao_2012 | |
end | |
end | |
context 'POST #create' do | |
it "assigns the current descriptor as the budget revenue deduction's descriptor" do | |
post :create | |
expect(assigns(:budget_revenue_deduction).descriptor).to eq detran_2012 | |
end | |
it "generate a bank moviment and accountancy movements" do | |
deduction_params = { | |
:date => Date.current, | |
:bank_account_id => bank_account.id, | |
:budget_revenue_id => budget_revenue.id, | |
:amount => 100, | |
:description => "Teste", | |
:deduction_type => DeductionType::DISCOUNTS | |
} | |
BudgetRevenueDeduction.any_instance.should_receive(:save).and_return(true) | |
MovementsGenerator.any_instance.should_receive(:generate!) | |
post :create, :budget_revenue_deduction => deduction_params | |
expect(AccountMovement.count).to be_eql 1 | |
account_movement = AccountMovement.last | |
expect(account_movement.bank_account).to be_eql bank_account | |
expect(account_movement.amount).to be_eql 100 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment