Test added to check the repetition of elements between pages when random order used. Scope variable initialized to 1
This commit is contained in:
@@ -43,7 +43,7 @@ class Budget
|
||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) }
|
||||
scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) }
|
||||
scope :sort_by_price, -> { reorder(price: :desc, confidence_score: :desc, id: :desc) }
|
||||
scope :sort_by_random, ->(seed) { reorder("budget_investments.id % #{seed}, budget_investments.id") }
|
||||
scope :sort_by_random, ->(seed) { reorder("budget_investments.id % #{seed || 1}, budget_investments.id") }
|
||||
|
||||
scope :valuation_open, -> { where(valuation_finished: false) }
|
||||
scope :without_admin, -> { valuation_open.where(administrator_id: nil) }
|
||||
|
||||
@@ -170,6 +170,25 @@ feature 'Budget Investments' do
|
||||
expect(order).to eq(new_order)
|
||||
end
|
||||
|
||||
scenario "Investments are not repeated with random order", :js do
|
||||
12.times { create(:budget_investment, heading: heading) }
|
||||
# 12 instead of per_page + 2 because in each page there are 10 (in this case), not 25
|
||||
|
||||
visit budget_investments_path(budget, order: 'random')
|
||||
|
||||
first_page_investments = all(".budget-investment h3").collect {|i| i.text }
|
||||
|
||||
click_link 'Next'
|
||||
expect(page).to have_content "You're on page 2"
|
||||
|
||||
second_page_investments = all(".budget-investment h3").collect {|i| i.text }
|
||||
|
||||
common_values = first_page_investments & second_page_investments
|
||||
|
||||
expect(common_values.length).to eq(0)
|
||||
|
||||
end
|
||||
|
||||
scenario 'Proposals are ordered by confidence_score', :js do
|
||||
create(:budget_investment, heading: heading, title: 'Best proposal').update_column(:confidence_score, 10)
|
||||
create(:budget_investment, heading: heading, title: 'Worst proposal').update_column(:confidence_score, 2)
|
||||
|
||||
Reference in New Issue
Block a user