Files
nairobi/spec/system/admin/poll/questions/answers/images/images_spec.rb
Javi Martín d050c04bb0 Use a button to destroy poll question answer images
As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST (or, in this case, DELETE) requests to
the server has a few issues.

Note that the AJAX response stopped working after replacing the link
with a button. Not sure about the reason, but, since this is one of the
very few places where we use AJAX calls to delete content, the easiest
solution is to stop using AJAX and be consistent with what we do in the
rest of the admin section.
2024-04-17 16:44:10 +02:00

96 lines
3.0 KiB
Ruby

require "rails_helper"
describe "Images", :admin do
let(:future_poll) { create(:poll, :future) }
let(:current_poll) { create(:poll) }
it_behaves_like "nested imageable",
"future_poll_question_answer",
"new_admin_answer_image_path",
{ answer_id: "id" },
nil,
"Save image",
"Image uploaded successfully",
true
context "Index" do
scenario "Answer with no images" do
answer = create(:poll_question_answer)
visit admin_answer_images_path(answer)
expect(page).not_to have_css("img[title='']")
end
scenario "Answer with images" do
answer = create(:poll_question_answer)
image = create(:image, imageable: answer)
visit admin_answer_images_path(answer)
expect(page).to have_css("img[title='#{image.title}']")
expect(page).to have_content(image.title)
end
end
describe "Add image to answer" do
scenario "Is possible for a not started poll" do
answer = create(:poll_question_answer, poll: future_poll)
visit admin_answer_images_path(answer)
expect(page).not_to have_css "img[title='clippy.jpg']"
expect(page).not_to have_content "clippy.jpg"
click_link "Add image"
expect(page).to have_content "Descriptive image"
imageable_attach_new_file(file_fixture("clippy.jpg"))
click_button "Save image"
expect(page).to have_content "Image uploaded successfully"
expect(page).to have_css "img[title='clippy.jpg']"
expect(page).to have_content "clippy.jpg"
end
scenario "Is not possible for an already started poll" do
answer = create(:poll_question_answer, poll: current_poll)
visit admin_answer_images_path(answer)
expect(page).not_to have_link "Add image"
expect(page).to have_content "Once the poll has started it will not be possible to create, edit or"
end
end
describe "Remove image from answer" do
scenario "Is possible for a not started poll" do
answer = create(:poll_question_answer, poll: future_poll)
image = create(:image, imageable: answer)
visit admin_answer_images_path(answer)
expect(page).to have_css "img[title='#{image.title}']"
expect(page).to have_content image.title
accept_confirm "Are you sure? Remove image \"#{image.title}\"" do
click_button "Remove image"
end
expect(page).not_to have_css "img[title='#{image.title}']"
expect(page).not_to have_content image.title
end
scenario "Is not possible for an already started poll" do
answer = create(:poll_question_answer, poll: current_poll)
image = create(:image, imageable: answer)
visit admin_answer_images_path(answer)
expect(page).to have_css "img[title='#{image.title}']"
expect(page).to have_content image.title
expect(page).not_to have_content "Remove image"
expect(page).to have_content "Once the poll has started it will not be possible to create, edit or"
end
end
end