Rename Poll::Question::Answer to Poll::Question::Option

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.
This commit is contained in:
Javi Martín
2024-05-13 17:38:43 +02:00
parent 6188281d33
commit 38b38d1fcc
100 changed files with 676 additions and 655 deletions

View File

@@ -236,8 +236,8 @@ describe "Admin booths assignments", :admin do
question_1 = create(:poll_question, :yes_no, poll: poll)
question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Today", question: question_2)
create(:poll_question_answer, title: "Tomorrow", question: question_2)
create(:poll_question_option, title: "Today", question: question_2)
create(:poll_question_option, title: "Tomorrow", question: question_2)
create(:poll_partial_result,
booth_assignment: booth_assignment,

View File

@@ -133,12 +133,12 @@ describe "Admin polls", :admin do
expect(page).not_to have_content("Do you support CONSUL?")
expect(Poll::Question.count).to eq(0)
expect(Poll::Question::Answer.count).to eq(0)
expect(Poll::Question::Option.count).to eq(0)
end
scenario "Can destroy polls with answers including videos" do
scenario "Can destroy polls with options including videos" do
poll = create(:poll, name: "Do you support CONSUL?")
create(:poll_answer_video, poll: poll)
create(:poll_option_video, poll: poll)
visit admin_polls_path
@@ -354,12 +354,12 @@ describe "Admin polls", :admin do
booth_assignment_3 = create(:poll_booth_assignment, poll: poll)
question_1 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Oui", question: question_1)
create(:poll_question_answer, title: "Non", question: question_1)
create(:poll_question_option, title: "Oui", question: question_1)
create(:poll_question_option, title: "Non", question: question_1)
question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Aujourd'hui", question: question_2)
create(:poll_question_answer, title: "Demain", question: question_2)
create(:poll_question_option, title: "Aujourd'hui", question: question_2)
create(:poll_question_option, title: "Demain", question: question_2)
[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
@@ -430,8 +430,8 @@ describe "Admin polls", :admin do
question_1 = create(:poll_question, :yes_no, poll: poll)
question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Today", question: question_2)
create(:poll_question_answer, title: "Tomorrow", question: question_2)
create(:poll_question_option, title: "Today", question: question_2)
create(:poll_question_option, title: "Tomorrow", question: question_2)
[booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
create(:poll_partial_result,
@@ -456,17 +456,17 @@ describe "Admin polls", :admin do
click_link "Results"
expect(page).to have_content(question_1.title)
question_1.question_answers.each_with_index do |answer, i|
question_1.question_options.each_with_index do |option, i|
within("#question_#{question_1.id}_#{i}_result") do
expect(page).to have_content(answer.title)
expect(page).to have_content(option.title)
expect(page).to have_content([33, 0][i])
end
end
expect(page).to have_content(question_2.title)
question_2.question_answers.each_with_index do |answer, i|
question_2.question_options.each_with_index do |option, i|
within("#question_#{question_2.id}_#{i}_result") do
expect(page).to have_content(answer.title)
expect(page).to have_content(option.title)
expect(page).to have_content([0, 15][i])
end
end

View File

@@ -4,31 +4,31 @@ describe "Documents", :admin do
let(:future_poll) { create(:poll, :future) }
context "Index" do
scenario "Answer with no documents" do
answer = create(:poll_question_answer)
scenario "Option with no documents" do
option = create(:poll_question_option)
document = create(:document)
visit admin_answer_documents_path(answer)
visit admin_option_documents_path(option)
expect(page).not_to have_content(document.title)
expect(page).to have_link "Go back", href: admin_question_path(answer.question)
expect(page).to have_link "Go back", href: admin_question_path(option.question)
end
scenario "Answer with documents" do
answer = create(:poll_question_answer)
document = create(:document, documentable: answer)
scenario "Option with documents" do
option = create(:poll_question_option)
document = create(:document, documentable: option)
visit admin_answer_documents_path(answer)
visit admin_option_documents_path(option)
expect(page).to have_content(document.title)
end
end
describe "Create document for answer" do
describe "Create document for option" do
scenario "with valid data" do
answer = create(:poll_question_answer, poll: future_poll)
option = create(:poll_question_option, poll: future_poll)
visit admin_answer_documents_path(answer)
visit admin_option_documents_path(option)
expect(page).not_to have_link "Download file"
@@ -43,9 +43,9 @@ describe "Documents", :admin do
end
scenario "with invalid data" do
answer = create(:poll_question_answer, poll: future_poll)
option = create(:poll_question_option, poll: future_poll)
visit admin_answer_documents_path(answer)
visit admin_option_documents_path(option)
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.pdf"))
fill_in "Title", with: ""
@@ -56,11 +56,11 @@ describe "Documents", :admin do
end
end
scenario "Remove document from answer" do
answer = create(:poll_question_answer, poll: future_poll)
document = create(:document, documentable: answer)
scenario "Remove document from option" do
option = create(:poll_question_option, poll: future_poll)
document = create(:document, documentable: option)
visit admin_answer_documents_path(answer)
visit admin_option_documents_path(option)
expect(page).to have_content(document.title)
accept_confirm("Are you sure? This action will delete \"#{document.title}\" and can't be undone.") do

View File

@@ -5,39 +5,39 @@ describe "Images", :admin do
let(:current_poll) { create(:poll) }
it_behaves_like "nested imageable",
"future_poll_question_answer",
"new_admin_answer_image_path",
{ answer_id: "id" },
"future_poll_question_option",
"new_admin_option_image_path",
{ option_id: "id" },
nil,
"Save image",
"Image uploaded successfully",
true
context "Index" do
scenario "Answer with no images" do
answer = create(:poll_question_answer)
scenario "Option with no images" do
option = create(:poll_question_option)
visit admin_answer_images_path(answer)
visit admin_option_images_path(option)
expect(page).not_to have_css("img[title='']")
end
scenario "Answer with images" do
answer = create(:poll_question_answer)
image = create(:image, imageable: answer)
scenario "Option with images" do
option = create(:poll_question_option)
image = create(:image, imageable: option)
visit admin_answer_images_path(answer)
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 answer" do
describe "Add image to option" do
scenario "Is possible for a not started poll" do
answer = create(:poll_question_answer, poll: future_poll)
option = create(:poll_question_option, poll: future_poll)
visit admin_answer_images_path(answer)
visit admin_option_images_path(option)
expect(page).not_to have_css "img[title='clippy.jpg']"
expect(page).not_to have_content "clippy.jpg"
@@ -54,21 +54,21 @@ describe "Images", :admin do
end
scenario "Is not possible for an already started poll" do
answer = create(:poll_question_answer, poll: current_poll)
option = create(:poll_question_option, poll: current_poll)
visit admin_answer_images_path(answer)
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 answer" do
describe "Remove image from option" do
scenario "Is possible for a not started poll" do
answer = create(:poll_question_answer, poll: future_poll)
image = create(:image, imageable: answer)
option = create(:poll_question_option, poll: future_poll)
image = create(:image, imageable: option)
visit admin_answer_images_path(answer)
visit admin_option_images_path(option)
expect(page).to have_css "img[title='#{image.title}']"
expect(page).to have_content image.title
@@ -81,10 +81,10 @@ describe "Images", :admin do
end
scenario "Is not possible for an already started poll" do
answer = create(:poll_question_answer, poll: current_poll)
image = create(:image, imageable: answer)
option = create(:poll_question_option, poll: current_poll)
image = create(:image, imageable: option)
visit admin_answer_images_path(answer)
visit admin_option_images_path(option)
expect(page).to have_css "img[title='#{image.title}']"
expect(page).to have_content image.title

View File

@@ -1,6 +1,6 @@
require "rails_helper"
describe "Answers", :admin do
describe "Poll question options", :admin do
let(:future_poll) { create(:poll, :future) }
let(:current_poll) { create(:poll) }
@@ -34,7 +34,7 @@ describe "Answers", :admin do
scenario "Create second answer and place after the first one" do
question = create(:poll_question, poll: future_poll)
create(:poll_question_answer, title: "First", question: question, given_order: 1)
create(:poll_question_option, title: "First", question: question, given_order: 1)
visit admin_question_path(question)
click_link "Add answer"
@@ -50,8 +50,8 @@ describe "Answers", :admin do
scenario "Update" do
question = create(:poll_question, poll: future_poll)
create(:poll_question_answer, question: question, title: "Answer title", given_order: 2)
create(:poll_question_answer, question: question, title: "Another title", given_order: 1)
create(:poll_question_option, question: question, title: "Answer title", given_order: 2)
create(:poll_question_option, question: question, title: "Another title", given_order: 1)
visit admin_question_path(question)
within("tr", text: "Answer title") { click_link "Edit" }
@@ -72,9 +72,9 @@ describe "Answers", :admin do
end
scenario "Destroy" do
answer = create(:poll_question_answer, poll: future_poll, title: "I'm not useful")
option = create(:poll_question_option, poll: future_poll, title: "I'm not useful")
visit admin_question_path(answer.question)
visit admin_question_path(option.question)
within("tr", text: "I'm not useful") do
accept_confirm("Are you sure? This action will delete \"I'm not useful\" and can't be undone.") do
@@ -88,8 +88,8 @@ describe "Answers", :admin do
scenario "Reorder" do
question = create(:poll_question)
create(:poll_question_answer, question: question, title: "First", given_order: 1)
create(:poll_question_answer, question: question, title: "Last", given_order: 2)
create(:poll_question_option, question: question, title: "First", given_order: 1)
create(:poll_question_option, question: question, title: "Last", given_order: 2)
visit admin_question_path(question)

View File

@@ -9,11 +9,11 @@ describe "Videos", :admin do
describe "Create" do
scenario "Is possible for a not started poll" do
question = create(:poll_question, poll: future_poll)
answer = create(:poll_question_answer, question: question)
option = create(:poll_question_option, question: question)
visit admin_question_path(question)
within("#poll_question_answer_#{answer.id}") do
within("#poll_question_option_#{option.id}") do
click_link "Video list"
end
click_link "Add video"
@@ -29,9 +29,9 @@ describe "Videos", :admin do
end
scenario "Is not possible for an already started poll" do
answer = create(:poll_question_answer, poll: current_poll)
option = create(:poll_question_option, poll: current_poll)
visit admin_answer_videos_path(answer)
visit admin_option_videos_path(option)
expect(page).not_to have_link "Add video"
expect(page).to have_content "Once the poll has started it will not be possible to create, edit or"
@@ -39,11 +39,11 @@ describe "Videos", :admin do
end
scenario "Update" do
video = create(:poll_answer_video, poll: future_poll)
video = create(:poll_option_video, poll: future_poll)
visit edit_admin_answer_video_path(video.answer, video)
visit edit_admin_option_video_path(video.option, video)
expect(page).to have_link "Go back", href: admin_answer_videos_path(video.answer)
expect(page).to have_link "Go back", href: admin_option_videos_path(video.option)
fill_in "Title", with: title
fill_in "External video", with: url
@@ -56,9 +56,9 @@ describe "Videos", :admin do
end
scenario "Destroy" do
video = create(:poll_answer_video, poll: future_poll)
video = create(:poll_option_video, poll: future_poll)
visit admin_answer_videos_path(video.answer)
visit admin_option_videos_path(video.option)
within("tr", text: video.title) do
accept_confirm("Are you sure? This action will delete \"#{video.title}\" and can't be undone.") do

View File

@@ -215,8 +215,8 @@ describe "Admin edit translatable records", :admin do
end
context "CKEditor fields" do
let(:translatable) { create(:poll_question_answer, poll: create(:poll, :future)) }
let(:path) { edit_admin_question_answer_path(translatable.question, translatable) }
let(:translatable) { create(:poll_question_option, poll: create(:poll, :future)) }
let(:path) { edit_admin_question_option_path(translatable.question, translatable) }
scenario "Changes the existing translation" do
visit path