diff --git a/app/controllers/credit_card_bills_controller.rb b/app/controllers/credit_card_bills_controller.rb new file mode 100644 index 0000000..8c41a88 --- /dev/null +++ b/app/controllers/credit_card_bills_controller.rb @@ -0,0 +1,70 @@ +class CreditCardBillsController < ApplicationController + before_action :set_credit_card_bill, only: %i[ show edit update destroy ] + + # GET /credit_card_bills or /credit_card_bills.json + def index + @credit_card_bills = CreditCardBill.all + end + + # GET /credit_card_bills/1 or /credit_card_bills/1.json + def show + end + + # GET /credit_card_bills/new + def new + @credit_card_bill = CreditCardBill.new + end + + # GET /credit_card_bills/1/edit + def edit + end + + # POST /credit_card_bills or /credit_card_bills.json + def create + @credit_card_bill = CreditCardBill.new(credit_card_bill_params) + + respond_to do |format| + if @credit_card_bill.save + format.html { redirect_to credit_card_bill_url(@credit_card_bill), notice: "Credit card bill was successfully created." } + format.json { render :show, status: :created, location: @credit_card_bill } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @credit_card_bill.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /credit_card_bills/1 or /credit_card_bills/1.json + def update + respond_to do |format| + if @credit_card_bill.update(credit_card_bill_params) + format.html { redirect_to credit_card_bill_url(@credit_card_bill), notice: "Credit card bill was successfully updated." } + format.json { render :show, status: :ok, location: @credit_card_bill } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @credit_card_bill.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /credit_card_bills/1 or /credit_card_bills/1.json + def destroy + @credit_card_bill.destroy + + respond_to do |format| + format.html { redirect_to credit_card_bills_url, notice: "Credit card bill was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_credit_card_bill + @credit_card_bill = CreditCardBill.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def credit_card_bill_params + params.require(:credit_card_bill).permit(:description, :amount) + end +end diff --git a/app/controllers/expenses_controller.rb b/app/controllers/expenses_controller.rb index c88513d..34fb814 100644 --- a/app/controllers/expenses_controller.rb +++ b/app/controllers/expenses_controller.rb @@ -65,6 +65,6 @@ class ExpensesController < ApplicationController # Only allow a list of trusted parameters through. def expense_params - params.require(:expense).permit(:description, :payment, :period, :autopaid, :estimated) + params.require(:expense).permit(:description, :payment, :period, :credit_card, :estimated) end end diff --git a/app/controllers/extra_bills_controller.rb b/app/controllers/extra_bills_controller.rb deleted file mode 100644 index 3caed45..0000000 --- a/app/controllers/extra_bills_controller.rb +++ /dev/null @@ -1,70 +0,0 @@ -class ExtraBillsController < ApplicationController - before_action :set_extra_bill, only: %i[ show edit update destroy ] - - # GET /extra_bills or /extra_bills.json - def index - @extra_bills = ExtraBill.all - end - - # GET /extra_bills/1 or /extra_bills/1.json - def show - end - - # GET /extra_bills/new - def new - @extra_bill = ExtraBill.new - end - - # GET /extra_bills/1/edit - def edit - end - - # POST /extra_bills or /extra_bills.json - def create - @extra_bill = ExtraBill.new(extra_bill_params) - - respond_to do |format| - if @extra_bill.save - format.html { redirect_to extra_bill_url(@extra_bill), notice: "Extra bill was successfully created." } - format.json { render :show, status: :created, location: @extra_bill } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @extra_bill.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /extra_bills/1 or /extra_bills/1.json - def update - respond_to do |format| - if @extra_bill.update(extra_bill_params) - format.html { redirect_to extra_bill_url(@extra_bill), notice: "Extra bill was successfully updated." } - format.json { render :show, status: :ok, location: @extra_bill } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @extra_bill.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /extra_bills/1 or /extra_bills/1.json - def destroy - @extra_bill.destroy - - respond_to do |format| - format.html { redirect_to extra_bills_url, notice: "Extra bill was successfully destroyed." } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_extra_bill - @extra_bill = ExtraBill.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def extra_bill_params - params.require(:extra_bill).permit(:description, :amount, :deduct_autopaid) - end -end diff --git a/app/models/credit_card_bill.rb b/app/models/credit_card_bill.rb new file mode 100644 index 0000000..9d90972 --- /dev/null +++ b/app/models/credit_card_bill.rb @@ -0,0 +1,5 @@ +class CreditCardBill < ApplicationRecord + def unpaid + amount - Expense.credit_card_monthly_total + end +end diff --git a/app/models/expense.rb b/app/models/expense.rb index b40b49d..3e38e34 100644 --- a/app/models/expense.rb +++ b/app/models/expense.rb @@ -19,7 +19,7 @@ class Expense < ApplicationRecord Expense.all.map(&:monthly).sum.round(2) end - def self.autopaid_total - Expense.where(autopaid: true).map(&:monthly).sum.round(2) + def self.credit_card_monthly_total + Expense.where(credit_card: true).map(&:monthly).sum.round(2) end end diff --git a/app/models/extra_bill.rb b/app/models/extra_bill.rb deleted file mode 100644 index 95d1845..0000000 --- a/app/models/extra_bill.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ExtraBill < ApplicationRecord - def adjusted_amount - deduct_autopaid? ? amount - Expense.autopaid_total : amount - end -end diff --git a/app/views/extra_bills/_extra_bill.html.erb b/app/views/credit_card_bills/_credit_card_bill.html.erb similarity index 66% rename from app/views/extra_bills/_extra_bill.html.erb rename to app/views/credit_card_bills/_credit_card_bill.html.erb index e077fb7..df91f34 100644 --- a/app/views/extra_bills/_extra_bill.html.erb +++ b/app/views/credit_card_bills/_credit_card_bill.html.erb @@ -1,27 +1,22 @@ -
+

