Commit f0a2c411 authored by Rémy Coutable's avatar Rémy Coutable

Allow IssuableFinder to filter by closed_at

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent deca6688
...@@ -94,6 +94,7 @@ class IssuableFinder ...@@ -94,6 +94,7 @@ class IssuableFinder
items = by_scope(items) items = by_scope(items)
items = by_created_at(items) items = by_created_at(items)
items = by_updated_at(items) items = by_updated_at(items)
items = by_closed_at(items)
items = by_state(items) items = by_state(items)
items = by_group(items) items = by_group(items)
items = by_assignee(items) items = by_assignee(items)
...@@ -353,6 +354,13 @@ class IssuableFinder ...@@ -353,6 +354,13 @@ class IssuableFinder
items items
end end
def by_closed_at(items)
items = items.closed_after(params[:closed_after]) if params[:closed_after].present?
items = items.closed_before(params[:closed_before]) if params[:closed_before].present?
items
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def by_state(items) def by_state(items)
case params[:state].to_s case params[:state].to_s
......
# frozen_string_literal: true
module ClosedAtFilterable
extend ActiveSupport::Concern
included do
scope :closed_before, ->(date) { where(scoped_table[:closed_at].lteq(date)) }
scope :closed_after, ->(date) { where(scoped_table[:closed_at].gteq(date)) }
def self.scoped_table
arel_table.alias(table_name)
end
end
end
...@@ -23,6 +23,7 @@ module Issuable ...@@ -23,6 +23,7 @@ module Issuable
include Sortable include Sortable
include CreatedAtFilterable include CreatedAtFilterable
include UpdatedAtFilterable include UpdatedAtFilterable
include ClosedAtFilterable
# This object is used to gather issuable meta data for displaying # This object is used to gather issuable meta data for displaying
# upvotes, downvotes, notes and closing merge requests count for issues and merge requests # upvotes, downvotes, notes and closing merge requests count for issues and merge requests
......
...@@ -416,6 +416,36 @@ describe IssuesFinder do ...@@ -416,6 +416,36 @@ describe IssuesFinder do
end end
end end
context 'filtering by closed_at' do
let!(:closed_issue1) { create(:issue, project: project1, state: :closed, closed_at: 1.week.ago) }
let!(:closed_issue2) { create(:issue, project: project2, state: :closed, closed_at: 1.week.from_now) }
let!(:closed_issue3) { create(:issue, project: project2, state: :closed, closed_at: 2.weeks.from_now) }
context 'through closed_after' do
let(:params) { { state: :closed, closed_after: closed_issue3.closed_at } }
it 'returns issues closed on or after the given date' do
expect(issues).to contain_exactly(closed_issue3)
end
end
context 'through closed_before' do
let(:params) { { state: :closed, closed_before: closed_issue1.closed_at } }
it 'returns issues closed on or before the given date' do
expect(issues).to contain_exactly(closed_issue1)
end
end
context 'through closed_after and closed_before' do
let(:params) { { state: :closed, closed_after: closed_issue2.closed_at, closed_before: closed_issue3.closed_at } }
it 'returns issues closed between the given dates' do
expect(issues).to contain_exactly(closed_issue2, closed_issue3)
end
end
end
context 'filtering by reaction name' do context 'filtering by reaction name' do
context 'user searches by no reaction' do context 'user searches by no reaction' do
let(:params) { { my_reaction_emoji: 'None' } } let(:params) { { my_reaction_emoji: 'None' } }
......
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