BigW Consortium Gitlab

users_spec.rb 2.33 KB
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe "User Feed", feature: true  do
  describe "GET /" do
    let!(:user) { create(:user) }

7
    context 'user atom feed via private token' do
8
      it "renders user atom feed" do
9
        visit user_path(user, :atom, private_token: user.private_token)
10
        expect(body).to have_selector('feed title')
11 12 13 14 15
      end
    end

    context 'feed content' do
      let(:project) { create(:project) }
16
      let(:issue) do
17 18 19 20
        create(:issue,
               project: project,
               author: user,
               description: "Houston, we have a bug!\n\n***\n\nI guess.")
21 22
      end
      let(:note) do
23 24 25 26 27
        create(:note,
               noteable: issue,
               author: user,
               note: 'Bug confirmed :+1:',
               project: project)
28 29 30
      end
      let(:merge_request) do
        create(:merge_request,
31 32 33 34
               title: 'Fix bug',
               author: user,
               source_project: project,
               target_project: project,
35
               description: "Here is the fix: ![an image](image.png)")
36
      end
37 38 39 40 41

      before do
        project.team << [user, :master]
        issue_event(issue, user)
        note_event(note, user)
42
        merge_request_event(merge_request, user)
43 44 45
        visit user_path(user, :atom, private_token: user.private_token)
      end

46
      it 'has issue opened event' do
47
        expect(body).to have_content("#{safe_name} opened issue ##{issue.iid}")
48 49
      end

50
      it 'has issue comment event' do
51 52
        expect(body).
          to have_content("#{safe_name} commented on issue ##{issue.iid}")
53
      end
54

55
      it 'has XHTML summaries in issue descriptions' do
56
        expect(body).to match /we have a bug!<\/p>\n\n<hr ?\/>\n\n<p dir="auto">I guess/
57 58
      end

59
      it 'has XHTML summaries in notes' do
60 61 62
        expect(body).to match /Bug confirmed <img[^>]*\/>/
      end

63
      it 'has XHTML summaries in merge request descriptions' do
64
        expect(body).to match /Here is the fix: <\/p><div[^>]*><a[^>]*><img[^>]*\/><\/a><\/div>/
65
      end
66 67 68 69 70 71 72 73 74 75
    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
76

77 78 79 80
  def merge_request_event(request, user)
    EventCreateService.new.open_mr(request, user)
  end

81
  def safe_name
82
    html_escape(user.name)
83
  end
84
end