Permalink
Browse files

Adding Rspec tests for exportable_transaction model

  • Loading branch information...
1 parent 8747f0b commit 759cdb87aa8e2a3198a2d7638dc8a99610d11bb0 Mohamed Magdy committed Jul 15, 2014
Showing with 52 additions and 0 deletions.
  1. +52 −0 Ruby/transaction.rb
View
@@ -56,4 +56,56 @@ class ExportableTransaction < Transaction
)
.order("transactions.server_time_created_at DESC")
end
+end
+
+# Rspec tests
+describe ExportableTransaction do
+ let(:merchant) { create(:merchant, country: Country.de) }
+ let(:transactions_count) { 5 }
+ let(:paid_out_status) { TransactionStatus.where(name: TransactionStatus::PAID_OUT).first }
+ let(:transactions) do
+ transactions_count.times.map do
+ create(
+ :transaction,
+ merchant: merchant,
+ current_status_id: paid_out_status.id,
+ tx_result: Transaction::TRANSACTION_SUCCESSFUL
+ )
+ end
+ end
+
+ let(:old_transaction) do
+ create(
+ :transaction,
+ merchant: merchant,
+ current_status_id: paid_out_status.id,
+ tx_result: Transaction::TRANSACTION_SUCCESSFUL,
+ server_time_created_at: 1.month.ago
+ )
+ end
+
+ context "merchant's shortened transactions" do
+ it "returns the merchant's transactions" do
+ transactions
+
+ expect(
+ merchant.exportable_transactions.shortened.map(&:transaction_code).sort
+ ).to eq(merchant.transactions.pluck(:transaction_code).sort)
+ end
+ end
+
+ context "total amount per time" do
+ it "returns the total amout in a specific time frame" do
+ transactions
+ old_transaction
+
+ expect(
+ merchant.exportable_transactions.total_amount(1.day.ago, Time.now)
+ ).to eq(transactions.sum(&:amount).to_f)
+
+ expect(
+ merchant.exportable_transactions.total_amount(2.months.ago, 1.month.ago)
+ ).to eq(old_transaction.amount.to_f.round(2))
+ end
+ end
end

0 comments on commit 759cdb8

Please sign in to comment.