Skip to content

Commit

Permalink
feature(api): added file type and size
Browse files Browse the repository at this point in the history
https://jira.railsc.ru/browse/PC4-16800

Conflicts:
	app/models/apress/amazon_assets/concerns/base_asset.rb
	app/views/apress/amazon_assets/api/v1/assets/_asset.json.jbuilder
  • Loading branch information
deniskorobicyn committed Mar 22, 2016
1 parent 3a3c831 commit cf8ea04
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
22 changes: 22 additions & 0 deletions app/models/apress/amazon_assets/concerns/base_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ def copy_to_remote
end
end

# Public: Возвращает размер файла, либо с амазона, либо локальное.
#
# Returns Integer.
def file_size
if remote?
remote_file_size
else
local_file_size
end
end

# Public: Возвращает тип файла, либо с амазона, либо локальное.
#
# Returns String.
def file_content_type
if remote?
remote_content_type
else
local_content_type
end
end

# Подготовим имя файла
#
# Returns nothing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
json.(asset, :id, :origin_file_name)
json.(asset, :id, :origin_file_name, :file_size, :file_content_type)

json.file asset.file.to_s
8 changes: 5 additions & 3 deletions docs/api/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Status: 200
{
"asset": {
"id": 9999,
"file": "http://s3.amazonaws.com/pulscen_production/public_assets/000/000/185/2fc7__sports-q-c-1920-1895-3.jpg",
"origin_file_name": "sports-q-c-1920-1895-3.jpg"
"id": 185,
"file": "http://s3.amazonaws.com/pulscen_development/public_assets/000/000/185/2fc7__sports-q-c-1920-1895-3.jpg",
"origin_file_name": "sports-q-c-1920-1895-3.jpg",
"file_size": 395316,
"file_content_type": "image/jpeg"
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,63 @@ def self.valid_content_types

it { expect(subject.file_name).to eq subject.remote_file_name }
end

describe '#file_content_type' do
let(:file) { File.new('spec/fixtures/assets/test.png') }

context 'with both files' do
before do
subject.local = file
subject.remote = file
end

it { expect(subject.file_content_type).to eq 'image/png' }
end

context 'with local file only' do
before do
subject.local = file
end

it { expect(subject.file_content_type).to eq 'image/png' }
end

context 'with remote file only' do
before do
subject.local = file
end

it { expect(subject.file_content_type).to eq 'image/png' }
end
end

describe '#file_size' do
let(:file) { File.new('spec/fixtures/assets/test.png') }

context 'with both files' do
before do
subject.local = file
subject.remote = file
end

it { expect(subject.file_size).to eq 827 }
end

context 'with local file only' do
before do
subject.local = file
end

it { expect(subject.file_size).to eq 827 }
end

context 'with remote file only' do
before do
subject.local = file
end

it { expect(subject.file_size).to eq 827 }
end
end
end

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
id
file
origin_file_name
file_size
file_content_type
),
id: {type: 'integer'},
file: {type: 'string'},
origin_file_name: {type: 'string'}
origin_file_name: {type: 'string'},
file_size: {type: 'integer'},
file_content_type: {type: 'string'}
}
}
}.with_indifferent_access
Expand Down

0 comments on commit cf8ea04

Please sign in to comment.