Commit eb0d6551 authored by Imre Farkas's avatar Imre Farkas

Fix ambiguous due_date column for Issue scopes

parent 63c64ab3
...@@ -48,7 +48,7 @@ class Issue < ActiveRecord::Base ...@@ -48,7 +48,7 @@ class Issue < ActiveRecord::Base
scope :unassigned, -> { where('NOT EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)') } 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 :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 :without_due_date, -> { where(due_date: nil) }
scope :due_before, ->(date) { where('issues.due_date < ?', date) } 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) } 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 ...@@ -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_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_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) } 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 ...@@ -5,6 +5,7 @@ describe 'Dashboard Issues Calendar Feed' do
let!(:user) { create(:user, email: 'private1@example.com', public_email: 'public1@example.com') } 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!(:assignee) { create(:user, email: 'private2@example.com', public_email: 'public2@example.com') }
let!(:project) { create(:project) } let!(:project) { create(:project) }
let(:milestone) { create(:milestone, project_id: project.id, title: 'v1.0') }
before do before do
project.add_master(user) project.add_master(user)
...@@ -14,7 +15,9 @@ describe 'Dashboard Issues Calendar Feed' do ...@@ -14,7 +15,9 @@ describe 'Dashboard Issues Calendar Feed' do
context 'with no referer' do context 'with no referer' do
it 'renders calendar feed' do it 'renders calendar feed' do
sign_in user 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(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR') expect(body).to have_text('BEGIN:VCALENDAR')
...@@ -25,19 +28,37 @@ describe 'Dashboard Issues Calendar Feed' do ...@@ -25,19 +28,37 @@ describe 'Dashboard Issues Calendar Feed' do
it 'renders calendar feed as text/plain' do it 'renders calendar feed as text/plain' do
sign_in user sign_in user
page.driver.header('Referer', issues_dashboard_url(host: Settings.gitlab.base_url)) 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(response_headers['Content-Type']).to have_content('text/plain')
expect(body).to have_text('BEGIN:VCALENDAR') expect(body).to have_text('BEGIN:VCALENDAR')
end end
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 end
context 'when authenticated via personal access token' do context 'when authenticated via personal access token' do
it 'renders calendar feed' do it 'renders calendar feed' do
personal_access_token = create(:personal_access_token, user: user) 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(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR') expect(body).to have_text('BEGIN:VCALENDAR')
...@@ -46,7 +67,10 @@ describe 'Dashboard Issues Calendar Feed' do ...@@ -46,7 +67,10 @@ describe 'Dashboard Issues Calendar Feed' do
context 'when authenticated via feed token' do context 'when authenticated via feed token' do
it 'renders calendar feed' 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(response_headers['Content-Type']).to have_content('text/calendar')
expect(body).to have_text('BEGIN:VCALENDAR') expect(body).to have_text('BEGIN:VCALENDAR')
...@@ -60,7 +84,10 @@ describe 'Dashboard Issues Calendar Feed' do ...@@ -60,7 +84,10 @@ describe 'Dashboard Issues Calendar Feed' do
end end
it 'renders issue fields' do 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})") expect(body).to have_text("SUMMARY:test title (in #{project.full_path})")
# line length for ics is 75 chars # 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