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:
@@ -1,11 +1,11 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::Poll::Questions::Answers::DocumentsController, :admin do
|
||||
let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) }
|
||||
let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) }
|
||||
describe Admin::Poll::Questions::Options::DocumentsController, :admin do
|
||||
let(:current_option) { create(:poll_question_option, poll: create(:poll)) }
|
||||
let(:future_option) { create(:poll_question_option, poll: create(:poll, :future)) }
|
||||
|
||||
describe "POST create" do
|
||||
let(:answer_attributes) do
|
||||
let(:option_attributes) do
|
||||
{
|
||||
documents_attributes: {
|
||||
"0" => {
|
||||
@@ -18,16 +18,16 @@ describe Admin::Poll::Questions::Answers::DocumentsController, :admin do
|
||||
end
|
||||
|
||||
it "is not possible for an already started poll" do
|
||||
post :create, params: { poll_question_answer: answer_attributes, answer_id: current_answer }
|
||||
post :create, params: { poll_question_option: option_attributes, option_id: current_option }
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Answer."
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Option."
|
||||
expect(Document.count).to eq 0
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
post :create, params: { poll_question_answer: answer_attributes, answer_id: future_answer }
|
||||
post :create, params: { poll_question_option: option_attributes, option_id: future_option }
|
||||
|
||||
expect(response).to redirect_to admin_answer_documents_path(future_answer)
|
||||
expect(response).to redirect_to admin_option_documents_path(future_option)
|
||||
expect(flash[:notice]).to eq "Document uploaded successfully"
|
||||
expect(Document.count).to eq 1
|
||||
end
|
||||
@@ -1,11 +1,11 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::Poll::Questions::Answers::ImagesController, :admin do
|
||||
let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) }
|
||||
let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) }
|
||||
describe Admin::Poll::Questions::Options::ImagesController, :admin do
|
||||
let(:current_option) { create(:poll_question_option, poll: create(:poll)) }
|
||||
let(:future_option) { create(:poll_question_option, poll: create(:poll, :future)) }
|
||||
|
||||
describe "POST create" do
|
||||
let(:answer_attributes) do
|
||||
let(:option_attributes) do
|
||||
{
|
||||
images_attributes: {
|
||||
"0" => {
|
||||
@@ -18,16 +18,16 @@ describe Admin::Poll::Questions::Answers::ImagesController, :admin do
|
||||
end
|
||||
|
||||
it "is not possible for an already started poll" do
|
||||
post :create, params: { poll_question_answer: answer_attributes, answer_id: current_answer }
|
||||
post :create, params: { poll_question_option: option_attributes, option_id: current_option }
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Answer."
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Option."
|
||||
expect(Image.count).to eq 0
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
post :create, params: { poll_question_answer: answer_attributes, answer_id: future_answer }
|
||||
post :create, params: { poll_question_option: option_attributes, option_id: future_option }
|
||||
|
||||
expect(response).to redirect_to admin_answer_images_path(future_answer)
|
||||
expect(response).to redirect_to admin_option_images_path(future_option)
|
||||
expect(flash[:notice]).to eq "Image uploaded successfully"
|
||||
expect(Image.count).to eq 1
|
||||
end
|
||||
@@ -35,7 +35,7 @@ describe Admin::Poll::Questions::Answers::ImagesController, :admin do
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "is not possible for an already started poll" do
|
||||
current_image = create(:image, imageable: current_answer)
|
||||
current_image = create(:image, imageable: current_option)
|
||||
delete :destroy, xhr: true, params: { id: current_image }
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'destroy' on Image."
|
||||
@@ -43,7 +43,7 @@ describe Admin::Poll::Questions::Answers::ImagesController, :admin do
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
future_image = create(:image, imageable: future_answer)
|
||||
future_image = create(:image, imageable: future_option)
|
||||
delete :destroy, xhr: true, params: { id: future_image }
|
||||
|
||||
expect(Image.count).to eq 0
|
||||
@@ -1,48 +1,48 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::Poll::Questions::Answers::VideosController, :admin do
|
||||
let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) }
|
||||
let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) }
|
||||
describe Admin::Poll::Questions::Options::VideosController, :admin do
|
||||
let(:current_option) { create(:poll_question_option, poll: create(:poll)) }
|
||||
let(:future_option) { create(:poll_question_option, poll: create(:poll, :future)) }
|
||||
|
||||
describe "POST create" do
|
||||
it "is not possible for an already started poll" do
|
||||
post :create, params: {
|
||||
poll_question_answer_video: {
|
||||
poll_question_option_video: {
|
||||
title: "Video from started poll",
|
||||
url: "https://www.youtube.com/watch?v=-JMf43st-1A"
|
||||
},
|
||||
answer_id: current_answer
|
||||
option_id: current_option
|
||||
}
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'create' on Video."
|
||||
expect(Poll::Question::Answer::Video.count).to eq 0
|
||||
expect(Poll::Question::Option::Video.count).to eq 0
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
post :create, params: {
|
||||
poll_question_answer_video: {
|
||||
poll_question_option_video: {
|
||||
title: "Video from not started poll",
|
||||
url: "https://www.youtube.com/watch?v=-JMf43st-1A"
|
||||
},
|
||||
answer_id: future_answer
|
||||
option_id: future_option
|
||||
}
|
||||
|
||||
expect(response).to redirect_to admin_answer_videos_path(future_answer)
|
||||
expect(response).to redirect_to admin_option_videos_path(future_option)
|
||||
expect(flash[:notice]).to eq "Video created successfully"
|
||||
expect(Poll::Question::Answer::Video.count).to eq 1
|
||||
expect(Poll::Question::Option::Video.count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH update" do
|
||||
it "is not possible for an already started poll" do
|
||||
current_video = create(:poll_answer_video, answer: current_answer, title: "Sample title")
|
||||
current_video = create(:poll_option_video, option: current_option, title: "Sample title")
|
||||
|
||||
patch :update, params: {
|
||||
poll_question_answer_video: {
|
||||
poll_question_option_video: {
|
||||
title: "New title"
|
||||
},
|
||||
id: current_video,
|
||||
answer_id: current_answer
|
||||
option_id: current_option
|
||||
}
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Video."
|
||||
@@ -50,17 +50,17 @@ describe Admin::Poll::Questions::Answers::VideosController, :admin do
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
future_video = create(:poll_answer_video, answer: future_answer)
|
||||
future_video = create(:poll_option_video, option: future_option)
|
||||
|
||||
patch :update, params: {
|
||||
poll_question_answer_video: {
|
||||
poll_question_option_video: {
|
||||
title: "New title"
|
||||
},
|
||||
id: future_video,
|
||||
answer_id: future_answer
|
||||
option_id: future_option
|
||||
}
|
||||
|
||||
expect(response).to redirect_to admin_answer_videos_path(future_answer)
|
||||
expect(response).to redirect_to admin_option_videos_path(future_option)
|
||||
expect(flash[:notice]).to eq "Changes saved"
|
||||
expect(future_video.reload.title).to eq "New title"
|
||||
end
|
||||
@@ -68,20 +68,20 @@ describe Admin::Poll::Questions::Answers::VideosController, :admin do
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "is not possible for an already started poll" do
|
||||
current_video = create(:poll_answer_video, answer: current_answer)
|
||||
delete :destroy, params: { answer_id: current_answer, id: current_video }
|
||||
current_video = create(:poll_option_video, option: current_option)
|
||||
delete :destroy, params: { option_id: current_option, id: current_video }
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'destroy' on Video."
|
||||
expect(Poll::Question::Answer::Video.count).to eq 1
|
||||
expect(Poll::Question::Option::Video.count).to eq 1
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
future_video = create(:poll_answer_video, answer: future_answer)
|
||||
delete :destroy, params: { answer_id: future_answer, id: future_video }
|
||||
future_video = create(:poll_option_video, option: future_option)
|
||||
delete :destroy, params: { option_id: future_option, id: future_video }
|
||||
|
||||
expect(response).to redirect_to admin_answer_videos_path(future_answer)
|
||||
expect(response).to redirect_to admin_option_videos_path(future_option)
|
||||
expect(flash[:notice]).to eq "Answer video deleted successfully."
|
||||
expect(Poll::Question::Answer::Video.count).to eq 0
|
||||
expect(Poll::Question::Option::Video.count).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,13 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::Poll::Questions::AnswersController, :admin do
|
||||
describe Admin::Poll::Questions::OptionsController, :admin do
|
||||
let(:current_question) { create(:poll_question, poll: create(:poll)) }
|
||||
let(:future_question) { create(:poll_question, poll: create(:poll, :future)) }
|
||||
|
||||
describe "POST create" do
|
||||
it "is not possible for an already started poll" do
|
||||
post :create, params: {
|
||||
poll_question_answer: {
|
||||
poll_question_option: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
@@ -18,13 +18,13 @@ describe Admin::Poll::Questions::AnswersController, :admin do
|
||||
question_id: current_question
|
||||
}
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'create' on Answer."
|
||||
expect(Poll::Question::Answer.count).to eq 0
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'create' on Option."
|
||||
expect(Poll::Question::Option.count).to eq 0
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
post :create, params: {
|
||||
poll_question_answer: {
|
||||
poll_question_option: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
@@ -36,72 +36,72 @@ describe Admin::Poll::Questions::AnswersController, :admin do
|
||||
}
|
||||
|
||||
expect(response).to redirect_to admin_question_path(future_question)
|
||||
expect(Poll::Question::Answer.last.title).to eq "Answer from future poll"
|
||||
expect(Poll::Question::Answer.count).to eq 1
|
||||
expect(Poll::Question::Option.last.title).to eq "Answer from future poll"
|
||||
expect(Poll::Question::Option.count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH update" do
|
||||
it "is not possible for an already started poll" do
|
||||
current_answer = create(:poll_question_answer, question: current_question, title: "Sample title")
|
||||
current_option = create(:poll_question_option, question: current_question, title: "Sample title")
|
||||
|
||||
patch :update, params: {
|
||||
poll_question_answer: {
|
||||
poll_question_option: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
title: "New title",
|
||||
id: current_answer.translations.first.id
|
||||
id: current_option.translations.first.id
|
||||
}
|
||||
}
|
||||
},
|
||||
question_id: current_question,
|
||||
id: current_answer
|
||||
id: current_option
|
||||
}
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Answer."
|
||||
expect(current_answer.reload.title).to eq "Sample title"
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Option."
|
||||
expect(current_option.reload.title).to eq "Sample title"
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
future_answer = create(:poll_question_answer, question: future_question)
|
||||
future_option = create(:poll_question_option, question: future_question)
|
||||
|
||||
patch :update, params: {
|
||||
poll_question_answer: {
|
||||
poll_question_option: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
title: "New title",
|
||||
id: future_answer.translations.first.id
|
||||
id: future_option.translations.first.id
|
||||
}
|
||||
}
|
||||
},
|
||||
question_id: future_question,
|
||||
id: future_answer
|
||||
id: future_option
|
||||
}
|
||||
|
||||
expect(response).to redirect_to admin_question_path(future_question)
|
||||
expect(flash[:notice]).to eq "Changes saved"
|
||||
expect(future_answer.reload.title).to eq "New title"
|
||||
expect(future_option.reload.title).to eq "New title"
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "is not possible for an already started poll" do
|
||||
current_answer = create(:poll_question_answer, question: current_question)
|
||||
delete :destroy, params: { question_id: current_question, id: current_answer }
|
||||
current_option = create(:poll_question_option, question: current_question)
|
||||
delete :destroy, params: { question_id: current_question, id: current_option }
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'destroy' on Answer."
|
||||
expect(Poll::Question::Answer.count).to eq 1
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'destroy' on Option."
|
||||
expect(Poll::Question::Option.count).to eq 1
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
future_answer = create(:poll_question_answer, question: future_question)
|
||||
delete :destroy, params: { question_id: future_question, id: future_answer }
|
||||
future_option = create(:poll_question_option, question: future_question)
|
||||
delete :destroy, params: { question_id: future_question, id: future_option }
|
||||
|
||||
expect(response).to redirect_to admin_question_path(future_question)
|
||||
expect(flash[:notice]).to eq "Answer deleted successfully"
|
||||
expect(Poll::Question::Answer.count).to eq 0
|
||||
expect(Poll::Question::Option.count).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user