Commit 06e7bcf8 authored by Igor Drozdov's avatar Igor Drozdov

Add size attribute to BlobEntity

parent 92490c32
...@@ -89,6 +89,14 @@ class DiffFileBaseEntity < Grape::Entity ...@@ -89,6 +89,14 @@ class DiffFileBaseEntity < Grape::Entity
expose :viewer, using: DiffViewerEntity 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 private
def memoized_submodule_links(diff_file, options) def memoized_submodule_links(diff_file, options)
......
...@@ -15,8 +15,16 @@ describe BlobEntity do ...@@ -15,8 +15,16 @@ describe BlobEntity do
context 'as json' do context 'as json' do
subject { entity.as_json } subject { entity.as_json }
it 'exposes needed attributes' do it 'contains needed attributes' do
expect(subject).to include(:readable_text, :url) 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 end
end end
...@@ -5,15 +5,15 @@ require 'spec_helper' ...@@ -5,15 +5,15 @@ require 'spec_helper'
describe DiffFileBaseEntity do describe DiffFileBaseEntity do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:repository) { project.repository } let(:repository) { project.repository }
let(:entity) { described_class.new(diff_file, options).as_json }
context 'diff for a changed submodule' do context 'diff for a changed submodule' do
let(:commit_sha_with_changed_submodule) do let(:commit_sha_with_changed_submodule) do
"cfe32cf61b73a0d5e9f13e774abde7ff789b1660" "cfe32cf61b73a0d5e9f13e774abde7ff789b1660"
end end
let(:commit) { project.commit(commit_sha_with_changed_submodule) } 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(: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 it do
expect(entity[:submodule]).to eq(true) expect(entity[:submodule]).to eq(true)
...@@ -23,4 +23,15 @@ describe DiffFileBaseEntity do ...@@ -23,4 +23,15 @@ describe DiffFileBaseEntity do
) )
end end
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 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