diff --git a/app/controllers/finance/ordergroups_controller.rb b/app/controllers/finance/ordergroups_controller.rb index 393262a3..58ba0c36 100644 --- a/app/controllers/finance/ordergroups_controller.rb +++ b/app/controllers/finance/ordergroups_controller.rb @@ -14,7 +14,7 @@ class Finance::OrdergroupsController < Finance::BaseController @ordergroups = @ordergroups.page(params[:page]).per(@per_page) @total_balances = FinancialTransactionClass.sorted.each_with_object({}) do |c, tmp| - tmp[c.id] = c.financial_transactions.reduce(0) { | sum, t | sum + t.amount } + tmp[c.id] = c.financial_transactions.reduce(0) { |sum, t| sum + t.amount } end end end diff --git a/app/views/finance/ordergroups/_ordergroups.html.haml b/app/views/finance/ordergroups/_ordergroups.html.haml index 3e0c99fc..6cf12c16 100644 --- a/app/views/finance/ordergroups/_ordergroups.html.haml +++ b/app/views/finance/ordergroups/_ordergroups.html.haml @@ -28,6 +28,6 @@ %th - FinancialTransactionClass.sorted.each do |c| - name = FinancialTransactionClass.has_multiple_classes ? c.display : heading_helper(Ordergroup, :account_balance) - %th.numeric= format_currency @total_balances[c.id] - %th.numeric + %th.numeric{:id => "total_balance#{c.id}"}= format_currency @total_balances[c.id] + %th.numeric#total_balance_sum = format_currency @total_balances.values.reduce(:+) \ No newline at end of file diff --git a/spec/controllers/finance/ordergroups_controller_spec.rb b/spec/controllers/finance/ordergroups_controller_spec.rb index f960c61d..3750016d 100644 --- a/spec/controllers/finance/ordergroups_controller_spec.rb +++ b/spec/controllers/finance/ordergroups_controller_spec.rb @@ -3,24 +3,30 @@ require 'spec_helper' describe Finance::OrdergroupsController do + include ActionView::Helpers::NumberHelper + render_views + let(:user) { create(:user, :role_finance, :role_orders, :ordergroup) } let(:fin_trans_type1) { create(:financial_transaction_type) } let(:fin_trans_type2) { create(:financial_transaction_type) } let(:fin_trans1) do create(:financial_transaction, user: user, + amount: 100, ordergroup: user.ordergroup, financial_transaction_type: fin_trans_type1) end let(:fin_trans2) do create(:financial_transaction, user: user, + amount: 200, ordergroup: user.ordergroup, financial_transaction_type: fin_trans_type1) end let(:fin_trans3) do create(:financial_transaction, user: user, + amount: 42.23, ordergroup: user.ordergroup, financial_transaction_type: fin_trans_type2) end @@ -37,14 +43,15 @@ describe Finance::OrdergroupsController do it 'renders index page' do get_with_defaults :index expect(response).to have_http_status(:success) - expect(response).to render_template('finance/ordergroups/index') end it 'calculates total balance sums correctly' do get_with_defaults :index - expect(assigns(:total_balances).size).to eq(2) - expect(assigns(:total_balances)[fin_trans_type1.id]).to eq(fin_trans1.amount + fin_trans2.amount) - expect(assigns(:total_balances)[fin_trans_type2.id]).to eq(fin_trans3.amount) + expect(response).to have_http_status(:success) + + assert_select "#total_balance#{fin_trans_type1.id}", number_to_currency(300) + assert_select "#total_balance#{fin_trans_type2.id}", number_to_currency(42.23) + assert_select '#total_balance_sum', number_to_currency(342.23) end end end