BigW Consortium Gitlab

users_spec.rb 2.84 KB
Newer Older
1 2
require 'spec_helper'

3
describe "User Feed"  do
4 5 6
  describe "GET /" do
    let!(:user) { create(:user) }

7
    context 'user atom feed via personal access token' do
8
      it "renders user atom feed" do
9 10 11
        personal_access_token = create(:personal_access_token, user: user)

        visit user_path(user, :atom, private_token: personal_access_token.token)
12
        expect(body).to have_selector('feed title')
13 14 15
      end
    end

16
    context 'user atom feed via RSS token' do
17 18 19 20 21 22
      it "renders user atom feed" do
        visit user_path(user, :atom, rss_token: user.rss_token)
        expect(body).to have_selector('feed title')
      end
    end

23
    context 'feed content' do
24
      let(:project) { create(:project, :repository) }
25
      let(:issue) do
26 27 28 29
        create(:issue,
               project: project,
               author: user,
               description: "Houston, we have a bug!\n\n***\n\nI guess.")
30 31
      end
      let(:note) do
32 33 34 35 36
        create(:note,
               noteable: issue,
               author: user,
               note: 'Bug confirmed :+1:',
               project: project)
37 38 39
      end
      let(:merge_request) do
        create(:merge_request,
40 41 42 43
               title: 'Fix bug',
               author: user,
               source_project: project,
               target_project: project,
44
               description: "Here is the fix: ![an image](image.png)")
45
      end
46 47
      let(:push_event) { create(:push_event, project: project, author: user) }
      let!(:push_event_payload) { create(:push_event_payload, event: push_event) }
48 49

      before do
50
        project.add_master(user)
51 52
        issue_event(issue, user)
        note_event(note, user)
53
        merge_request_event(merge_request, user)
54
        visit user_path(user, :atom, rss_token: user.rss_token)
55 56
      end

57
      it 'has issue opened event' do
58
        expect(body).to have_content("#{safe_name} opened issue ##{issue.iid}")
59 60
      end

61
      it 'has issue comment event' do
62 63
        expect(body)
          .to have_content("#{safe_name} commented on issue ##{issue.iid}")
64
      end
65

66
      it 'has XHTML summaries in issue descriptions' do
67
        expect(body).to match /<hr ?\/>/
68 69
      end

70
      it 'has XHTML summaries in notes' do
71
        expect(body).to match /Bug confirmed <gl-emoji[^>]*>/
72 73
      end

74
      it 'has XHTML summaries in merge request descriptions' do
75
        expect(body).to match /Here is the fix: <a[^>]*><img[^>]*\/><\/a>/
76
      end
77 78 79 80

      it 'has push event commit ID' do
        expect(body).to have_content(Commit.truncate_sha(push_event.commit_id))
      end
81 82 83 84 85 86 87 88 89 90
    end
  end

  def issue_event(issue, user)
    EventCreateService.new.open_issue(issue, user)
  end

  def note_event(note, user)
    EventCreateService.new.leave_note(note, user)
  end
91

92 93 94 95
  def merge_request_event(request, user)
    EventCreateService.new.open_mr(request, user)
  end

96
  def safe_name
97
    html_escape(user.name)
98
  end
99
end