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.
36 lines
923 B
Ruby
36 lines
923 B
Ruby
require "rails_helper"
|
|
|
|
describe "Documents", :admin do
|
|
context "Index" do
|
|
scenario "Answer with no documents" do
|
|
answer = create(:poll_question_answer)
|
|
document = create(:document)
|
|
|
|
visit admin_answer_documents_path(answer)
|
|
|
|
expect(page).not_to have_content(document.title)
|
|
end
|
|
|
|
scenario "Answer with documents" do
|
|
answer = create(:poll_question_answer)
|
|
document = create(:document, documentable: answer)
|
|
|
|
visit admin_answer_documents_path(answer)
|
|
|
|
expect(page).to have_content(document.title)
|
|
end
|
|
end
|
|
|
|
scenario "Remove document from answer", :js do
|
|
answer = create(:poll_question_answer)
|
|
document = create(:document, documentable: answer)
|
|
|
|
visit admin_answer_documents_path(answer)
|
|
expect(page).to have_content(document.title)
|
|
|
|
accept_confirm { click_link "Delete" }
|
|
|
|
expect(page).not_to have_content(document.title)
|
|
end
|
|
end
|