Description: - <%= extra_bill.description %> + <%= credit_card_bill.description %>

Amount: - <%= extra_bill.amount %> -

- -

- Adjusted Amount: - <%= extra_bill.adjusted_amount %> + <%= credit_card_bill.amount %>

Accounted For: - <%= Expense.autopaid_total %> + <%= Expense.credit_card_monthly_total %>

- Deduct autopaid: - <%= extra_bill.deduct_autopaid %> + Unpaid: + <%= credit_card_bill.unpaid %>

@@ -38,7 +33,7 @@ <%= member.name %> <%= member.burden_percent * 100 %>% - <%= number_to_currency(member.burden_amount(total_amount: extra_bill.adjusted_amount)) %> + <%= number_to_currency(member.burden_amount(total_amount: credit_card_bill.unpaid)) %> <% end %> @@ -46,8 +41,8 @@

<% if action_name != "show" %> - <%= link_to "Show this extra bill", extra_bill, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to 'Edit this extra bill', edit_extra_bill_path(extra_bill), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Show this credit card bill", credit_card_bill, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to 'Edit this credit card bill', edit_credit_card_bill_path(credit_card_bill), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<% end %>
diff --git a/app/views/credit_card_bills/_credit_card_bill.json.jbuilder b/app/views/credit_card_bills/_credit_card_bill.json.jbuilder new file mode 100644 index 0000000..681e928 --- /dev/null +++ b/app/views/credit_card_bills/_credit_card_bill.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! credit_card_bill, :id, :description, :amount, :created_at, :updated_at +json.url credit_card_bill_url(credit_card_bill, format: :json) diff --git a/app/views/extra_bills/_form.html.erb b/app/views/credit_card_bills/_form.html.erb similarity index 56% rename from app/views/extra_bills/_form.html.erb rename to app/views/credit_card_bills/_form.html.erb index a00dfbf..6098e1d 100644 --- a/app/views/extra_bills/_form.html.erb +++ b/app/views/credit_card_bills/_form.html.erb @@ -1,10 +1,9 @@ -<%= form_with(model: extra_bill, class: "contents") do |form| %> - <% if extra_bill.errors.any? %> -
-

<%= pluralize(extra_bill.errors.count, "error") %> prohibited this extra_bill from being saved:

+<%= form_with(model: credit_card_bill, class: "contents") do |form| %> + <% if credit_card_bill.errors.any? %>
+

<%= pluralize(credit_card_bill.errors.count, "error") %> prohibited this credit_card_bill from being saved:

    - <% extra_bill.errors.each do |error| %> + <% credit_card_bill.errors.each do |error| %>
  • <%= error.full_message %>
  • <% end %>
@@ -21,11 +20,6 @@ <%= form.text_field :amount, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
-
- <%= form.label :deduct_autopaid %> - <%= form.check_box :deduct_autopaid, class: "block mt-2 h-5 w-5" %> -
-
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
diff --git a/app/views/credit_card_bills/edit.html.erb b/app/views/credit_card_bills/edit.html.erb new file mode 100644 index 0000000..ec91b94 --- /dev/null +++ b/app/views/credit_card_bills/edit.html.erb @@ -0,0 +1,8 @@ +
+

Editing credit card bill

+ + <%= render "form", credit_card_bill: @credit_card_bill %> + + <%= link_to "Show this credit card bill", @credit_card_bill, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to credit card bills", credit_card_bills_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/credit_card_bills/index.html.erb b/app/views/credit_card_bills/index.html.erb new file mode 100644 index 0000000..c74377d --- /dev/null +++ b/app/views/credit_card_bills/index.html.erb @@ -0,0 +1,14 @@ +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + +
+

Credit card bills

+ <%= link_to 'New credit card bill', new_credit_card_bill_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> +
+ +
+ <%= render @credit_card_bills %> +
+
diff --git a/app/views/credit_card_bills/index.json.jbuilder b/app/views/credit_card_bills/index.json.jbuilder new file mode 100644 index 0000000..2ac3401 --- /dev/null +++ b/app/views/credit_card_bills/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @credit_card_bills, partial: "credit_card_bills/credit_card_bill", as: :credit_card_bill diff --git a/app/views/credit_card_bills/new.html.erb b/app/views/credit_card_bills/new.html.erb new file mode 100644 index 0000000..e0b9218 --- /dev/null +++ b/app/views/credit_card_bills/new.html.erb @@ -0,0 +1,7 @@ +
+

New credit card bill

+ + <%= render "form", credit_card_bill: @credit_card_bill %> + + <%= link_to 'Back to credit card bills', credit_card_bills_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/credit_card_bills/show.html.erb b/app/views/credit_card_bills/show.html.erb new file mode 100644 index 0000000..18b1e77 --- /dev/null +++ b/app/views/credit_card_bills/show.html.erb @@ -0,0 +1,15 @@ +
+
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <%= render @credit_card_bill %> + + <%= link_to 'Edit this credit_card_bill', edit_credit_card_bill_path(@credit_card_bill), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+ <%= button_to 'Destroy this credit_card_bill', credit_card_bill_path(@credit_card_bill), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> +
+ <%= link_to 'Back to credit_card_bills', credit_card_bills_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+
diff --git a/app/views/credit_card_bills/show.json.jbuilder b/app/views/credit_card_bills/show.json.jbuilder new file mode 100644 index 0000000..410f902 --- /dev/null +++ b/app/views/credit_card_bills/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "credit_card_bills/credit_card_bill", credit_card_bill: @credit_card_bill diff --git a/app/views/dashboard/show.html.erb b/app/views/dashboard/show.html.erb index 7edbc72..6cfe1bd 100644 --- a/app/views/dashboard/show.html.erb +++ b/app/views/dashboard/show.html.erb @@ -49,7 +49,7 @@ Payment Period Montly - Autopaid + credit_card Estimated @@ -60,7 +60,7 @@ <%= number_to_currency(expense.payment) %> <%= expense.period %> <%= number_to_currency(expense.monthly) %> - <%= expense.autopaid %> + <%= expense.credit_card %> <%= expense.estimated %> <% end %> diff --git a/app/views/expenses/_expense.html.erb b/app/views/expenses/_expense.html.erb index cb922b0..83e9896 100644 --- a/app/views/expenses/_expense.html.erb +++ b/app/views/expenses/_expense.html.erb @@ -15,8 +15,8 @@

- Autopaid: - <%= expense.autopaid %> + Credit card: + <%= expense.credit_card %>

diff --git a/app/views/expenses/_expense.json.jbuilder b/app/views/expenses/_expense.json.jbuilder index 216ad4e..964a52e 100644 --- a/app/views/expenses/_expense.json.jbuilder +++ b/app/views/expenses/_expense.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! expense, :id, :description, :payment, :period, :autopaid, :estimated, :created_at, :updated_at +json.extract! expense, :id, :description, :payment, :period, :credit_card, :estimated, :created_at, :updated_at json.url expense_url(expense, format: :json) diff --git a/app/views/expenses/_form.html.erb b/app/views/expenses/_form.html.erb index 0630871..766faec 100644 --- a/app/views/expenses/_form.html.erb +++ b/app/views/expenses/_form.html.erb @@ -32,8 +32,8 @@

