Track expenses
This commit is contained in:
parent
7521ebaa45
commit
e588ab3db0
19 changed files with 374 additions and 0 deletions
48
test/controllers/expenses_controller_test.rb
Normal file
48
test/controllers/expenses_controller_test.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require "test_helper"
|
||||
|
||||
class ExpensesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@expense = expenses(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get expenses_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_expense_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create expense" do
|
||||
assert_difference("Expense.count") do
|
||||
post expenses_url, params: { expense: { autopaid: @expense.autopaid, description: @expense.description, estimated: @expense.estimated, payment: @expense.payment, period: @expense.period } }
|
||||
end
|
||||
|
||||
assert_redirected_to expense_url(Expense.last)
|
||||
end
|
||||
|
||||
test "should show expense" do
|
||||
get expense_url(@expense)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_expense_url(@expense)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update expense" do
|
||||
patch expense_url(@expense), params: { expense: { autopaid: @expense.autopaid, description: @expense.description, estimated: @expense.estimated, payment: @expense.payment, period: @expense.period } }
|
||||
assert_redirected_to expense_url(@expense)
|
||||
end
|
||||
|
||||
test "should destroy expense" do
|
||||
assert_difference("Expense.count", -1) do
|
||||
delete expense_url(@expense)
|
||||
end
|
||||
|
||||
assert_redirected_to expenses_url
|
||||
end
|
||||
end
|
15
test/fixtures/expenses.yml
vendored
Normal file
15
test/fixtures/expenses.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
description: MyString
|
||||
payment: 9.99
|
||||
period: 1
|
||||
autopaid: false
|
||||
estimated: false
|
||||
|
||||
two:
|
||||
description: MyString
|
||||
payment: 9.99
|
||||
period: 1
|
||||
autopaid: false
|
||||
estimated: false
|
7
test/models/expense_test.rb
Normal file
7
test/models/expense_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class ExpenseTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
49
test/system/expenses_test.rb
Normal file
49
test/system/expenses_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class ExpensesTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@expense = expenses(:one)
|
||||
end
|
||||
|
||||
test "visiting the index" do
|
||||
visit expenses_url
|
||||
assert_selector "h1", text: "Expenses"
|
||||
end
|
||||
|
||||
test "should create expense" do
|
||||
visit expenses_url
|
||||
click_on "New expense"
|
||||
|
||||
check "Autopaid" if @expense.autopaid
|
||||
fill_in "Description", with: @expense.description
|
||||
check "Estimated" if @expense.estimated
|
||||
fill_in "Payment", with: @expense.payment
|
||||
fill_in "Period", with: @expense.period
|
||||
click_on "Create Expense"
|
||||
|
||||
assert_text "Expense was successfully created"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should update Expense" do
|
||||
visit expense_url(@expense)
|
||||
click_on "Edit this expense", match: :first
|
||||
|
||||
check "Autopaid" if @expense.autopaid
|
||||
fill_in "Description", with: @expense.description
|
||||
check "Estimated" if @expense.estimated
|
||||
fill_in "Payment", with: @expense.payment
|
||||
fill_in "Period", with: @expense.period
|
||||
click_on "Update Expense"
|
||||
|
||||
assert_text "Expense was successfully updated"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should destroy Expense" do
|
||||
visit expense_url(@expense)
|
||||
click_on "Destroy this expense", match: :first
|
||||
|
||||
assert_text "Expense was successfully destroyed"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue