-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "../../spec_helper" | ||
|
||
private class SaveTransaction < Transaction::SaveOperation | ||
permit_columns :reference | ||
|
||
include Bill::UpdateDirectReceipt | ||
end | ||
|
||
describe Bill::UpdateDirectReceipt do | ||
it "updates receipt transaction" do | ||
user = UserFactory.create | ||
|
||
transaction = TransactionFactory.create &.user_id(user.id) | ||
.amount(-20) | ||
.description("Awesome transaction") | ||
.status(:draft) | ||
.type(:receipt) | ||
|
||
new_user = UserFactory.create &.email("some@one.now") | ||
new_description = "Another transaction" | ||
new_amount = 45 | ||
new_status = TransactionStatus.new(:open) | ||
|
||
SaveTransaction.update(transaction, params( | ||
user_id: new_user.id, | ||
amount: new_amount, | ||
credit: false, | ||
description: new_description, | ||
status: new_status, | ||
type: :invoice | ||
)) do |operation, updated_transaction| | ||
operation.saved?.should be_true | ||
|
||
updated_transaction.amount.should eq(-new_amount) | ||
updated_transaction.description.should eq(new_description) | ||
updated_transaction.status.should eq(new_status) | ||
updated_transaction.type.should eq(TransactionType.new(:receipt)) | ||
updated_transaction.user_id.should eq(new_user.id) | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Receives payment without creating a `Receipt` record | ||
module Bill::UpdateDirectReceipt | ||
macro included | ||
before_save do | ||
set_type | ||
set_credit | ||
end | ||
|
||
include Bill::UpdateTransaction | ||
|
||
private def set_type | ||
type.value = TransactionType.new(:receipt) | ||
end | ||
|
||
private def set_credit | ||
credit.value = true | ||
end | ||
end | ||
end |
This file contains 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