diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 381a4cea1..a48fa3188 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -169,11 +169,11 @@ module Budgets def investments if @current_order == 'random' - @investments.apply_filters_and_search(@budget, params, @current_filter) - .send("sort_by_#{@current_order}", params[:random_seed]) + @budget.investments.apply_filters_and_search(@budget, params, @current_filter) + .send("sort_by_#{@current_order}", params[:random_seed]) else - @investments.apply_filters_and_search(@budget, params, @current_filter) - .send("sort_by_#{@current_order}") + @budget.investments.apply_filters_and_search(@budget, params, @current_filter) + .send("sort_by_#{@current_order}") end end diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index a0d02bc37..e669579df 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1874,6 +1874,24 @@ feature 'Budget Investments' do expect(page).to have_css(".map-icon", count: 0, visible: false) end end + + scenario "Shows all investments and not only the ones on the current page", :js do + stub_const("#{Budgets::InvestmentsController}::PER_PAGE", 2) + + 3.times do + create(:map_location, investment: create(:budget_investment, heading: heading)) + end + + visit budget_investments_path(budget, heading_id: heading.id) + + within("#budget-investments") do + expect(page).to have_css(".budget-investment", count: 2) + end + + within(".map_location") do + expect(page).to have_css(".map-icon", count: 3, visible: false) + end + end end end