dashboard_issues_spec.rb 4.19 KB
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe 'Dashboard Issues Calendar Feed'  do
  describe 'GET /issues' 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) }
8
    let(:milestone) { create(:milestone, project_id: project.id, title: 'v1.0') }
9 10 11 12 13 14

    before do
      project.add_master(user)
    end

    context 'when authenticated' do
15 16 17
      context 'with no referer' do
        it 'renders calendar feed' do
          sign_in user
18 19 20
          visit issues_dashboard_path(:ics,
                                      due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
                                      sort: 'closest_future_date')
21

22 23 24 25 26 27 28 29 30
          expect(response_headers['Content-Type']).to have_content('text/calendar')
          expect(body).to have_text('BEGIN:VCALENDAR')
        end
      end

      context 'with GitLab as the referer' do
        it 'renders calendar feed as text/plain' do
          sign_in user
          page.driver.header('Referer', issues_dashboard_url(host: Settings.gitlab.base_url))
31 32 33
          visit issues_dashboard_path(:ics,
                                      due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
                                      sort: 'closest_future_date')
34 35 36 37

          expect(response_headers['Content-Type']).to have_content('text/plain')
          expect(body).to have_text('BEGIN:VCALENDAR')
        end
38
      end
39 40 41 42 43 44 45 46 47 48 49 50 51

      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
52 53 54 55 56 57
    end

    context 'when authenticated via personal access token' do
      it 'renders calendar feed' do
        personal_access_token = create(:personal_access_token, user: user)

58 59 60 61
        visit issues_dashboard_path(:ics,
                                    due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
                                    sort: 'closest_future_date',
                                    private_token: personal_access_token.token)
62 63 64 65 66 67 68 69

        expect(response_headers['Content-Type']).to have_content('text/calendar')
        expect(body).to have_text('BEGIN:VCALENDAR')
      end
    end

    context 'when authenticated via feed token' do
      it 'renders calendar feed' do
70 71 72 73
        visit issues_dashboard_path(:ics,
                                    due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
                                    sort: 'closest_future_date',
                                    feed_token: user.feed_token)
74 75 76 77 78 79 80 81 82 83 84 85 86

        expect(response_headers['Content-Type']).to have_content('text/calendar')
        expect(body).to have_text('BEGIN:VCALENDAR')
      end
    end

    context 'issue with due date' do
      let!(:issue) do
        create(:issue, author: user, assignees: [assignee], project: project, title: 'test title',
                       description: 'test desc', due_date: Date.tomorrow)
      end

      it 'renders issue fields' do
87 88 89 90
        visit issues_dashboard_path(:ics,
                                    due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name,
                                    sort: 'closest_future_date',
                                    feed_token: user.feed_token)
91 92 93 94 95 96 97 98 99 100 101 102

        expect(body).to have_text("SUMMARY:test title (in #{project.full_path})")
        # line length for ics is 75 chars
        expected_description = "DESCRIPTION:Find out more at #{issue_url(issue)}".insert(75, "\r\n")
        expect(body).to have_text(expected_description)
        expect(body).to have_text("DTSTART;VALUE=DATE:#{Date.tomorrow.strftime('%Y%m%d')}")
        expect(body).to have_text("URL:#{issue_url(issue)}")
        expect(body).to have_text('TRANSP:TRANSPARENT')
      end
    end
  end
end