Commit bd0f9d01 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'id-add-raw-size-to-blob-entity' into 'master'

Add size attribute to BlobEntity

See merge request gitlab-org/gitlab!18959
parents 81adce38 06e7bcf8
......@@ -89,6 +89,14 @@ class DiffFileBaseEntity < Grape::Entity
expose :viewer, using: DiffViewerEntity
expose :old_size do |diff_file|
diff_file.old_blob&.raw_size
end
expose :new_size do |diff_file|
diff_file.new_blob&.raw_size
end
private
def memoized_submodule_links(diff_file, options)
......
......@@ -15,8 +15,16 @@ describe BlobEntity do
context 'as json' do
subject { entity.as_json }
it 'exposes needed attributes' do
expect(subject).to include(:readable_text, :url)
it 'contains needed attributes' do
expect(subject).to include({
id: blob.id,
path: blob.path,
name: blob.name,
mode: "100644",
readable_text: true,
icon: "file-text-o",
url: "/#{project.full_path}/blob/master/bar/branch-test.txt"
})
end
end
end
......@@ -5,15 +5,15 @@ require 'spec_helper'
describe DiffFileBaseEntity do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:entity) { described_class.new(diff_file, options).as_json }
context 'diff for a changed submodule' do
let(:commit_sha_with_changed_submodule) do
"cfe32cf61b73a0d5e9f13e774abde7ff789b1660"
end
let(:commit) { project.commit(commit_sha_with_changed_submodule) }
let(:diff_file) { commit.diffs.diff_files.to_a.last }
let(:options) { { request: {}, submodule_links: Gitlab::SubmoduleLinks.new(repository) } }
let(:entity) { described_class.new(diff_file, options).as_json }
let(:diff_file) { commit.diffs.diff_files.to_a.last }
it do
expect(entity[:submodule]).to eq(true)
......@@ -23,4 +23,15 @@ describe DiffFileBaseEntity do
)
end
end
context 'contains raw sizes for the blob' do
let(:commit) { project.commit('png-lfs') }
let(:options) { { request: {} } }
let(:diff_file) { commit.diffs.diff_files.to_a.second }
it do
expect(entity[:old_size]).to eq(1219696)
expect(entity[:new_size]).to eq(132)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment