Simplify tests requiring admin login

We were repeating the same code over and over (with a few variants) to
setup tests which require an administrator. We can use a tag and
simplify the code.
This commit is contained in:
Javi Martín
2020-11-20 21:54:18 +01:00
parent 64205ab15f
commit 3da4ee00b8
82 changed files with 110 additions and 468 deletions

View File

@@ -1,13 +1,10 @@
shared_examples "documentable" do |documentable_factory_name, documentable_path, documentable_path_arguments|
let(:administrator) { create(:user) }
let(:user) { create(:user) }
let(:arguments) { {} }
let(:documentable) { create(documentable_factory_name, author: user) }
let!(:document) { create(:document, documentable: documentable, user: documentable.author) }
before do
create(:administrator, user: administrator)
documentable_path_arguments.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": documentable.send(path_to_value))
end
@@ -46,8 +43,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
expect(page).to have_link("Delete document")
end
scenario "Administrators cannot destroy documentables they have not authored" do
login_as(administrator)
scenario "Administrators cannot destroy documentables they have not authored", :admin do
visit send(documentable_path, arguments)
expect(page).not_to have_link("Delete document")