views: refactor the attachment/edit view
Make it more reusable, by: - Renaming `attachment/update` to `attachment/edit` - Refactoring the CSS styles into their own stylesheet - Allow to specify the 'accept' option
This commit is contained in:
parent
5be83bd01e
commit
1c61f2de58
12 changed files with 66 additions and 57 deletions
|
@ -2,33 +2,37 @@ require 'rails_helper'
|
|||
|
||||
describe 'shared/attachment/_update.html.haml', type: :view do
|
||||
let(:champ) { build(:champ_piece_justificative, dossier: create(:dossier)) }
|
||||
let(:attachment) { nil }
|
||||
let(:virus_scan_result) { nil }
|
||||
let(:attached_file) { champ.piece_justificative_file }
|
||||
let(:user_can_destroy) { false }
|
||||
|
||||
subject do
|
||||
form_for(champ.dossier) do |form|
|
||||
render 'shared/attachment/update', {
|
||||
attachment: attachment,
|
||||
user_can_destroy: user_can_destroy,
|
||||
form: form
|
||||
render 'shared/attachment/edit', {
|
||||
form: form,
|
||||
attached_file: attached_file,
|
||||
accept: 'image/png',
|
||||
user_can_destroy: user_can_destroy
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'renders a form field for uploading a file' do
|
||||
expect(subject).to have_selector('input[type=file]:not(.hidden)')
|
||||
context 'when there is no attached file' do
|
||||
before do
|
||||
champ.piece_justificative_file.purge
|
||||
end
|
||||
|
||||
it 'renders a form field for uploading a file' do
|
||||
expect(subject).to have_selector('input[type=file]:not(.hidden)')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is a attached file' do
|
||||
let(:attachment) { champ.piece_justificative_file.attachment }
|
||||
|
||||
it 'renders a form field for uploading a file' do
|
||||
expect(subject).to have_selector('input[type=file]:not(.hidden)')
|
||||
end
|
||||
|
||||
it 'does not renders a link to the unsaved file' do
|
||||
expect(subject).not_to have_content(attachment.filename.to_s)
|
||||
expect(subject).not_to have_content(attached_file.filename.to_s)
|
||||
end
|
||||
|
||||
it 'doesn’t render action buttons' do
|
||||
|
@ -40,7 +44,7 @@ describe 'shared/attachment/_update.html.haml', type: :view do
|
|||
before { champ.save! }
|
||||
|
||||
it 'renders a link to the file' do
|
||||
expect(subject).to have_content(attachment.filename.to_s)
|
||||
expect(subject).to have_content(attached_file.filename.to_s)
|
||||
end
|
||||
|
||||
it 'renders action buttons' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue