allow euros and cents in transaction params
This commit is contained in:
parent
661728772f
commit
44e83e2aba
|
@ -34,12 +34,14 @@ class TransactionsController < ApplicationController
|
|||
|
||||
def transaction_params
|
||||
t = params.require(:transaction)
|
||||
.permit(:debtor, :creditor, :amount, :message)
|
||||
.permit(:debtor, :creditor, :message, :euros, :cents)
|
||||
|
||||
t.update({
|
||||
{
|
||||
debtor: User.find_by(name: t[:debtor]) || User.zeus,
|
||||
creditor: User.find_by(name: t[:creditor]) || User.zeus,
|
||||
issuer: current_client || current_user
|
||||
})
|
||||
issuer: current_client || current_user,
|
||||
amount: (t[:euros].to_f*100 + t[:cents].to_f).to_i,
|
||||
message: t[:message]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ RSpec.describe TransactionsController, type: :controller do
|
|||
@attributes = { transaction: {
|
||||
debtor: @debtor.name,
|
||||
creditor: @creditor.name,
|
||||
amount: 20,
|
||||
cents: 70,
|
||||
message: 'hoi'
|
||||
}}
|
||||
post :create, @attributes
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe TransactionsController, type: :controller do
|
|||
end
|
||||
|
||||
it "should set amount" do
|
||||
expect(@transaction.amount).to eq(20)
|
||||
expect(@transaction.amount).to eq(70)
|
||||
end
|
||||
|
||||
it "should set creditor" do
|
||||
|
@ -42,10 +42,22 @@ RSpec.describe TransactionsController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context "with float euros" do
|
||||
it "should set correct amount" do
|
||||
post :create, transaction: {
|
||||
debtor: @debtor.name,
|
||||
creditor: @creditor.name,
|
||||
euros: 10.5,
|
||||
message: "Omdat je een leuke jongen bent!"
|
||||
}
|
||||
expect(Transaction.last.amount).to eq(1050)
|
||||
end
|
||||
end
|
||||
|
||||
context "with negative amount" do
|
||||
it "should be refused" do
|
||||
expect do
|
||||
post :create, transaction: attributes_for(:transaction, amount: -20)
|
||||
post :create, transaction: attributes_for(:transaction, cents: -20)
|
||||
end.not_to change {Transaction.count}
|
||||
end
|
||||
end
|
||||
|
@ -54,9 +66,9 @@ RSpec.describe TransactionsController, type: :controller do
|
|||
it "should be refused" do
|
||||
expect do
|
||||
post :create, transaction: {
|
||||
debtor: @creditor,
|
||||
creditor: @debtor,
|
||||
amount: 10000000000000,
|
||||
debtor: @creditor.name,
|
||||
creditor: @debtor.name,
|
||||
euros: 10000000000000,
|
||||
message: 'DIT IS OVERVAL'
|
||||
}
|
||||
end.not_to change {Transaction.count}
|
||||
|
|
Loading…
Reference in New Issue