- <%= form.label :autopaid %> - <%= form.check_box :autopaid, class: "block mt-2 h-5 w-5" %> + <%= form.label :credit_card %> + <%= form.check_box :credit_card, class: "block mt-2 h-5 w-5" %>
diff --git a/app/views/extra_bills/_extra_bill.json.jbuilder b/app/views/extra_bills/_extra_bill.json.jbuilder deleted file mode 100644 index b4b6212..0000000 --- a/app/views/extra_bills/_extra_bill.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.extract! extra_bill, :id, :description, :amount, :deduct_autopaid, :created_at, :updated_at -json.url extra_bill_url(extra_bill, format: :json) diff --git a/app/views/extra_bills/edit.html.erb b/app/views/extra_bills/edit.html.erb deleted file mode 100644 index 01fc93d..0000000 --- a/app/views/extra_bills/edit.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -
-

Editing extra bill

- - <%= render "form", extra_bill: @extra_bill %> - - <%= link_to "Show this extra bill", @extra_bill, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Back to extra bills", extra_bills_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
diff --git a/app/views/extra_bills/index.html.erb b/app/views/extra_bills/index.html.erb deleted file mode 100644 index b3926a1..0000000 --- a/app/views/extra_bills/index.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
- <% if notice.present? %> -

<%= notice %>

- <% end %> - -
-

Extra bills

- <%= link_to 'New extra bill', new_extra_bill_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> -
- -
- <%= render @extra_bills %> -
-
diff --git a/app/views/extra_bills/index.json.jbuilder b/app/views/extra_bills/index.json.jbuilder deleted file mode 100644 index c9fcca7..0000000 --- a/app/views/extra_bills/index.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.array! @extra_bills, partial: "extra_bills/extra_bill", as: :extra_bill diff --git a/app/views/extra_bills/new.html.erb b/app/views/extra_bills/new.html.erb deleted file mode 100644 index 93bdabb..0000000 --- a/app/views/extra_bills/new.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -
-

New extra bill

- - <%= render "form", extra_bill: @extra_bill %> - - <%= link_to 'Back to extra bills', extra_bills_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
diff --git a/app/views/extra_bills/show.html.erb b/app/views/extra_bills/show.html.erb deleted file mode 100644 index 1575349..0000000 --- a/app/views/extra_bills/show.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -
-
- <% if notice.present? %> -

<%= notice %>

