-
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
1 parent
4446ace
commit 8c82b1c
Showing
7 changed files
with
174 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<div> | ||
<%= render(Forms::HeaderComponent.new(text: "Edit #{@budget.description} Budget for #{budget.month.titleize}")) %> | ||
<%= render(Forms::HeaderComponent.new(text: "Edit #{@budget.description} Budget for #{@budget.month.titleize}")) %> | ||
|
||
<%= render partial: "form", budget: @budget %> | ||
</div> |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<%= render(Forms::ShowComponent.new( | ||
header: @member.full_name, | ||
header: "#{@budget.description} Budget for #{@budget.month.titleize}", | ||
fields: [ | ||
{ label: "Birthdate", data: @member.birthdate&.strftime("%B %d, %Y") }, | ||
{ label: "Created", data: @member.created_at.to_date&.strftime("%B %d, %Y") }, | ||
{ label: "Updated", data: @member.updated_at.to_date&.strftime("%B %d, %Y") } | ||
{ label: "Cash Flow Type", data: @budget.cash_flow_type }, | ||
{ label: "Budget Category", data: @budget.category.description }, | ||
{ label: "Amount", data: @budget.amount }, | ||
{ label: "Created", data: @budget.created_at.to_date&.strftime("%B %d, %Y") }, | ||
{ label: "Updated", data: @budget.updated_at.to_date&.strftime("%B %d, %Y") } | ||
] | ||
)) | ||
%> |
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the MembersHelper. For example: | ||
# | ||
# describe MembersHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe BudgetsHelper, type: :helper do | ||
describe "#budget_month_options_for_select" do | ||
it "builds an array with 12 elements" do | ||
expect(helper.budget_month_options_for_select.is_a?(Array)).to be_truthy | ||
expect(helper.budget_month_options_for_select.size).to eq(12) | ||
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,141 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe BudgetsController, type: :request do | ||
let(:budget_category) { FactoryBot.create(:budget_category) } | ||
let(:budget) { FactoryBot.create(:budget, category: budget_category) } | ||
|
||
describe "GET /budgets" do | ||
it "returns HTTP success" do | ||
get budgets_path | ||
expect(response).to have_http_status(:success) | ||
end | ||
end | ||
|
||
describe "GET /budget/:id" do | ||
context "when the ID exists" do | ||
it "returns HTTP success" do | ||
get budget_path(budget) | ||
expect(response).to have_http_status(:success) | ||
end | ||
end | ||
|
||
context "when the ID doesn't exist" do | ||
it "returns HTTP missing" do | ||
get budget_path(id: budget.id + 10) | ||
expect(response).to have_http_status(:missing) | ||
end | ||
end | ||
end | ||
|
||
describe "GET /budget/new" do | ||
it "returns HTTP success" do | ||
get new_budget_path | ||
expect(response).to have_http_status(:success) | ||
end | ||
end | ||
|
||
describe "POST /budget" do | ||
let(:good_params) do | ||
{ | ||
budget: { | ||
month: Budget::BUDGET_MONTHS.first, | ||
description: "Paycheck", | ||
amount: 1.0, | ||
cash_flow_type: :income, | ||
budget_category_id: budget_category.id | ||
} | ||
} | ||
end | ||
|
||
let(:bad_params) do | ||
{ | ||
budget: { | ||
month: Budget::BUDGET_MONTHS.first, | ||
description: "Paycheck", | ||
amount: 1.0, | ||
cash_flow_type: :income | ||
} | ||
} | ||
end | ||
|
||
context "when the record doesn't already exist" do | ||
it "returns HTTP redirect" do | ||
post budgets_path, params: good_params | ||
expect(response).to have_http_status(:redirect) | ||
end | ||
end | ||
|
||
context "when the record is missing required fields" do | ||
it "returns HTTP unprocessible entity" do | ||
post budgets_path, params: bad_params | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
|
||
describe "PUT /budgets" do | ||
let(:good_params) do | ||
{ | ||
budget: { | ||
month: Budget::BUDGET_MONTHS.first, | ||
description: "Paycheck", | ||
amount: 2.0, | ||
cash_flow_type: :income, | ||
budget_category_id: budget_category.id | ||
} | ||
} | ||
end | ||
|
||
let(:missing_params) do | ||
{ | ||
id: budget.id, | ||
budget: { | ||
month: Budget::BUDGET_MONTHS.first, | ||
description: nil, | ||
amount: 1.0, | ||
cash_flow_type: :income | ||
} | ||
} | ||
end | ||
|
||
context "when the record already exist" do | ||
it "returns HTTP redirect" do | ||
put budget_path(id: budget.id), params: good_params | ||
expect(response).to have_http_status(:redirect) | ||
expect(budget.reload.amount).to eq(2.0) | ||
end | ||
end | ||
|
||
context "when the record doesn't already exist" do | ||
it "returns HTTP missing" do | ||
put budget_path(id: budget.id + 1), params: good_params | ||
expect(response).to have_http_status(:missing) | ||
end | ||
end | ||
|
||
context "when the record is missing required fields" do | ||
it "returns HTTP unprocessable entity" do | ||
put budget_path(id: budget.id), params: missing_params | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
|
||
describe "DELETE /budget/:id" do | ||
context "when the ID exists" do | ||
it "returns HTTP redirect" do | ||
delete budget_path(budget) | ||
expect(response).to have_http_status(:redirect) | ||
end | ||
end | ||
|
||
context "when the ID doesn't exist" do | ||
it "returns HTTP missing" do | ||
delete budget_path(id: budget.id + 10) | ||
expect(response).to have_http_status(:missing) | ||
end | ||
end | ||
end | ||
end |