Merge pull request #3318 from consul/backport-refactor_investments_index
Show all investments in the map
This commit is contained in:
@@ -6,6 +6,8 @@ module Budgets
|
|||||||
include FlagActions
|
include FlagActions
|
||||||
include ImageAttributes
|
include ImageAttributes
|
||||||
|
|
||||||
|
PER_PAGE = 10
|
||||||
|
|
||||||
before_action :authenticate_user!, except: [:index, :show, :json_data]
|
before_action :authenticate_user!, except: [:index, :show, :json_data]
|
||||||
|
|
||||||
load_and_authorize_resource :budget, except: :json_data
|
load_and_authorize_resource :budget, except: :json_data
|
||||||
@@ -37,7 +39,7 @@ module Budgets
|
|||||||
respond_to :html, :js
|
respond_to :html, :js
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@investments = investments.page(params[:page]).per(10).for_render
|
@investments = investments.page(params[:page]).per(PER_PAGE).for_render
|
||||||
|
|
||||||
@investment_ids = @investments.pluck(:id)
|
@investment_ids = @investments.pluck(:id)
|
||||||
@investments_map_coordinates = MapLocation.where(investment: investments).map(&:json_data)
|
@investments_map_coordinates = MapLocation.where(investment: investments).map(&:json_data)
|
||||||
@@ -167,11 +169,11 @@ module Budgets
|
|||||||
|
|
||||||
def investments
|
def investments
|
||||||
if @current_order == 'random'
|
if @current_order == 'random'
|
||||||
@investments.apply_filters_and_search(@budget, params, @current_filter)
|
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
|
||||||
.send("sort_by_#{@current_order}", params[:random_seed])
|
.send("sort_by_#{@current_order}", params[:random_seed])
|
||||||
else
|
else
|
||||||
@investments.apply_filters_and_search(@budget, params, @current_filter)
|
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
|
||||||
.send("sort_by_#{@current_order}")
|
.send("sort_by_#{@current_order}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1874,6 +1874,24 @@ feature 'Budget Investments' do
|
|||||||
expect(page).to have_css(".map-icon", count: 0, visible: false)
|
expect(page).to have_css(".map-icon", count: 0, visible: false)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user