- <% end %> - - <%= render @extra_bill %> - - <%= link_to 'Edit this extra_bill', edit_extra_bill_path(@extra_bill), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
- <%= button_to 'Destroy this extra_bill', extra_bill_path(@extra_bill), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> -
- <%= link_to 'Back to extra_bills', extra_bills_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
-
diff --git a/app/views/extra_bills/show.json.jbuilder b/app/views/extra_bills/show.json.jbuilder deleted file mode 100644 index 7659dc9..0000000 --- a/app/views/extra_bills/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "extra_bills/extra_bill", extra_bill: @extra_bill diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 46a0e9e..c90e132 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,7 +16,7 @@ diff --git a/config/routes.rb b/config/routes.rb index 7f55438..4930193 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - resources :extra_bills + resources :credit_card_bills resource :dashboard, only: :show resources :incomes resources :members diff --git a/db/migrate/20230225002002_explicit_credit_card.rb b/db/migrate/20230225002002_explicit_credit_card.rb new file mode 100644 index 0000000..53b827d --- /dev/null +++ b/db/migrate/20230225002002_explicit_credit_card.rb @@ -0,0 +1,7 @@ +class ExplicitCreditCard < ActiveRecord::Migration[7.0] + def change + rename_column :expenses, :autopaid, :credit_card + rename_table :extra_bills, :credit_card_bills + remove_column :credit_card_bills, :deduct_autopaid + end +end diff --git a/db/schema.rb b/db/schema.rb index e3c238e..67131f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,21 +10,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_02_24_232804) do - create_table "expenses", force: :cascade do |t| - t.string "description", default: "", null: false - t.decimal "payment", precision: 8, scale: 2, default: "0.0", null: false - t.integer "period", default: 0, null: false - t.boolean "autopaid", default: false, null: false - t.boolean "estimated", default: false, null: false +ActiveRecord::Schema[7.0].define(version: 2023_02_25_002002) do + create_table "credit_card_bills", force: :cascade do |t| + t.string "description" + t.decimal "amount" t.datetime "created_at", null: false t.datetime "updated_at", null: false end - create_table "extra_bills", force: :cascade do |t| - t.string "description" - t.decimal "amount" - t.boolean "deduct_autopaid" + create_table "expenses", force: :cascade do |t| + t.string "description", default: "", null: false + t.decimal "payment", precision: 8, scale: 2, default: "0.0", null: false + t.integer "period", default: 0, null: false + t.boolean "credit_card", default: false, null: false + t.boolean "estimated", default: false, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/test/controllers/credit_card_bills_controller_test.rb b/test/controllers/credit_card_bills_controller_test.rb new file mode 100644 index 0000000..85a7106 --- /dev/null +++ b/test/controllers/credit_card_bills_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class CreditCardBillsControllerTest < ActionDispatch::IntegrationTest + setup do + @credit_card_bill = credit_card_bills(:one) + end + + test "should get index" do + get credit_card_bills_url + assert_response :success + end + + test "should get new" do + get new_credit_card_bill_url + assert_response :success + end + + test "should create credit_card_bill" do + assert_difference("CreditCardBill.count") do + post credit_card_bills_url, params: { credit_card_bill: { amount: @credit_card_bill.amount, description: @credit_card_bill.description } } + end + + assert_redirected_to credit_card_bill_url(CreditCardBill.last) + end + + test "should show credit_card_bill" do + get credit_card_bill_url(@credit_card_bill) + assert_response :success + end + + test "should get edit" do + get edit_credit_card_bill_url(@credit_card_bill) + assert_response :success + end + + test "should update credit_card_bill" do + patch credit_card_bill_url(@credit_card_bill), params: { credit_card_bill: { amount: @credit_card_bill.amount, description: @credit_card_bill.description } } + assert_redirected_to credit_card_bill_url(@credit_card_bill) + end + + test "should destroy credit_card_bill" do + assert_difference("CreditCardBill.count", -1) do + delete credit_card_bill_url(@credit_card_bill) + end + + assert_redirected_to credit_card_bills_url + end +end diff --git a/test/controllers/expenses_controller_test.rb b/test/controllers/expenses_controller_test.rb index 1e5b44b..49c2498 100644 --- a/test/controllers/expenses_controller_test.rb +++ b/test/controllers/expenses_controller_test.rb @@ -17,7 +17,7 @@ class ExpensesControllerTest < ActionDispatch::IntegrationTest 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 } } + post expenses_url, params: { expense: { credit_card: @expense.credit_card, description: @expense.description, estimated: @expense.estimated, payment: @expense.payment, period: @expense.period } } end assert_redirected_to expense_url(Expense.last) @@ -34,7 +34,7 @@ class ExpensesControllerTest < ActionDispatch::IntegrationTest 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 } } + patch expense_url(@expense), params: { expense: { credit_card: @expense.credit_card, description: @expense.description, estimated: @expense.estimated, payment: @expense.payment, period: @expense.period } } assert_redirected_to expense_url(@expense) end diff --git a/test/controllers/extra_bills_controller_test.rb b/test/controllers/extra_bills_controller_test.rb deleted file mode 100644 index 35049d2..0000000 --- a/test/controllers/extra_bills_controller_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require "test_helper" - -class ExtraBillsControllerTest < ActionDispatch::IntegrationTest - setup do - @extra_bill = extra_bills(:one) - end - - test "should get index" do - get extra_bills_url - assert_response :success - end - - test "should get new" do - get new_extra_bill_url - assert_response :success - end - - test "should create extra_bill" do - assert_difference("ExtraBill.count") do - post extra_bills_url, params: { extra_bill: { amount: @extra_bill.amount, deduct_autopaid: @extra_bill.deduct_autopaid, description: @extra_bill.description } } - end - - assert_redirected_to extra_bill_url(ExtraBill.last) - end - - test "should show extra_bill" do - get extra_bill_url(@extra_bill) - assert_response :success - end - - test "should get edit" do - get edit_extra_bill_url(@extra_bill) - assert_response :success - end - - test "should update extra_bill" do - patch extra_bill_url(@extra_bill), params: { extra_bill: { amount: @extra_bill.amount, deduct_autopaid: @extra_bill.deduct_autopaid, description: @extra_bill.description } } - assert_redirected_to extra_bill_url(@extra_bill) - end - - test "should destroy extra_bill" do - assert_difference("ExtraBill.count", -1) do - delete extra_bill_url(@extra_bill) - end - - assert_redirected_to extra_bills_url - end -end diff --git a/test/fixtures/extra_bills.yml b/test/fixtures/credit_card_bills.yml similarity index 78% rename from test/fixtures/extra_bills.yml rename to test/fixtures/credit_card_bills.yml index febbccc..ca0607b 100644 --- a/test/fixtures/extra_bills.yml +++ b/test/fixtures/credit_card_bills.yml @@ -3,9 +3,7 @@ one: description: MyString amount: 9.99 - deduct_autopaid: false two: description: MyString amount: 9.99 - deduct_autopaid: false diff --git a/test/fixtures/expenses.yml b/test/fixtures/expenses.yml index 3eb6185..3c0ef47 100644 --- a/test/fixtures/expenses.yml +++ b/test/fixtures/expenses.yml @@ -4,12 +4,12 @@ one: description: MyString payment: 9.99 period: 1 - autopaid: false + credit_card: false estimated: false two: description: MyString payment: 9.99 period: 1 - autopaid: false + credit_card: false estimated: false diff --git a/test/models/extra_bill_test.rb b/test/models/credit_card_bill_test.rb similarity index 60% rename from test/models/extra_bill_test.rb rename to test/models/credit_card_bill_test.rb index 01a4bf0..f0558a5 100644 --- a/test/models/extra_bill_test.rb +++ b/test/models/credit_card_bill_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class ExtraBillTest < ActiveSupport::TestCase +class CreditCardBillTest < ActiveSupport::TestCase # test "the truth" do # assert true # end diff --git a/test/system/expenses_test.rb b/test/system/expenses_test.rb index 5778073..679a8ef 100644 --- a/test/system/expenses_test.rb +++ b/test/system/expenses_test.rb @@ -14,7 +14,7 @@ class ExpensesTest < ApplicationSystemTestCase visit expenses_url click_on "New expense" - check "Autopaid" if @expense.autopaid + check "Credit card" if @expense.credit_card fill_in "Description", with: @expense.description check "Estimated" if @expense.estimated fill_in "Payment", with: @expense.payment @@ -29,7 +29,7 @@ class ExpensesTest < ApplicationSystemTestCase visit expense_url(@expense) click_on "Edit this expense", match: :first - check "Autopaid" if @expense.autopaid + check "Credit card" if @expense.credit_card fill_in "Description", with: @expense.description check "Estimated" if @expense.estimated fill_in "Payment", with: @expense.payment diff --git a/test/system/extra_bills_test.rb b/test/system/extra_bills_test.rb index 77ec8ea..50cf2fc 100644 --- a/test/system/extra_bills_test.rb +++ b/test/system/extra_bills_test.rb @@ -1,45 +1,43 @@ require "application_system_test_case" -class ExtraBillsTest < ApplicationSystemTestCase +class CreditCardBillsTest < ApplicationSystemTestCase setup do - @extra_bill = extra_bills(:one) + @credit_card_bill = credit_card_bills(:one) end test "visiting the index" do - visit extra_bills_url - assert_selector "h1", text: "Extra bills" + visit credit_card_bills_url + assert_selector "h1", text: "Credit card bills" end - test "should create extra bill" do - visit extra_bills_url - click_on "New extra bill" + test "should create credit card bill" do + visit credit_card_bills_url + click_on "New credit card bill" - fill_in "Amount", with: @extra_bill.amount - check "Deduct autopaid" if @extra_bill.deduct_autopaid - fill_in "Description", with: @extra_bill.description - click_on "Create Extra bill" + fill_in "Amount", with: @credit_card_bill.amount + fill_in "Description", with: @credit_card_bill.description + click_on "Create Credit card bill" - assert_text "Extra bill was successfully created" + assert_text "Credit card bill was successfully created" click_on "Back" end - test "should update Extra bill" do - visit extra_bill_url(@extra_bill) - click_on "Edit this extra bill", match: :first + test "should update Credit card bill" do + visit credit_card_bill_url(@credit_card_bill) + click_on "Edit this credit card bill", match: :first - fill_in "Amount", with: @extra_bill.amount - check "Deduct autopaid" if @extra_bill.deduct_autopaid - fill_in "Description", with: @extra_bill.description - click_on "Update Extra bill" + fill_in "Amount", with: @credit_card_bill.amount + fill_in "Description", with: @credit_card_bill.description + click_on "Update Credit card bill" - assert_text "Extra bill was successfully updated" + assert_text "Credit card bill was successfully updated" click_on "Back" end - test "should destroy Extra bill" do - visit extra_bill_url(@extra_bill) - click_on "Destroy this extra bill", match: :first + test "should destroy Credit card bill" do + visit credit_card_bill_url(@credit_card_bill) + click_on "Destroy this credit card bill", match: :first - assert_text "Extra bill was successfully destroyed" + assert_text "Credit card bill was successfully destroyed" end end