diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-12-04 20:17:10 -0200 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-12-06 17:07:49 -0800 |
commit | 26b94bcc7d510482eea253b02dcc4ff22c48d68a (patch) | |
tree | 68a0f8dddb009b03af5de530fe4feb94a289dc6d /spec/support/shared_examples/serializers | |
parent | 9a78524f465488b2b5daa3fbdb2ec7c71c9641a6 (diff) | |
download | gitlab-ce-26b94bcc7d510482eea253b02dcc4ff22c48d68a.tar.gz |
Remove unused data from discussions endpoint
We don't need a series of attributes to render diff files on
discussions.json request. Therefore this MR removes lots of unnecessary
attributes from the request, mainly the highlighted diff lines, which
are pretty expensive.
Diffstat (limited to 'spec/support/shared_examples/serializers')
-rw-r--r-- | spec/support/shared_examples/serializers/diff_file_entity_examples.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/support/shared_examples/serializers/diff_file_entity_examples.rb b/spec/support/shared_examples/serializers/diff_file_entity_examples.rb new file mode 100644 index 00000000000..b8065886c42 --- /dev/null +++ b/spec/support/shared_examples/serializers/diff_file_entity_examples.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +shared_examples 'diff file base entity' do + it 'exposes essential attributes' do + expect(subject).to include(:content_sha, :submodule, :submodule_link, + :submodule_tree_url, :old_path_html, + :new_path_html, :blob, :can_modify_blob, + :file_hash, :file_path, :old_path, :new_path, + :collapsed, :text, :diff_refs, :stored_externally, + :external_storage, :renamed_file, :deleted_file, + :mode_changed, :a_mode, :b_mode, :new_file) + end + + # Converted diff files from GitHub import does not contain blob file + # and content sha. + context 'when diff file does not have a blob and content sha' do + it 'exposes some attributes as nil' do + allow(diff_file).to receive(:content_sha).and_return(nil) + allow(diff_file).to receive(:blob).and_return(nil) + + expect(subject[:context_lines_path]).to be_nil + expect(subject[:view_path]).to be_nil + expect(subject[:highlighted_diff_lines]).to be_nil + expect(subject[:can_modify_blob]).to be_nil + end + end +end + +shared_examples 'diff file entity' do + it_behaves_like 'diff file base entity' + + it 'exposes correct attributes' do + expect(subject).to include(:too_large, :added_lines, :removed_lines, + :context_lines_path, :highlighted_diff_lines, + :parallel_diff_lines) + end + + it 'includes viewer' do + expect(subject[:viewer].with_indifferent_access) + .to match_schema('entities/diff_viewer') + end +end + +shared_examples 'diff file discussion entity' do + it_behaves_like 'diff file base entity' +end |