Commit cf55dd8b authored by Sean McGivern's avatar Sean McGivern

Merge branch '47769-fix_ambiguous_due_date_for_issue_scopes' into 'master'

Fix ambiguous due_date column for Issue scopes

Closes #47769

See merge request gitlab-org/gitlab-ce!20251
parents 2dfddddd eb0d6551
......@@ -48,7 +48,7 @@ class Issue < ActiveRecord::Base
scope :unassigned, -> { where('NOT EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)') }
scope :assigned_to, ->(u) { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = ? AND issue_id = issues.id)', u.id)}
scope :with_due_date, -> { where('due_date IS NOT NULL') }
scope :with_due_date, -> { where.not(due_date: nil) }
scope :without_due_date, -> { where(due_date: nil) }
scope :due_before, ->(date) { where('issues.due_date < ?', date) }
scope :due_between, ->(from_date, to_date) { where('issues.due_date >= ?', from_date).where('issues.due_date <= ?', to_date) }
......@@ -56,7 +56,7 @@ class Issue < ActiveRecord::Base
scope :order_due_date_asc, -> { reorder('issues.due_date IS NULL, issues.due_date ASC') }
scope :order_due_date_desc, -> { reorder('issues.due_date IS NULL, issues.due_date DESC') }
scope :order_closest_future_date, -> { reorder('CASE WHEN due_date >= CURRENT_DATE THEN 0 ELSE 1 END ASC, ABS(CURRENT_DATE - due_date) ASC') }
scope :order_closest_future_date, -> { reorder('CASE WHEN issues.due_date >= CURRENT_DATE THEN 0 ELSE 1 END ASC, ABS(CURRENT_DATE - issues.due_date) ASC') }
scope :preload_associations, -> { preload(:labels, project: :namespace) }
......
---
title: Fix ambiguous due_date column for Issue scopes
merge_request:
author:
type: fixed
......@@ -5,6 +5,7 @@ describe 'Dashboard Issues Calendar Feed' do
let!(:user) { create(:user, email: 'private1@example.com', public_email: 'public1@example.com') }
let!(:assignee) { create(:user, email: 'private2@example.com', public_email: 'public2@example.com') }
let!(:project) { create(:project) }
let(:milestone) { create(:milestone, project_id: project.id, title: 'v1.0') }
before do
project.add_master(user)
......@@ -14,7 +15,9 @@ describe 'Dashboard Issues Calendar Feed' do
context 'with no referer' do
it 'renders calendar feed' do
sign_in user
visit issues_dashboard_path(:ics)
visit issues_dashboard_path(:ics,
due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
sort: 'closest_future_date')
expect(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR')
......@@ -25,19 +28,37 @@ describe 'Dashboard Issues Calendar Feed' do
it 'renders calendar feed as text/plain' do
sign_in user
page.driver.header('Referer', issues_dashboard_url(host: Settings.gitlab.base_url))
visit issues_dashboard_path(:ics)
visit issues_dashboard_path(:ics,
due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
sort: 'closest_future_date')
expect(response_headers['Content-Type']).to have_content('text/plain')
expect(body).to have_text('BEGIN:VCALENDAR')
end
end
context 'when filtered by milestone' do
it 'renders calendar feed' do
sign_in user
visit issues_dashboard_path(:ics,
due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
sort: 'closest_future_date',
milestone_title: milestone.title)
expect(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR')
end
end
end
context 'when authenticated via personal access token' do
it 'renders calendar feed' do
personal_access_token = create(:personal_access_token, user: user)
visit issues_dashboard_path(:ics, private_token: personal_access_token.token)
visit issues_dashboard_path(:ics,
due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
sort: 'closest_future_date',
private_token: personal_access_token.token)
expect(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR')
......@@ -46,7 +67,10 @@ describe 'Dashboard Issues Calendar Feed' do
context 'when authenticated via feed token' do
it 'renders calendar feed' do
visit issues_dashboard_path(:ics, feed_token: user.feed_token)
visit issues_dashboard_path(:ics,
due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
sort: 'closest_future_date',
feed_token: user.feed_token)
expect(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR')
......@@ -60,7 +84,10 @@ describe 'Dashboard Issues Calendar Feed' do
end
it 'renders issue fields' do
visit issues_dashboard_path(:ics, feed_token: user.feed_token)
visit issues_dashboard_path(:ics,
due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
sort: 'closest_future_date',
feed_token: user.feed_token)
expect(body).to have_text("SUMMARY:test title (in #{project.full_path})")
# line length for ics is 75 chars
......
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