Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ GIT

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module-ptp.git
revision: e2ec0dd39b5e8b96b88986c494087a9e87e94d2e
revision: 9ea26682739486ce4ca30a814747e88e57e70524
specs:
decidim-budgets_booth (0.27.0)
decidim-budgets (~> 0.27.0)
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/decidim/budgets/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ def projects
return @projects if @projects

@projects = reorder(search.result)
@projects = @projects.page(params[:page]).per(current_component.settings.projects_per_page)
ids = @projects.pluck(:id)

# keep the order so that when we use filters and pagination, projects are always
# displayed in the same order on the pages
@projects = Decidim::Budgets::Project.where(id: ids)
.order(Arel.sql("position(id::text in '#{ids.join(",")}')"))
.page(params[:page])
.per(current_component.settings.projects_per_page)
end

def all_geocoded_projects
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"--window-size=1920,1080"
end
options.args << "--ignore-certificate-errors" if ENV["TEST_SSL"]
options.add_preference("intl.accept_languages", "en-GB")
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
Expand Down
48 changes: 48 additions & 0 deletions spec/system/explore_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,54 @@
end
end

context "when filtering by category and changing pages" do
let!(:projects_count) { 10 }
let!(:categories) { create_list(:category, 2, participatory_space: component.participatory_space) }

it "keeps the order of the projects displayed on the pages" do
component.update!(settings: { projects_per_page: 3 })
first_cate = categories.first
sec_cate = categories.last
projects.each_with_index do |project, index|
project.category = index.even? ? first_cate : sec_cate
project.save
end

visit_budget

within ".with_any_category_check_boxes_tree_filter" do
uncheck "All"
uncheck translated(first_cate.name)
end

within "#projects" do
expect(page).to have_css(".budget-list__item", count: 3)
end

budget_list = all("div.budget-list__item")
first_proj = budget_list[0][:id]
sec_proj = budget_list[1][:id]
third_proj = budget_list[2][:id]

within "#projects .pagination" do
# navigate page 2
expect(page).to have_content("2")
page.find("a", text: "2").click
end

within "#projects .pagination" do
# navigate back page 1
page.find("a", text: "1").click
end

# check that the projects are displayed in the same order on page one
new_budget_list = all("div.budget-list__item")
expect(new_budget_list[0][:id]).to eq(first_proj)
expect(new_budget_list[1][:id]).to eq(sec_proj)
expect(new_budget_list[2][:id]).to eq(third_proj)
end
end

context "and votes are finished" do
let!(:component) do
create(:budgets_component,
Expand Down
Loading