mirror of
https://github.com/we-promise/sure.git
synced 2026-04-12 08:37:22 +00:00
Add transaction modal flow (#633)
* Add transaction modal flow * Preserve decimals when creating transactions
This commit is contained in:
@@ -16,6 +16,12 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "prefills account_id if provided" do
|
||||
get new_transaction_url(account_id: @transaction.account_id)
|
||||
assert_response :success
|
||||
assert_select "option[selected][value='#{@transaction.account_id}']"
|
||||
end
|
||||
|
||||
test "should create transaction" do
|
||||
name = "transaction_name"
|
||||
assert_difference("Transaction.count") do
|
||||
@@ -25,6 +31,51 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to transactions_url
|
||||
end
|
||||
|
||||
test "creation preserves decimals" do
|
||||
assert_difference("Transaction.count") do
|
||||
post transactions_url, params: { transaction: {
|
||||
nature: "expense",
|
||||
account_id: @transaction.account_id,
|
||||
amount: 123.45,
|
||||
currency: @transaction.currency,
|
||||
date: @transaction.date,
|
||||
name: @transaction.name } }
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal 123.45.to_d, Transaction.order(created_at: :desc).first.amount
|
||||
end
|
||||
|
||||
test "expenses are positive" do
|
||||
assert_difference("Transaction.count") do
|
||||
post transactions_url, params: { transaction: {
|
||||
nature: "expense",
|
||||
account_id: @transaction.account_id,
|
||||
amount: @transaction.amount,
|
||||
currency: @transaction.currency,
|
||||
date: @transaction.date,
|
||||
name: @transaction.name } }
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert Transaction.order(created_at: :desc).first.amount.positive?, "Amount should be positive"
|
||||
end
|
||||
|
||||
test "incomes are negative" do
|
||||
assert_difference("Transaction.count") do
|
||||
post transactions_url, params: { transaction: {
|
||||
nature: "income",
|
||||
account_id: @transaction.account_id,
|
||||
amount: @transaction.amount,
|
||||
currency: @transaction.currency,
|
||||
date: @transaction.date,
|
||||
name: @transaction.name } }
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert Transaction.order(created_at: :desc).first.amount.negative?, "Amount should be negative"
|
||||
end
|
||||
|
||||
test "should show transaction" do
|
||||
get transaction_url(@transaction)
|
||||
assert_response :success
|
||||
|
||||
Reference in New Issue
Block a user