Show all investments in the map
We were showing only the ones being shown in the current page because
we were modifying `@investments` using a method which used
`@investments`, and we were calling that method twice.
There are many possible solutions: using a local variable to store the
result of the `investments` method, modifying `@investments` after
modifying `@investments_map_coordinates`, ... I've used the one which in
my humble opinion is a bit less fragile: not using `@investments` inside
the `investments` method. That way, the `investments` method will always
return the same result.
Note `stub_const("Budgets::InvestmentsController::PER_PAGE", 2)`
wouldn't work because `Budgets::InvestmentsController` isn't loaded when
that line is executed. So we need to load it. Instead of requiring the
file, using `#{Budgets::InvestmentsController}` seems to be an easier
solution.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user