From f6da20da64822c10570b9d004f648088875e4331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 27 Mar 2019 14:27:41 +0100 Subject: [PATCH] Fix typos in investment order tests There was a typo: `new_order = eq(all(` instead of `new_order = all(`, which was causing the tests to pass. However, the final expectation should test that we keep the same order in the same session, and we were accidentally testing the opposite. We're also adding an extra check to verify there are investments on the page, since in some cases we were accessing pages with no investments, and so these tests were always passing. --- spec/features/budgets/investments_spec.rb | 41 +++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 9815cdcaa..22c7bd698 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -586,30 +586,34 @@ feature "Budget Investments" do let(:per_page) { Budgets::InvestmentsController::PER_PAGE } scenario "Default order is random" do - (per_page + 2).times { create(:budget_investment) } + (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + + within(".submenu .is-active") { expect(page).to have_content "random" } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty visit budget_investments_path(budget, heading_id: heading.id) - new_order = eq(all(".budget-investment h3").collect {|i| i.text }) + new_order = all(".budget-investment h3").collect { |i| i.text } - expect(order).not_to eq(new_order) + expect(order).to eq(new_order) end scenario "Random order after another order" do - (per_page + 2).times { create(:budget_investment) } + (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty + click_link "highest rated" click_link "random" - order = all(".budget-investment h3").collect {|i| i.text } - visit budget_investments_path(budget, heading_id: heading.id) - new_order = eq(all(".budget-investment h3").collect {|i| i.text }) + new_order = all(".budget-investment h3").collect { |i| i.text } - expect(order).not_to eq(new_order) + expect(order).to eq(new_order) end scenario "Random order maintained with pagination" do @@ -617,7 +621,8 @@ feature "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty click_link "Next" expect(page).to have_content "You're on page 2" @@ -625,7 +630,7 @@ feature "Budget Investments" do click_link "Previous" expect(page).to have_content "You're on page 1" - new_order = all(".budget-investment h3").collect {|i| i.text } + new_order = all(".budget-investment h3").collect { |i| i.text } expect(order).to eq(new_order) end @@ -634,12 +639,13 @@ feature "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty click_link Budget::Investment.first.title click_link "Go back" - new_order = all(".budget-investment h3").collect {|i| i.text } + new_order = all(".budget-investment h3").collect { |i| i.text } expect(order).to eq(new_order) end @@ -758,17 +764,18 @@ feature "Budget Investments" do end scenario "Order is random if budget is finished" do - per_page.times { create(:budget_investment) } + per_page.times { create(:budget_investment, :winner, heading: heading) } budget.update(phase: "finished") visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty visit budget_investments_path(budget, heading_id: heading.id) - new_order = eq(all(".budget-investment h3").collect {|i| i.text }) + new_order = all(".budget-investment h3").collect { |i| i.text } - expect(order).not_to eq(new_order) + expect(order).to eq(new_order) end scenario "Order always is random for unfeasible and unselected investments" do