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
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