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 ...@@ -268,17 +268,19 @@ class IssuableFinder
end end
def by_weight(items) def by_weight(items)
return items if filter_by_any_weight? || !weights? return items unless weights?
if filter_by_no_weight? if filter_by_no_weight?
items.where(weight: [-1, nil]) items.where(weight: [-1, nil])
elsif filter_by_any_weight?
items.where.not(weight: [-1, nil])
else else
items.where(weight: params[:weight]) items.where(weight: params[:weight])
end end
end end
def weights? def weights?
params[:weight].present? params[:weight].present? && params[:weight] != Issue::WEIGHT_ALL
end end
def filter_by_no_weight? def filter_by_no_weight?
......
...@@ -144,12 +144,12 @@ module IssuesHelper ...@@ -144,12 +144,12 @@ module IssuesHelper
end end
def issues_weight_options_for_edit(selected = nil) 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]) options_for_select(weights, selected || params[:weight])
end end
def issue_weights def issue_weights(weight_array = Issue.weight_options)
Issue.weight_options.map {|op| [op] * 2} weight_array.map {|op| [op] * 2}
end end
# Required for Banzai::Filter::IssueReferenceFilter # Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue module_function :url_for_issue
......
...@@ -30,6 +30,7 @@ class Issue < ActiveRecord::Base ...@@ -30,6 +30,7 @@ class Issue < ActiveRecord::Base
include Elastic::IssuesSearch include Elastic::IssuesSearch
WEIGHT_RANGE = 1..9 WEIGHT_RANGE = 1..9
WEIGHT_ALL = 'Everything'
WEIGHT_ANY = 'Any Weight' WEIGHT_ANY = 'Any Weight'
WEIGHT_NONE = 'No Weight' WEIGHT_NONE = 'No Weight'
...@@ -127,6 +128,6 @@ class Issue < ActiveRecord::Base ...@@ -127,6 +128,6 @@ class Issue < ActiveRecord::Base
end end
def self.weight_options def self.weight_options
[WEIGHT_ANY, WEIGHT_NONE] + WEIGHT_RANGE.to_a [WEIGHT_ALL, WEIGHT_ANY, WEIGHT_NONE] + WEIGHT_RANGE.to_a
end end
end end
...@@ -4,13 +4,12 @@ feature 'Issue filtering by Weight', feature: true do ...@@ -4,13 +4,12 @@ feature 'Issue filtering by Weight', feature: true do
include Select2Helper include Select2Helper
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let(:weight) { create(:weight, project: project) }
let(:weight_num) {random_weight} let(:weight_num) {random_weight}
before(:each) do before(:each) do
create(:issue, project: project, weight: nil) create(:issue, project: project, weight: nil)
create(:issue, project: project, weight: weight_num) create(:issue, project: project, weight: weight_num)
create(:issue, project: project, weight: random_weight) create(:issue, project: project, weight: weight_num)
end end
scenario 'filters by no Weight', js: true do scenario 'filters by no Weight', js: true do
...@@ -24,14 +23,21 @@ feature 'Issue filtering by Weight', feature: true do ...@@ -24,14 +23,21 @@ feature 'Issue filtering by Weight', feature: true do
visit_issues(project) visit_issues(project)
filter_by_weight(Issue::WEIGHT_ANY) filter_by_weight(Issue::WEIGHT_ANY)
expect(page).to have_css('.issue', count: 3) expect(page).to have_css('.issue', count: 2)
end end
scenario 'filters by a specific Weight', js: true do scenario 'filters by a specific Weight', js: true do
visit_issues(project) visit_issues(project)
filter_by_weight(weight_num) 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 end
def visit_issues(project) 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