4cb747fdb6
Test helpers are separated between two files: spec_helper and rails_helper. This separation is meant to allow tests that do not require Rails (like testing standalone libs) to boot faster. The spec_helper file is always loaded, through `--require spec_helper` in the `.rspec` config file. When needed, the rails_helper file is expected to be required manually. This is fine, but: - Many test files have a redundant `require 'spec_helper'` line; - Many test files should require `rails_helper`, but don't. Not requiring `rails_helper` will cause the Rails-concerned section of the test environment not to be configured–which may cause subtle bugs (like the test database not being properly initialized). Moreover, Spring loads all the Rails files on preloading anyway. So the gains from using only `spec_helper` are thin. To streamline this process, this commit: - Configures `.rspec` to require `rails_helper` by default; - Remove all manual requires to spec_helper or rails_helper. Reference: https://stackoverflow.com/questions/24145329/how-is-spec-rails-helper-rb-different-from-spec-spec-helper-rb-do-i-need-it
67 lines
1.9 KiB
Ruby
67 lines
1.9 KiB
Ruby
describe 'shared/attachment/_update.html.haml', type: :view do
|
||
let(:champ) { build(:champ_piece_justificative, dossier: create(:dossier)) }
|
||
let(:attached_file) { champ.piece_justificative_file }
|
||
let(:user_can_destroy) { false }
|
||
|
||
subject do
|
||
form_for(champ.dossier) do |form|
|
||
render 'shared/attachment/edit', {
|
||
form: form,
|
||
attached_file: attached_file,
|
||
accept: 'image/png',
|
||
user_can_destroy: user_can_destroy
|
||
}
|
||
end
|
||
end
|
||
|
||
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
|
||
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(attached_file.filename.to_s)
|
||
end
|
||
|
||
it 'doesn’t render action buttons' do
|
||
expect(subject).not_to have_link('Remplacer')
|
||
expect(subject).not_to have_link('Supprimer')
|
||
end
|
||
|
||
context 'and the attachment has been saved' do
|
||
before { champ.save! }
|
||
|
||
it 'renders a link to the file' do
|
||
expect(subject).to have_content(attached_file.filename.to_s)
|
||
end
|
||
|
||
it 'renders action buttons' do
|
||
expect(subject).to have_button('Remplacer')
|
||
end
|
||
|
||
it 'hides the form field by default' do
|
||
expect(subject).to have_selector('input[type=file].hidden')
|
||
end
|
||
|
||
it 'hides the Delete button by default' do
|
||
is_expected.not_to have_link('Supprimer')
|
||
end
|
||
|
||
context 'and the user can delete the attachment' do
|
||
let(:user_can_destroy) { true }
|
||
|
||
it { is_expected.to have_link('Supprimer') }
|
||
end
|
||
end
|
||
end
|
||
end
|