spec/batch_spec.rb in ach_builder-0.0.2 vs spec/batch_spec.rb in ach_builder-0.2.1
- old
+ new
@@ -1,26 +1,40 @@
require 'spec_helper'
describe ACH::Batch do
before(:each) do
@batch = ACH::Batch.new
- @file = ACH.sample_file
+ @file = ACH::FileFactory.sample_file
end
- it "should create entry with attributes" do
+ it "should create entry with attributes in hash form" do
entry = @batch.entry :amount => 100
- entry.should be_instance_of(ACH::Entry)
+ entry.should be_instance_of(ACH::Record::Entry)
entry.amount.should == 100
end
- it "should create entry with attributes" do
+ it "should create entry with attributes in block form" do
entry = @batch.entry do
amount 100
end
entry.amount.should == 100
end
+ it "should raise error when adding addenda records without any entry" do
+ batch = ACH::Batch.new
+ expect{ batch.addenda(:payment_related_info =>'foo bar') }.to raise_error(ACH::Component::HasManyAssociation::NoLinkError)
+ end
+
+ it "should append addenda records after entry records" do
+ batch = ACH::Batch.new
+ 3.times do |i|
+ batch.entry(:amount => 100)
+ i.times{ batch.addenda(:payment_related_info => 'foo bar') }
+ end
+ batch.to_ach.map(&:class)[1...-1].should == [ACH::Record::Entry, ACH::Record::Entry, ACH::Record::Addenda, ACH::Record::Entry, ACH::Record::Addenda, ACH::Record::Addenda]
+ end
+
it "should return false for has_credit? and has_debit? for empty entries" do
@batch.has_credit?.should be_false
@batch.has_debit?.should be_false
end
@@ -48,14 +62,12 @@
@batch.entry :amount => 100
@batch.entry :amount => 100, :transaction_code => 21
@batch.header.service_class_code.should == 200
end
- it "should have header record with length of 94" do
- @file.batch(0).header.to_s!.length.should == ACH::Constants::RECORD_SIZE
+ it "should have header and control record with length of 94" do
+ [:header, :control].each do |record|
+ @file.batches[0].send(record).to_s!.length.should == ACH::Constants::RECORD_SIZE
+ end
end
-
- it "should have control record with length of 94" do
- @file.batch(0).send(:before_header) # to fill service_class_code value
- @file.batch(0).control.to_s!.length.should == ACH::Constants::RECORD_SIZE
- end
+
end