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

@@ -1,18 +1,18 @@
require "rails_helper"
describe Admin::Poll::Questions::Answers::Documents::IndexComponent do
describe Admin::Poll::Questions::Options::Documents::IndexComponent do
before { sign_in(create(:administrator).user) }
let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) }
let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) }
let(:future_answer) { create(:poll_question_option, poll: create(:poll, :future)) }
let(:current_answer) { create(:poll_question_option, poll: create(:poll)) }
it "displays the 'Add new document' link when the poll has not started" do
render_inline Admin::Poll::Questions::Answers::Documents::IndexComponent.new(future_answer)
render_inline Admin::Poll::Questions::Options::Documents::IndexComponent.new(future_answer)
expect(page).to have_link "Add new document"
end
it "does not display the 'Add new document' link when the poll has started" do
render_inline Admin::Poll::Questions::Answers::Documents::IndexComponent.new(current_answer)
render_inline Admin::Poll::Questions::Options::Documents::IndexComponent.new(current_answer)
expect(page).not_to have_link "Add new document"
end

View File

@@ -1,13 +1,13 @@
require "rails_helper"
describe Admin::Poll::Questions::Answers::Documents::TableActionsComponent, :admin do
let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) }
let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) }
describe Admin::Poll::Questions::Options::Documents::TableActionsComponent, :admin do
let(:future_answer) { create(:poll_question_option, poll: create(:poll, :future)) }
let(:current_answer) { create(:poll_question_option, poll: create(:poll)) }
it "displays the destroy action when the poll has not started" do
document = create(:document, documentable: future_answer)
render_inline Admin::Poll::Questions::Answers::Documents::TableActionsComponent.new(document)
render_inline Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document)
expect(page).to have_link "Download file"
expect(page).to have_button "Delete"
@@ -17,7 +17,7 @@ describe Admin::Poll::Questions::Answers::Documents::TableActionsComponent, :adm
it "does not display the destroy action when the poll has started" do
document = create(:document, documentable: current_answer)
render_inline Admin::Poll::Questions::Answers::Documents::TableActionsComponent.new(document)
render_inline Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document)
expect(page).to have_link "Download file"
expect(page).not_to have_button "Delete"

View File

@@ -1,19 +1,19 @@
require "rails_helper"
describe Admin::Poll::Questions::Answers::TableActionsComponent, :admin do
describe Admin::Poll::Questions::Options::TableActionsComponent, :admin do
it "displays the edit and destroy actions when the poll has not started" do
answer = create(:poll_question_answer, poll: create(:poll, :future))
option = create(:poll_question_option, poll: create(:poll, :future))
render_inline Admin::Poll::Questions::Answers::TableActionsComponent.new(answer)
render_inline Admin::Poll::Questions::Options::TableActionsComponent.new(option)
expect(page).to have_link "Edit"
expect(page).to have_button "Delete"
end
it "does not display the edit and destroy actions when the poll has started" do
answer = create(:poll_question_answer, poll: create(:poll))
option = create(:poll_question_option, poll: create(:poll))
render_inline Admin::Poll::Questions::Answers::TableActionsComponent.new(answer)
render_inline Admin::Poll::Questions::Options::TableActionsComponent.new(option)
expect(page).not_to have_link "Edit"
expect(page).not_to have_button "Delete"

View File

@@ -1,19 +1,19 @@
require "rails_helper"
describe Admin::Poll::Questions::Answers::Videos::TableActionsComponent, :admin do
describe Admin::Poll::Questions::Options::Videos::TableActionsComponent, :admin do
it "displays the edit and destroy actions when the poll has not started" do
video = create(:poll_answer_video, poll: create(:poll, :future))
video = create(:poll_option_video, poll: create(:poll, :future))
render_inline Admin::Poll::Questions::Answers::Videos::TableActionsComponent.new(video)
render_inline Admin::Poll::Questions::Options::Videos::TableActionsComponent.new(video)
expect(page).to have_link "Edit"
expect(page).to have_button "Delete"
end
it "does not display the edit and destroy actions when the poll has started" do
video = create(:poll_answer_video, poll: create(:poll))
video = create(:poll_option_video, poll: create(:poll))
render_inline Admin::Poll::Questions::Answers::Videos::TableActionsComponent.new(video)
render_inline Admin::Poll::Questions::Options::Videos::TableActionsComponent.new(video)
expect(page).not_to have_link "Edit"
expect(page).not_to have_button "Delete"