Commit 7904c10c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ee-epics-by-timeframe' into 'master'

Allow to find epics by the given time frame

See merge request gitlab-org/gitlab-ee!4247
parents d97cd821 dad53553
class AddDateIndexesToEpics < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :epics, :start_date
add_concurrent_index :epics, :end_date
end
def down
remove_concurrent_index :epics, :start_date
remove_concurrent_index :epics, :end_date
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180115201419) do
ActiveRecord::Schema.define(version: 20180131104538) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -811,9 +811,11 @@ ActiveRecord::Schema.define(version: 20180115201419) do
add_index "epics", ["assignee_id"], name: "index_epics_on_assignee_id", using: :btree
add_index "epics", ["author_id"], name: "index_epics_on_author_id", using: :btree
add_index "epics", ["end_date"], name: "index_epics_on_end_date", using: :btree
add_index "epics", ["group_id"], name: "index_epics_on_group_id", using: :btree
add_index "epics", ["iid"], name: "index_epics_on_iid", using: :btree
add_index "epics", ["milestone_id"], name: "index_milestone", using: :btree
add_index "epics", ["start_date"], name: "index_epics_on_start_date", using: :btree
create_table "events", force: :cascade do |t|
t.integer "project_id"
......
......@@ -10,6 +10,7 @@ class EpicsFinder < IssuableFinder
items = by_created_at(items)
items = by_search(items)
items = by_author(items)
items = by_timeframe(items)
sort(items)
end
......@@ -48,4 +49,13 @@ class EpicsFinder < IssuableFinder
groups.select { |g| Ability.allowed?(current_user, :read_epic, g) }
end
end
def by_timeframe(items)
return items unless params[:start_date] && params[:end_date]
items
.where('epics.start_date is not NULL or epics.end_date is not NULL')
.where('epics.start_date is NULL or epics.start_date <= ?', params[:end_date].end_of_day)
.where('epics.end_date is NULL or epics.end_date >= ?', params[:start_date].beginning_of_day)
end
end
......@@ -6,8 +6,8 @@ describe EpicsFinder do
let(:group) { create(:group, :private) }
let(:another_group) { create(:group) }
let!(:epic1) { create(:epic, group: group, title: 'This is awesome epic', created_at: 1.week.ago) }
let!(:epic2) { create(:epic, group: group, created_at: 4.days.ago, author: user) }
let!(:epic3) { create(:epic, group: group, description: 'not so awesome') }
let!(:epic2) { create(:epic, group: group, created_at: 4.days.ago, author: user, start_date: 2.days.ago) }
let!(:epic3) { create(:epic, group: group, description: 'not so awesome', start_date: 5.days.ago, end_date: 3.days.ago) }
let!(:epic4) { create(:epic, group: another_group) }
describe '#execute' do
......@@ -89,6 +89,24 @@ describe EpicsFinder do
expect(epics).to contain_exactly(epic1, epic2, epic3, subepic1, subepic2)
end
end
context 'by timeframe' do
it 'returns epics which start in the timeframe' do
expect(epics(start_date: 2.days.ago, end_date: 1.day.ago)).to contain_exactly(epic2)
end
it 'returns epics which end in the timeframe' do
expect(epics(start_date: 4.days.ago, end_date: 3.days.ago)).to contain_exactly(epic3)
end
it 'returns epics which start before and end after the timeframe' do
expect(epics(start_date: 4.days.ago, end_date: 4.days.ago)).to contain_exactly(epic3)
end
it 'ignores epics which do not have start and end date set' do
expect(epics(start_date: 2.days.ago, end_date: 1.day.ago)).not_to include(epic1)
end
end
end
end
end
......
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