diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-06-29 10:53:44 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-07-04 11:12:33 +0100 |
commit | a8a85e60aa5133730448f79f8ca83dd57c68fb25 (patch) | |
tree | c0a74cd45c9a2c22b230addc13bc2e5824c6cc31 | |
parent | 9b0fceb83758d33ef85c4a8c98c671e86e29304f (diff) | |
download | gitlab-ce-a8a85e60aa5133730448f79f8ca83dd57c68fb25.tar.gz |
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
-rw-r--r-- | app/models/issue.rb | 4 | ||||
-rw-r--r-- | changelogs/unreleased/47769-fix_ambiguous_due_date_for_issue_scopes.yml | 5 | ||||
-rw-r--r-- | spec/features/ics/dashboard_issues_spec.rb | 37 |
3 files changed, 39 insertions, 7 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index d136700836d..3a11c03940d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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) } diff --git a/changelogs/unreleased/47769-fix_ambiguous_due_date_for_issue_scopes.yml b/changelogs/unreleased/47769-fix_ambiguous_due_date_for_issue_scopes.yml new file mode 100644 index 00000000000..b8bb70b3266 --- /dev/null +++ b/changelogs/unreleased/47769-fix_ambiguous_due_date_for_issue_scopes.yml @@ -0,0 +1,5 @@ +--- +title: Fix ambiguous due_date column for Issue scopes +merge_request: +author: +type: fixed diff --git a/spec/features/ics/dashboard_issues_spec.rb b/spec/features/ics/dashboard_issues_spec.rb index 90d02f7e40f..a4d05c25a90 100644 --- a/spec/features/ics/dashboard_issues_spec.rb +++ b/spec/features/ics/dashboard_issues_spec.rb @@ -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 |