[Fix #1865] Expose attachment field over API
This commit is contained in:
parent
fe0aafdd44
commit
5b9f25271f
3 changed files with 34 additions and 0 deletions
|
@ -1,5 +1,15 @@
|
|||
class ChampSerializer < ActiveModel::Serializer
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
attributes :value
|
||||
|
||||
has_one :type_de_champ
|
||||
|
||||
def value
|
||||
if object.piece_justificative_file.attached?
|
||||
url_for(object.piece_justificative_file)
|
||||
else
|
||||
object.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,6 +31,8 @@ Rails.application.configure do
|
|||
# ActionMailer::Base.deliveries array.
|
||||
config.action_mailer.delivery_method = :test
|
||||
|
||||
config.active_storage.service = :local
|
||||
|
||||
# Randomize the order test cases are executed.
|
||||
config.active_support.test_order = :random
|
||||
|
||||
|
|
22
spec/serializers/champ_serializer_spec.rb
Normal file
22
spec/serializers/champ_serializer_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
describe ChampSerializer do
|
||||
describe '#attributes' do
|
||||
subject { ChampSerializer.new(champ).serializable_hash }
|
||||
|
||||
context 'when type champ is piece justificative' do
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
let(:champ) { create(:champ, type_de_champ: create(:type_de_champ_piece_justificative)) }
|
||||
|
||||
before { champ.piece_justificative_file.attach({ filename: __FILE__, io: File.open(__FILE__) }) }
|
||||
after { champ.piece_justificative_file.purge }
|
||||
|
||||
it { is_expected.to include(value: url_for(champ.piece_justificative_file)) }
|
||||
end
|
||||
|
||||
context 'when type champ is not piece justificative' do
|
||||
let(:champ) { create(:champ, value: "blah") }
|
||||
|
||||
it { is_expected.to include(value: "blah") }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue