Don't allow to modify answer's images for started polls
Note that the `create` action doesn't create an image but updates an answer instead. We're removing the references to `:create` in the abilities since it isn't used. In the future we might change the form to add an image to an answer because it's been broken for ages since it shows all the attached images.
This commit is contained in:
committed by
Javi Martín
parent
5fe86264ca
commit
245594f32b
@@ -1,8 +1,11 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Images", :admin do
|
||||
let(:future_poll) { create(:poll, :future) }
|
||||
let(:current_poll) { create(:poll) }
|
||||
|
||||
it_behaves_like "nested imageable",
|
||||
"poll_question_answer",
|
||||
"future_poll_question_answer",
|
||||
"new_admin_answer_image_path",
|
||||
{ answer_id: "id" },
|
||||
nil,
|
||||
@@ -30,34 +33,63 @@ describe "Images", :admin do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Add image to answer" do
|
||||
answer = create(:poll_question_answer)
|
||||
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")
|
||||
visit admin_answer_images_path(answer)
|
||||
|
||||
visit new_admin_answer_image_path(answer)
|
||||
imageable_attach_new_file(file_fixture("clippy.jpg"))
|
||||
click_button "Save image"
|
||||
expect(page).not_to have_css "img[title='clippy.jpg']"
|
||||
expect(page).not_to have_content "clippy.jpg"
|
||||
|
||||
expect(page).to have_css("img[title='clippy.jpg']")
|
||||
expect(page).to have_content("clippy.jpg")
|
||||
end
|
||||
click_link "Add image"
|
||||
expect(page).to have_content "Descriptive image"
|
||||
|
||||
scenario "Remove image from answer" do
|
||||
answer = create(:poll_question_answer)
|
||||
image = create(:image, imageable: answer)
|
||||
imageable_attach_new_file(file_fixture("clippy.jpg"))
|
||||
click_button "Save image"
|
||||
|
||||
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_link "Remove 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
|
||||
|
||||
expect(page).not_to have_css("img[title='#{image.title}']")
|
||||
expect(page).not_to have_content(image.title)
|
||||
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_link "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_link "Remove image"
|
||||
expect(page).to have_content "Once the poll has started it will not be possible to create, edit or"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user