Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diff_line_entity_spec.rb « serializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 862b06c800acde7d6c78773ccb0ba08c61ce922f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe DiffLineEntity do
  include RepoHelpers

  let(:code) { 'hello world' }
  let(:line) { Gitlab::Diff::Line.new(code, 'new', 1, nil, 1) }
  let(:entity) { described_class.new(line, request: {}) }

  subject { entity.as_json }

  it 'exposes correct attributes' do
    expect(subject).to include(
      :line_code, :type, :old_line, :new_line, :text, :meta_data, :rich_text
    )
  end

  describe '#rich_text' do
    let(:code) { '<h2 onmouseover="alert(2)">Test</h2>' }
    let(:rich_text_value) { nil }

    before do
      line.instance_variable_set(:@rich_text, rich_text_value)
    end

    shared_examples 'escapes html tags' do
      it do
        expect(subject[:rich_text]).to eq html_escape(code)
        expect(subject[:rich_text]).to be_html_safe
      end
    end

    context 'when rich_line is present' do
      let(:rich_text_value) { code }

      it_behaves_like 'escapes html tags'
    end

    context 'when rich_line is not present' do
      it_behaves_like 'escapes html tags'
    end
  end
end