Having a class named `Poll::Question::Answer` and another class named `Poll::Answer` was so confusing that no developer working on the project has ever been capable of remembering which is which for more than a few seconds. Furthermore, we're planning to add open answers to polls, and we might add a reference from the `poll_answers` table to the `poll_question_answers` table to property differentiate between open answers and closed answers. Having yet another thing named answer would be more than what our brains can handle (we know it because we did this once in a prototype). So we're renaming `Poll::Question::Answer` to `Poll::Question::Option`. Hopefully that'll make it easier to remember. The name is also (more or less) consistent with the `Legislation::QuestionOption` class, which is similar. We aren't changing the table or columns names for now in order to avoid possible issues when upgrading (old code running with the new database tables/columns after running the migrations but before deployment has finished, for instance). We might do it in the future. I've tried not to change the internationalization keys either so existing translations would still be valid. However, since we have to change the keys in `activerecord.yml` so methods like `human_attribute_name` keep working, I'm also changing them in places where similar keys were used (like `poll_question_answer` or `poll/question/answer`). Note that it isn't clear whether we should use `option` or `question_option` in some cases. In order to keep things simple, we're using `option` where we were using `answer` and `question_option` where we were using `question_answer`. Also note we're adding tests for the admin menu component, since at first I forgot to change the `answers` reference there and all tests passed.
96 lines
3.0 KiB
Ruby
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_option",
|
|
"new_admin_option_image_path",
|
|
{ option_id: "id" },
|
|
nil,
|
|
"Save image",
|
|
"Image uploaded successfully",
|
|
true
|
|
|
|
context "Index" do
|
|
scenario "Option with no images" do
|
|
option = create(:poll_question_option)
|
|
|
|
visit admin_option_images_path(option)
|
|
|
|
expect(page).not_to have_css("img[title='']")
|
|
end
|
|
|
|
scenario "Option with images" do
|
|
option = create(:poll_question_option)
|
|
image = create(:image, imageable: option)
|
|
|
|
visit admin_option_images_path(option)
|
|
|
|
expect(page).to have_css("img[title='#{image.title}']")
|
|
expect(page).to have_content(image.title)
|
|
end
|
|
end
|
|
|
|
describe "Add image to option" do
|
|
scenario "Is possible for a not started poll" do
|
|
option = create(:poll_question_option, poll: future_poll)
|
|
|
|
visit admin_option_images_path(option)
|
|
|
|
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
|
|
option = create(:poll_question_option, poll: current_poll)
|
|
|
|
visit admin_option_images_path(option)
|
|
|
|
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 option" do
|
|
scenario "Is possible for a not started poll" do
|
|
option = create(:poll_question_option, poll: future_poll)
|
|
image = create(:image, imageable: option)
|
|
|
|
visit admin_option_images_path(option)
|
|
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
|
|
option = create(:poll_question_option, poll: current_poll)
|
|
image = create(:image, imageable: option)
|
|
|
|
visit admin_option_images_path(option)
|
|
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
|