Created
May 16, 2013 11:42
-
-
Save guipdutra/5591148 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
# encoding: utf-8 | |
require 'spec_helper' | |
describe MovementsFilter do | |
let(:descriptor) { Descriptor.make!(:detran_2012) } | |
let(:management_unit) { ManagementUnit.make!(:unidade_central) } | |
let(:accounting_account) { AccountingAccount.make!(:with_bank_account, :title => "Credito") } | |
before do | |
Timecop.travel(Date.new(2012, 10, 10)) | |
FactoryGirl.create(:accountancy_movement, | |
:accountable => Pledge.make!(:empenho, | |
:amount => 100.00, | |
:descriptor => descriptor, | |
:emission_date => Date.new(2012, 10, 10), | |
:management_unit => management_unit | |
), | |
:accounting_account => accounting_account, | |
:amount => 100.0, | |
:date => Date.new(2012, 10, 10), | |
:descriptor => descriptor, | |
:movement_type => AccountancyMovementType::CREDIT | |
) | |
FactoryGirl.create(:accountancy_movement, | |
:accountable => Pledge.make!(:empenho, | |
:amount => 100.00, | |
:descriptor => descriptor, | |
:emission_date => Date.new(2012, 10, 10), | |
:management_unit => management_unit | |
), | |
:accounting_account => accounting_account, | |
:amount => 100.0, | |
:date => Date.new(2012, 10, 10), | |
:descriptor => descriptor, | |
:movement_type => AccountancyMovementType::CREDIT | |
) | |
Pledge.make!(:empenho, | |
:descriptor => descriptor, | |
:emission_date => Date.new(2012, 10, 10), | |
:management_unit => management_unit | |
) | |
FactoryGirl.create(:accountancy_movement, | |
:accountable => Pledge.make!(:empenho, | |
:amount => 100.00, | |
:descriptor => descriptor, | |
:emission_date => Date.new(2012, 10, 11), | |
:management_unit => management_unit | |
), | |
:accounting_account => accounting_account, | |
:amount => 100.0, | |
:date => Date.new(2012, 10, 11), | |
:descriptor => descriptor, | |
:movement_type => AccountancyMovementType::CREDIT | |
) | |
Pledge.make!(:empenho, | |
:amount => 100.00, | |
:descriptor => descriptor, | |
:emission_date => Date.new(2012, 10, 12), | |
:management_unit => management_unit | |
) | |
descriptor.update_attribute(:period, Date.new(2012, 11, 1)) | |
FactoryGirl.create(:accountancy_movement, | |
:accountable => Pledge.make!(:empenho, | |
:amount => 100.00, | |
:descriptor => descriptor, | |
:emission_date => Date.new(2012, 11, 10), | |
:management_unit => management_unit | |
), | |
:accounting_account => accounting_account, | |
:amount => 100.0, | |
:date => Date.new(2012, 11, 10), | |
:descriptor => descriptor, | |
:movement_type => AccountancyMovementType::CREDIT | |
) | |
end | |
after do | |
Timecop.return | |
end | |
it "returns movements for current month" do | |
expect(described_class.new(:descriptor => descriptor).filter).to eq [ | |
{:date => Date.new(2012, 10, 10), :movements => 2, :pendings => 3}, | |
{:date => Date.new(2012, 10, 11), :movements => 1, :pendings => 1}, | |
{:date => Date.new(2012, 10, 12), :movements => 0, :pendings => 1} | |
] | |
end | |
it "returns movements for specified year/month" do | |
movements = described_class.new(:descriptor => descriptor, | |
:month => Month::NOVEMBER, | |
:year => 2012).filter | |
expect(movements).to eq [{:date => Date.new(2012, 11, 10), :movements => 1, :pendings => 1}] | |
end | |
it "doesnt returns movements with movements and pendings equals to zero" do | |
movements = described_class.new(:descriptor => descriptor).filter | |
expect(movements).to_not include({:date => Date.new(2012, 10, 10), :movements => 0, :pendings => 0}) | |
end | |
it "returns empty array if no movements found on month/year" do | |
movements = described_class.new(:descriptor => descriptor, | |
:month => Month::DECEMBER, | |
:year => 2012).filter | |
expect(movements).to eq [] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment