Commit 2a37a929 authored by James Lopez's avatar James Lopez

refactored weight stuff and added new option to select all weight

parent 21ba6790
......@@ -268,17 +268,19 @@ class IssuableFinder
end
def by_weight(items)
return items if filter_by_any_weight? || !weights?
return items unless weights?
if filter_by_no_weight?
items.where(weight: [-1, nil])
elsif filter_by_any_weight?
items.where.not(weight: [-1, nil])
else
items.where(weight: params[:weight])
end
end
def weights?
params[:weight].present?
params[:weight].present? && params[:weight] != Issue::WEIGHT_ALL
end
def filter_by_no_weight?
......
......@@ -144,12 +144,12 @@ module IssuesHelper
end
def issues_weight_options_for_edit(selected = nil)
weights = issue_weights - [[Issue::WEIGHT_ANY] * 2]
weights = [[Issue::WEIGHT_NONE, nil]] + issue_weights(Issue::WEIGHT_RANGE.to_a)
options_for_select(weights, selected || params[:weight])
end
def issue_weights
Issue.weight_options.map {|op| [op] * 2}
def issue_weights(weight_array = Issue.weight_options)
weight_array.map {|op| [op] * 2}
end
# Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue
......
......@@ -30,6 +30,7 @@ class Issue < ActiveRecord::Base
include Elastic::IssuesSearch
WEIGHT_RANGE = 1..9
WEIGHT_ALL = 'Everything'
WEIGHT_ANY = 'Any Weight'
WEIGHT_NONE = 'No Weight'
......@@ -127,6 +128,6 @@ class Issue < ActiveRecord::Base
end
def self.weight_options
[WEIGHT_ANY, WEIGHT_NONE] + WEIGHT_RANGE.to_a
[WEIGHT_ALL, WEIGHT_ANY, WEIGHT_NONE] + WEIGHT_RANGE.to_a
end
end
......@@ -4,13 +4,12 @@ feature 'Issue filtering by Weight', feature: true do
include Select2Helper
let(:project) { create(:project, :public) }
let(:weight) { create(:weight, project: project) }
let(:weight_num) {random_weight}
before(:each) do
create(:issue, project: project, weight: nil)
create(:issue, project: project, weight: weight_num)
create(:issue, project: project, weight: random_weight)
create(:issue, project: project, weight: weight_num)
end
scenario 'filters by no Weight', js: true do
......@@ -24,14 +23,21 @@ feature 'Issue filtering by Weight', feature: true do
visit_issues(project)
filter_by_weight(Issue::WEIGHT_ANY)
expect(page).to have_css('.issue', count: 3)
expect(page).to have_css('.issue', count: 2)
end
scenario 'filters by a specific Weight', js: true do
visit_issues(project)
filter_by_weight(weight_num)
expect(page).to have_css('.issue', count: 1)
expect(page).to have_css('.issue', count: 2)
end
scenario 'all weights', js: true do
visit_issues(project)
filter_by_weight(Issue::WEIGHT_ALL)
expect(page).to have_css('.issue', count: 3)
end
def visit_issues(project)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment