Refactor sorting specs to work with direction

This commit is contained in:
Anna Anks Nowak
2019-01-01 18:52:02 +01:00
committed by Javi Martín
parent 747b8295b1
commit 0affaaee7e

View File

@@ -603,7 +603,7 @@ feature 'Admin budget investments' do
create(:budget_investment, title: 'C Third Investment', cached_votes_up: 10, budget: budget)
end
scenario "Default sorting" do
scenario "Default" do
create(:budget_investment, title: 'D Fourth Investment', cached_votes_up: 50, budget: budget)
visit admin_budget_budget_investments_path(budget)
@@ -613,26 +613,76 @@ feature 'Admin budget investments' do
expect('A Second Investment').to appear_before('C Third Investment')
end
scenario 'Sort by ID' do
visit admin_budget_budget_investments_path(budget, sort_by: 'id')
context 'Ascending' do
scenario 'Sort by ID' do
visit admin_budget_budget_investments_path(budget, sort_by: 'id', direction: 'asc')
expect('C Third Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('B First Investment')
expect('B First Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('C Third Investment')
end
scenario 'Sort by title' do
visit admin_budget_budget_investments_path(budget, sort_by: 'title', direction: 'asc')
expect('A Second Investment').to appear_before('B First Investment')
expect('B First Investment').to appear_before('C Third Investment')
end
scenario 'Sort by supports' do
visit admin_budget_budget_investments_path(budget, sort_by: 'supports', direction: 'asc')
expect('C Third Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('B First Investment')
end
end
scenario 'Sort by title' do
visit admin_budget_budget_investments_path(budget, sort_by: 'title')
context 'Descending' do
scenario 'Sort by ID' do
visit admin_budget_budget_investments_path(budget, sort_by: 'id', direction: 'desc')
expect('A Second Investment').to appear_before('B First Investment')
expect('B First Investment').to appear_before('C Third Investment')
expect('C Third Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('B First Investment')
end
scenario 'Sort by title' do
visit admin_budget_budget_investments_path(budget, sort_by: 'title', direction: 'desc')
expect('C Third Investment').to appear_before('B First Investment')
expect('B First Investment').to appear_before('A Second Investment')
end
scenario 'Sort by supports' do
visit admin_budget_budget_investments_path(budget, sort_by: 'supports', direction: 'desc')
expect('B First Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('C Third Investment')
end
end
scenario 'Sort by supports' do
visit admin_budget_budget_investments_path(budget, sort_by: 'supports')
context 'With no direction provided sorts ascending' do
scenario 'Sort by ID' do
visit admin_budget_budget_investments_path(budget, sort_by: 'id')
expect('B First Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('C Third Investment')
expect('B First Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('C Third Investment')
end
scenario 'Sort by title' do
visit admin_budget_budget_investments_path(budget, sort_by: 'title')
expect('A Second Investment').to appear_before('B First Investment')
expect('B First Investment').to appear_before('C Third Investment')
end
scenario 'Sort by supports' do
visit admin_budget_budget_investments_path(budget, sort_by: 'supports')
expect('C Third Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('B First Investment')
end
end
end
context 'Show' do