From 38b38d1fcc304821dc4df83ee4c816faa9ab0caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 13 May 2024 17:38:43 +0200 Subject: [PATCH] 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. --- app/assets/javascripts/application.js | 4 +- .../javascripts/{answers.js => options.js} | 12 ++-- app/assets/javascripts/questions.js | 2 +- app/components/admin/menu_component.rb | 8 +-- .../answers/documents/index_component.rb | 14 ----- .../answers/table_actions_component.html.erb | 1 - .../answers/table_actions_component.rb | 7 --- .../documents/index_component.html.erb | 14 ++--- .../options/documents/index_component.rb | 14 +++++ .../table_actions_component.html.erb | 0 .../documents/table_actions_component.rb | 2 +- .../options/table_actions_component.html.erb | 1 + .../options/table_actions_component.rb | 7 +++ .../videos/table_actions_component.html.erb | 0 .../videos/table_actions_component.rb | 2 +- ...nt.html.erb => options_component.html.erb} | 30 ++++----- ...wers_component.rb => options_component.rb} | 16 ++--- .../questions/question_component.html.erb | 4 +- .../polls/questions/question_component.rb | 2 +- .../questions/read_more_component.html.erb | 2 +- .../polls/questions/read_more_component.rb | 2 +- .../polls/results/question_component.html.erb | 4 +- .../polls/results/question_component.rb | 2 +- .../questions/answers/documents_controller.rb | 30 --------- .../questions/answers/images_controller.rb | 41 ------------ .../questions/answers/videos_controller.rb | 46 -------------- .../questions/options/documents_controller.rb | 30 +++++++++ .../questions/options/images_controller.rb | 41 ++++++++++++ .../questions/options/videos_controller.rb | 46 ++++++++++++++ ...rs_controller.rb => options_controller.rb} | 24 +++---- app/controllers/dashboard/polls_controller.rb | 4 +- .../officing/results_controller.rb | 2 +- app/controllers/polls/answers_controller.rb | 2 +- app/controllers/polls/questions_controller.rb | 2 +- app/models/abilities/administrator.rb | 16 ++--- app/models/abilities/common.rb | 4 +- app/models/poll/question.rb | 24 +++---- app/models/poll/question/answer/video.rb | 6 -- .../poll/question/{answer.rb => option.rb} | 17 +++-- app/models/poll/question/option/video.rb | 6 ++ .../answers/documents/index.html.erb | 1 - .../questions/answers/videos/new.html.erb | 9 --- .../{answers => options}/_form.html.erb | 8 +-- .../options/documents/index.html.erb | 1 + .../{answers => options}/edit.html.erb | 4 +- .../images/index.html.erb | 12 ++-- .../{answers => options}/images/new.html.erb | 4 +- .../{answers => options}/new.html.erb | 2 +- .../videos/_form.html.erb | 0 .../{answers => options}/videos/edit.html.erb | 4 +- .../videos/index.html.erb | 8 +-- .../questions/options/videos/new.html.erb | 9 +++ app/views/admin/poll/questions/show.html.erb | 16 ++--- app/views/admin/poll/results/_result.html.erb | 6 +- .../dashboard/polls/_question_fields.html.erb | 6 +- ...l.erb => _question_option_fields.html.erb} | 0 app/views/officing/results/index.html.erb | 6 +- app/views/officing/results/new.html.erb | 2 +- .../{answers.js.erb => options.js.erb} | 2 +- config/initializers/routes_hierarchy.rb | 4 +- config/locales/en/activerecord.yml | 6 +- config/locales/en/general.yml | 2 +- config/locales/en/responders.yml | 10 +-- config/locales/es/activerecord.yml | 6 +- config/locales/es/general.yml | 2 +- config/locales/es/responders.yml | 10 +-- config/routes/admin.rb | 20 +++--- db/dev_seeds/polls.rb | 28 ++++----- spec/components/admin/menu_component_spec.rb | 16 +++++ .../documents/index_component_spec.rb | 10 +-- .../documents/table_actions_component_spec.rb | 10 +-- .../table_actions_component_spec.rb | 10 +-- .../videos/table_actions_component_spec.rb | 10 +-- ...nent_spec.rb => options_component_spec.rb} | 22 +++---- .../questions/question_component_spec.rb | 6 +- .../questions/read_more_component_spec.rb | 26 ++++---- .../documents_controller_spec.rb | 16 ++--- .../images_controller_spec.rb | 20 +++--- .../videos_controller_spec.rb | 48 +++++++------- ...ler_spec.rb => options_controller_spec.rb} | 50 +++++++-------- spec/controllers/documents_controller_spec.rb | 8 +-- spec/factories/polls.rb | 24 +++---- spec/models/abilities/administrator_spec.rb | 52 +++++++-------- spec/models/poll/answer_spec.rb | 8 +-- spec/models/poll/partial_result_spec.rb | 6 +- spec/models/poll/question/answer_spec.rb | 63 ------------------- spec/models/poll/question/option_spec.rb | 63 +++++++++++++++++++ spec/routing/polymorphic_routes_spec.rb | 4 +- spec/shared/system/nested_imageable.rb | 2 +- .../admin/poll/booth_assigments_spec.rb | 4 +- spec/system/admin/poll/polls_spec.rb | 26 ++++---- .../documents/documents_spec.rb | 34 +++++----- .../images/images_spec.rb | 44 ++++++------- .../options_spec.rb} | 16 ++--- .../videos/videos_spec.rb | 18 +++--- spec/system/admin/translatable_spec.rb | 4 +- spec/system/officing/results_spec.rb | 14 ++--- spec/system/polls/polls_spec.rb | 4 +- spec/system/polls/questions_spec.rb | 4 +- spec/system/polls/results_spec.rb | 10 +-- 100 files changed, 676 insertions(+), 655 deletions(-) rename app/assets/javascripts/{answers.js => options.js} (73%) delete mode 100644 app/components/admin/poll/questions/answers/documents/index_component.rb delete mode 100644 app/components/admin/poll/questions/answers/table_actions_component.html.erb delete mode 100644 app/components/admin/poll/questions/answers/table_actions_component.rb rename app/components/admin/poll/questions/{answers => options}/documents/index_component.html.erb (71%) create mode 100644 app/components/admin/poll/questions/options/documents/index_component.rb rename app/components/admin/poll/questions/{answers => options}/documents/table_actions_component.html.erb (100%) rename app/components/admin/poll/questions/{answers => options}/documents/table_actions_component.rb (64%) create mode 100644 app/components/admin/poll/questions/options/table_actions_component.html.erb create mode 100644 app/components/admin/poll/questions/options/table_actions_component.rb rename app/components/admin/poll/questions/{answers => options}/videos/table_actions_component.html.erb (100%) rename app/components/admin/poll/questions/{answers => options}/videos/table_actions_component.rb (61%) rename app/components/polls/questions/{answers_component.html.erb => options_component.html.erb} (60%) rename app/components/polls/questions/{answers_component.rb => options_component.rb} (50%) delete mode 100644 app/controllers/admin/poll/questions/answers/documents_controller.rb delete mode 100644 app/controllers/admin/poll/questions/answers/images_controller.rb delete mode 100644 app/controllers/admin/poll/questions/answers/videos_controller.rb create mode 100644 app/controllers/admin/poll/questions/options/documents_controller.rb create mode 100644 app/controllers/admin/poll/questions/options/images_controller.rb create mode 100644 app/controllers/admin/poll/questions/options/videos_controller.rb rename app/controllers/admin/poll/questions/{answers_controller.rb => options_controller.rb} (60%) delete mode 100644 app/models/poll/question/answer/video.rb rename app/models/poll/question/{answer.rb => option.rb} (66%) create mode 100644 app/models/poll/question/option/video.rb delete mode 100644 app/views/admin/poll/questions/answers/documents/index.html.erb delete mode 100644 app/views/admin/poll/questions/answers/videos/new.html.erb rename app/views/admin/poll/questions/{answers => options}/_form.html.erb (67%) create mode 100644 app/views/admin/poll/questions/options/documents/index.html.erb rename app/views/admin/poll/questions/{answers => options}/edit.html.erb (69%) rename app/views/admin/poll/questions/{answers => options}/images/index.html.erb (76%) rename app/views/admin/poll/questions/{answers => options}/images/new.html.erb (67%) rename app/views/admin/poll/questions/{answers => options}/new.html.erb (81%) rename app/views/admin/poll/questions/{answers => options}/videos/_form.html.erb (100%) rename app/views/admin/poll/questions/{answers => options}/videos/edit.html.erb (51%) rename app/views/admin/poll/questions/{answers => options}/videos/index.html.erb (79%) create mode 100644 app/views/admin/poll/questions/options/videos/new.html.erb rename app/views/dashboard/polls/{_question_answer_fields.html.erb => _question_option_fields.html.erb} (100%) rename app/views/polls/questions/{answers.js.erb => options.js.erb} (56%) rename spec/components/admin/poll/questions/{answers => options}/documents/index_component_spec.rb (59%) rename spec/components/admin/poll/questions/{answers => options}/documents/table_actions_component_spec.rb (68%) rename spec/components/admin/poll/questions/{answers => options}/table_actions_component_spec.rb (51%) rename spec/components/admin/poll/questions/{answers => options}/videos/table_actions_component_spec.rb (58%) rename spec/components/polls/questions/{answers_component_spec.rb => options_component_spec.rb} (82%) rename spec/controllers/admin/poll/questions/{answers => options}/documents_controller_spec.rb (54%) rename spec/controllers/admin/poll/questions/{answers => options}/images_controller_spec.rb (62%) rename spec/controllers/admin/poll/questions/{answers => options}/videos_controller_spec.rb (55%) rename spec/controllers/admin/poll/questions/{answers_controller_spec.rb => options_controller_spec.rb} (67%) delete mode 100644 spec/models/poll/question/answer_spec.rb create mode 100644 spec/models/poll/question/option_spec.rb rename spec/system/admin/poll/questions/{answers => options}/documents/documents_spec.rb (63%) rename spec/system/admin/poll/questions/{answers => options}/images/images_spec.rb (65%) rename spec/system/admin/poll/questions/{answers/answers_spec.rb => options/options_spec.rb} (85%) rename spec/system/admin/poll/questions/{answers => options}/videos/videos_spec.rb (74%) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9e6031dd4..5003ec2f0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -89,7 +89,7 @@ //= require markdown_editor //= require html_editor //= require cocoon -//= require answers +//= require options //= require questions //= require legislation_admin //= require legislation @@ -129,7 +129,7 @@ var initialize_modules = function() { "use strict"; - App.Answers.initialize(); + App.Options.initialize(); App.Questions.initialize(); App.Comments.initialize(); App.ParticipationNotAllowed.initialize(); diff --git a/app/assets/javascripts/answers.js b/app/assets/javascripts/options.js similarity index 73% rename from app/assets/javascripts/answers.js rename to app/assets/javascripts/options.js index 74cb29305..9af905ded 100644 --- a/app/assets/javascripts/answers.js +++ b/app/assets/javascripts/options.js @@ -1,10 +1,10 @@ (function() { "use strict"; - App.Answers = { - initializeAnswers: function(answers) { + App.Options = { + initializeOptions: function(answers) { $(answers).on("cocoon:after-insert", function(e, new_answer) { var given_order; - given_order = App.Answers.maxGivenOrder(answers) + 1; + given_order = App.Options.maxGivenOrder(answers) + 1; $(new_answer).find("[name$='[given_order]']").val(given_order); }); }, @@ -18,13 +18,13 @@ }); return max_order; }, - nestedAnswers: function() { + nestedOptions: function() { $(".js-answers").each(function(index, answers) { - App.Answers.initializeAnswers(answers); + App.Options.initializeOptions(answers); }); }, initialize: function() { - App.Answers.nestedAnswers(); + App.Options.nestedOptions(); } }; }).call(this); diff --git a/app/assets/javascripts/questions.js b/app/assets/javascripts/questions.js index 5ce74d1fd..a90e47298 100644 --- a/app/assets/javascripts/questions.js +++ b/app/assets/javascripts/questions.js @@ -3,7 +3,7 @@ App.Questions = { nestedQuestions: function() { $(".js-questions").on("cocoon:after-insert", function(e, new_question) { - App.Answers.initializeAnswers($(new_question).find(".js-answers")); + App.Options.initializeOptions($(new_question).find(".js-answers")); }); }, initialize: function() { diff --git a/app/components/admin/menu_component.rb b/app/components/admin/menu_component.rb index 2fb97d858..bbb9141ac 100644 --- a/app/components/admin/menu_component.rb +++ b/app/components/admin/menu_component.rb @@ -39,8 +39,8 @@ class Admin::MenuComponent < ApplicationComponent end def polls? - controller.class.module_parent == Admin::Poll::Questions::Answers || - %w[polls active_polls recounts results questions answers].include?(controller_name) && + controller.class.module_parent == Admin::Poll::Questions::Options || + %w[polls active_polls recounts results questions options].include?(controller_name) && action_name != "booth_assignments" end @@ -62,7 +62,7 @@ class Admin::MenuComponent < ApplicationComponent controllers_names = ["pages", "banners", "information_texts", "documents", "images", "content_blocks"] (controllers_names.include?(controller_name) || homepage? || pages?) && - controller.class.module_parent != Admin::Poll::Questions::Answers + controller.class.module_parent != Admin::Poll::Questions::Options end def homepage? @@ -515,7 +515,7 @@ class Admin::MenuComponent < ApplicationComponent [ t("admin.menu.site_customization.images"), admin_site_customization_images_path, - controller_name == "images" && controller.class.module_parent != Admin::Poll::Questions::Answers + controller_name == "images" && controller.class.module_parent != Admin::Poll::Questions::Options ] end diff --git a/app/components/admin/poll/questions/answers/documents/index_component.rb b/app/components/admin/poll/questions/answers/documents/index_component.rb deleted file mode 100644 index 60e816dc8..000000000 --- a/app/components/admin/poll/questions/answers/documents/index_component.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Admin::Poll::Questions::Answers::Documents::IndexComponent < ApplicationComponent - attr_reader :answer - use_helpers :can? - - def initialize(answer) - @answer = answer - end - - private - - def documents - @documents ||= @answer.class.find(@answer.id).documents - end -end diff --git a/app/components/admin/poll/questions/answers/table_actions_component.html.erb b/app/components/admin/poll/questions/answers/table_actions_component.html.erb deleted file mode 100644 index d401f1a36..000000000 --- a/app/components/admin/poll/questions/answers/table_actions_component.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render Admin::AllowedTableActionsComponent.new(answer) %> diff --git a/app/components/admin/poll/questions/answers/table_actions_component.rb b/app/components/admin/poll/questions/answers/table_actions_component.rb deleted file mode 100644 index 94b60b92e..000000000 --- a/app/components/admin/poll/questions/answers/table_actions_component.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Admin::Poll::Questions::Answers::TableActionsComponent < ApplicationComponent - attr_reader :answer - - def initialize(answer) - @answer = answer - end -end diff --git a/app/components/admin/poll/questions/answers/documents/index_component.html.erb b/app/components/admin/poll/questions/options/documents/index_component.html.erb similarity index 71% rename from app/components/admin/poll/questions/answers/documents/index_component.html.erb rename to app/components/admin/poll/questions/options/documents/index_component.html.erb index 644bb18b2..49666c076 100644 --- a/app/components/admin/poll/questions/answers/documents/index_component.html.erb +++ b/app/components/admin/poll/questions/options/documents/index_component.html.erb @@ -1,16 +1,16 @@ -<%= back_link_to admin_question_path(answer.question) %> +<%= back_link_to admin_question_path(option.question) %>

<%= t("admin.questions.show.answers.documents_list") %>

- <% if can?(:update, answer) %> - <%= form_for(Poll::Question::Answer.new, url: admin_answer_documents_path(answer)) do |f| %> - <%= render "shared/errors", resource: answer %> + <% if can?(:update, option) %> + <%= form_for(Poll::Question::Option.new, url: admin_option_documents_path(option)) do |f| %> + <%= render "shared/errors", resource: option %> <%= render Documents::NestedComponent.new(f) %> @@ -37,7 +37,7 @@ <%= document.title %> - <%= render Admin::Poll::Questions::Answers::Documents::TableActionsComponent.new(document) %> + <%= render Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document) %> <% end %> diff --git a/app/components/admin/poll/questions/options/documents/index_component.rb b/app/components/admin/poll/questions/options/documents/index_component.rb new file mode 100644 index 000000000..08925174d --- /dev/null +++ b/app/components/admin/poll/questions/options/documents/index_component.rb @@ -0,0 +1,14 @@ +class Admin::Poll::Questions::Options::Documents::IndexComponent < ApplicationComponent + attr_reader :option + use_helpers :can? + + def initialize(option) + @option = option + end + + private + + def documents + @documents ||= @option.class.find(@option.id).documents + end +end diff --git a/app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb b/app/components/admin/poll/questions/options/documents/table_actions_component.html.erb similarity index 100% rename from app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb rename to app/components/admin/poll/questions/options/documents/table_actions_component.html.erb diff --git a/app/components/admin/poll/questions/answers/documents/table_actions_component.rb b/app/components/admin/poll/questions/options/documents/table_actions_component.rb similarity index 64% rename from app/components/admin/poll/questions/answers/documents/table_actions_component.rb rename to app/components/admin/poll/questions/options/documents/table_actions_component.rb index da895ef1a..a261351fb 100644 --- a/app/components/admin/poll/questions/answers/documents/table_actions_component.rb +++ b/app/components/admin/poll/questions/options/documents/table_actions_component.rb @@ -1,4 +1,4 @@ -class Admin::Poll::Questions::Answers::Documents::TableActionsComponent < ApplicationComponent +class Admin::Poll::Questions::Options::Documents::TableActionsComponent < ApplicationComponent attr_reader :document def initialize(document) diff --git a/app/components/admin/poll/questions/options/table_actions_component.html.erb b/app/components/admin/poll/questions/options/table_actions_component.html.erb new file mode 100644 index 000000000..a49f959fc --- /dev/null +++ b/app/components/admin/poll/questions/options/table_actions_component.html.erb @@ -0,0 +1 @@ +<%= render Admin::AllowedTableActionsComponent.new(option) %> diff --git a/app/components/admin/poll/questions/options/table_actions_component.rb b/app/components/admin/poll/questions/options/table_actions_component.rb new file mode 100644 index 000000000..24acf4a0e --- /dev/null +++ b/app/components/admin/poll/questions/options/table_actions_component.rb @@ -0,0 +1,7 @@ +class Admin::Poll::Questions::Options::TableActionsComponent < ApplicationComponent + attr_reader :option + + def initialize(option) + @option = option + end +end diff --git a/app/components/admin/poll/questions/answers/videos/table_actions_component.html.erb b/app/components/admin/poll/questions/options/videos/table_actions_component.html.erb similarity index 100% rename from app/components/admin/poll/questions/answers/videos/table_actions_component.html.erb rename to app/components/admin/poll/questions/options/videos/table_actions_component.html.erb diff --git a/app/components/admin/poll/questions/answers/videos/table_actions_component.rb b/app/components/admin/poll/questions/options/videos/table_actions_component.rb similarity index 61% rename from app/components/admin/poll/questions/answers/videos/table_actions_component.rb rename to app/components/admin/poll/questions/options/videos/table_actions_component.rb index 06e772b6b..750e14f77 100644 --- a/app/components/admin/poll/questions/answers/videos/table_actions_component.rb +++ b/app/components/admin/poll/questions/options/videos/table_actions_component.rb @@ -1,4 +1,4 @@ -class Admin::Poll::Questions::Answers::Videos::TableActionsComponent < ApplicationComponent +class Admin::Poll::Questions::Options::Videos::TableActionsComponent < ApplicationComponent attr_reader :video def initialize(video) diff --git a/app/components/polls/questions/answers_component.html.erb b/app/components/polls/questions/options_component.html.erb similarity index 60% rename from app/components/polls/questions/answers_component.html.erb rename to app/components/polls/questions/options_component.html.erb index c9fc65343..2d1f30c3d 100644 --- a/app/components/polls/questions/answers_component.html.erb +++ b/app/components/polls/questions/options_component.html.erb @@ -1,35 +1,35 @@
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %> - <% question_answers.each do |question_answer| %> - <% if already_answered?(question_answer) %> - <%= button_to question_answer.title, - question_answer_path(question, user_answer(question_answer)), + <% question_options.each do |question_option| %> + <% if already_answered?(question_option) %> + <%= button_to question_option.title, + question_answer_path(question, user_answer(question_option)), method: :delete, remote: true, - title: t("poll_questions.show.voted", answer: question_answer.title), + title: t("poll_questions.show.voted", answer: question_option.title), class: "button answered", "aria-pressed": true %> <% else %> - <%= button_to question_answer.title, - answer_question_path(question, answer: question_answer.title), + <%= button_to question_option.title, + answer_question_path(question, answer: question_option.title), remote: true, - title: t("poll_questions.show.vote_answer", answer: question_answer.title), + title: t("poll_questions.show.vote_answer", answer: question_option.title), class: "button secondary hollow", "aria-pressed": false, - disabled: disable_answer?(question_answer) %> + disabled: disable_answer?(question_option) %> <% end %> <% end %> <% elsif !user_signed_in? %> - <% question_answers.each do |question_answer| %> - <%= link_to question_answer.title, new_user_session_path, class: "button secondary hollow" %> + <% question_options.each do |question_option| %> + <%= link_to question_option.title, new_user_session_path, class: "button secondary hollow" %> <% end %> <% elsif !current_user.level_two_or_three_verified? %> - <% question_answers.each do |question_answer| %> - <%= link_to question_answer.title, verification_path, class: "button secondary hollow" %> + <% question_options.each do |question_option| %> + <%= link_to question_option.title, verification_path, class: "button secondary hollow" %> <% end %> <% else %> - <% question_answers.each do |question_answer| %> - <%= question_answer.title %> + <% question_options.each do |question_option| %> + <%= question_option.title %> <% end %> <% end %>
diff --git a/app/components/polls/questions/answers_component.rb b/app/components/polls/questions/options_component.rb similarity index 50% rename from app/components/polls/questions/answers_component.rb rename to app/components/polls/questions/options_component.rb index cebfbc235..afda77836 100644 --- a/app/components/polls/questions/answers_component.rb +++ b/app/components/polls/questions/options_component.rb @@ -1,4 +1,4 @@ -class Polls::Questions::AnswersComponent < ApplicationComponent +class Polls::Questions::OptionsComponent < ApplicationComponent attr_reader :question use_helpers :can?, :current_user, :user_signed_in? @@ -6,19 +6,19 @@ class Polls::Questions::AnswersComponent < ApplicationComponent @question = question end - def already_answered?(question_answer) - user_answer(question_answer).present? + def already_answered?(question_option) + user_answer(question_option).present? end - def question_answers - question.question_answers + def question_options + question.question_options end - def user_answer(question_answer) - user_answers.find_by(answer: question_answer.title) + def user_answer(question_option) + user_answers.find_by(answer: question_option.title) end - def disable_answer?(question_answer) + def disable_answer?(question_option) question.multiple? && user_answers.count == question.max_votes end diff --git a/app/components/polls/questions/question_component.html.erb b/app/components/polls/questions/question_component.html.erb index ac675a889..f7a535ee2 100644 --- a/app/components/polls/questions/question_component.html.erb +++ b/app/components/polls/questions/question_component.html.erb @@ -10,10 +10,10 @@ <% end %>
- <%= render Polls::Questions::AnswersComponent.new(question) %> + <%= render Polls::Questions::OptionsComponent.new(question) %>
- <% if question.answers_with_read_more? %> + <% if question.options_with_read_more? %>

<%= t("poll_questions.read_more_about") %>

<%= answers_read_more_links %>

diff --git a/app/components/polls/questions/question_component.rb b/app/components/polls/questions/question_component.rb index 09b8cacd9..278431ed8 100644 --- a/app/components/polls/questions/question_component.rb +++ b/app/components/polls/questions/question_component.rb @@ -6,7 +6,7 @@ class Polls::Questions::QuestionComponent < ApplicationComponent end def answers_read_more_links - safe_join(question.answers_with_read_more.map do |answer| + safe_join(question.options_with_read_more.map do |answer| link_to answer.title, "#answer_#{answer.id}" end, ", ") end diff --git a/app/components/polls/questions/read_more_component.html.erb b/app/components/polls/questions/read_more_component.html.erb index e3672ddc4..c6ea45b01 100644 --- a/app/components/polls/questions/read_more_component.html.erb +++ b/app/components/polls/questions/read_more_component.html.erb @@ -1,5 +1,5 @@

<%= question.title %>

-<% question.answers_with_read_more.each do |answer| %> +<% question.options_with_read_more.each do |answer| %>
" id="answer_<%= answer.id %>">

<%= answer.title %>

diff --git a/app/components/polls/questions/read_more_component.rb b/app/components/polls/questions/read_more_component.rb index f86eafdd1..6b9e7c756 100644 --- a/app/components/polls/questions/read_more_component.rb +++ b/app/components/polls/questions/read_more_component.rb @@ -8,6 +8,6 @@ class Polls::Questions::ReadMoreComponent < ApplicationComponent end def render? - question.answers_with_read_more? + question.options_with_read_more? end end diff --git a/app/components/polls/results/question_component.html.erb b/app/components/polls/results/question_component.html.erb index f11a56898..d25f8f70f 100644 --- a/app/components/polls/results/question_component.html.erb +++ b/app/components/polls/results/question_component.html.erb @@ -2,7 +2,7 @@ - <%- question.question_answers.each do |answer| %> + <%- question.question_options.each do |answer| %> - <%- question.question_answers.each do |answer| %> + <%- question.question_options.each do |answer| %> <% end %> diff --git a/app/views/admin/poll/questions/options/videos/new.html.erb b/app/views/admin/poll/questions/options/videos/new.html.erb new file mode 100644 index 000000000..b94149499 --- /dev/null +++ b/app/views/admin/poll/questions/options/videos/new.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to admin_option_videos_path(@option) %> + +

+ <%= t("admin.answers.videos.new.title") %> +

+ +
+ <%= render "form", form_url: admin_option_videos_path(@option) %> +
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index f6c8ef32b..2c8642265 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -47,8 +47,8 @@
- <% if can?(:create, Poll::Question::Answer.new(question: @question)) %> - <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), + <% if can?(:create, Poll::Question::Option.new(question: @question)) %> + <%= link_to t("admin.questions.show.add_answer"), new_admin_question_option_path(@question), class: "button float-right" %> <% else %>
@@ -70,8 +70,8 @@ -
- <% @question.question_answers.each do |answer| %> + + <% @question.question_options.each do |answer| %> @@ -79,22 +79,22 @@ (<%= answer.images.count %>)
<%= link_to t("admin.questions.show.answers.images_list"), - admin_answer_images_path(answer) %> + admin_option_images_path(answer) %> <% end %> diff --git a/app/views/admin/poll/results/_result.html.erb b/app/views/admin/poll/results/_result.html.erb index 511f278ef..0f2600f4f 100644 --- a/app/views/admin/poll/results/_result.html.erb +++ b/app/views/admin/poll/results/_result.html.erb @@ -9,11 +9,11 @@ - <% question.question_answers.each_with_index do |answer, i| %> + <% question.question_options.each_with_index do |option, i| %> <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %> - - + + <% end %> diff --git a/app/views/dashboard/polls/_question_fields.html.erb b/app/views/dashboard/polls/_question_fields.html.erb index b4d688697..483b7b36f 100644 --- a/app/views/dashboard/polls/_question_fields.html.erb +++ b/app/views/dashboard/polls/_question_fields.html.erb @@ -13,14 +13,14 @@
- <%= f.fields_for :question_answers do |answer| %> - <%= render "question_answer_fields", f: answer %> + <%= f.fields_for :question_options do |answer| %> + <%= render "question_option_fields", f: answer %> <% end %>
diff --git a/app/views/dashboard/polls/_question_answer_fields.html.erb b/app/views/dashboard/polls/_question_option_fields.html.erb similarity index 100% rename from app/views/dashboard/polls/_question_answer_fields.html.erb rename to app/views/dashboard/polls/_question_option_fields.html.erb diff --git a/app/views/officing/results/index.html.erb b/app/views/officing/results/index.html.erb index 1f689e07a..2b2d8ef15 100644 --- a/app/views/officing/results/index.html.erb +++ b/app/views/officing/results/index.html.erb @@ -39,11 +39,11 @@ - <% question.question_answers.each_with_index do |answer, i| %> + <% question.question_options.each_with_index do |option, i| %> <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %> - - + + <% end %> diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb index 06f49a251..86330cbc7 100644 --- a/app/views/officing/results/new.html.erb +++ b/app/views/officing/results/new.html.erb @@ -16,7 +16,7 @@

<%= question.title %>

- <% question.question_answers.each_with_index do |answer, i| %> + <% question.question_options.each_with_index do |answer, i| %>
<%= text_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), placeholder: "0" %> diff --git a/app/views/polls/questions/answers.js.erb b/app/views/polls/questions/options.js.erb similarity index 56% rename from app/views/polls/questions/answers.js.erb rename to app/views/polls/questions/options.js.erb index 2c4380238..f906184a5 100644 --- a/app/views/polls/questions/answers.js.erb +++ b/app/views/polls/questions/options.js.erb @@ -1 +1 @@ -$("#<%= dom_id(@question) %>_answers").html("<%= j render Polls::Questions::AnswersComponent.new(@question) %>"); +$("#<%= dom_id(@question) %>_answers").html("<%= j render Polls::Questions::OptionsComponent.new(@question) %>"); diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index 298805088..fc9eac7f0 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -25,8 +25,8 @@ module ActionDispatch::Routing::UrlFor def namespaced_polymorphic_path(namespace, resource, options = {}) if %w[Budget::Group Budget::Heading Legislation::DraftVersion Legislation::Question - Poll::Booth Poll::BoothAssignment Poll::Officer Poll::Question Poll::Question::Answer - Poll::Question::Answer::Video Poll::Shift SDG::LocalTarget].include?(resource.class.name) + Poll::Booth Poll::BoothAssignment Poll::Officer Poll::Question Poll::Question::Option + Poll::Question::Option::Video Poll::Shift SDG::LocalTarget].include?(resource.class.name) resolve = resolve_for(resource) resolve_options = resolve.pop diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 787eaabf7..43397129f 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -459,13 +459,13 @@ en: image: title: Title attachment: "Choose image" - poll/question/answer: + poll/question/option: title: Answer description: Description - poll/question/answer/translation: + poll/question/option/translation: title: Answer description: "Description (optional)" - poll/question/answer/video: + poll/question/option/video: title: Title url: External video newsletter: diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 50d61d52e..3137ea334 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -162,7 +162,7 @@ en: legislation/process: process legislation/question: question poll/shift: Shift - poll/question/answer: Answer + poll/question/option: Answer user: Account verification/sms: phone signature_sheet: Signature sheet diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml index b4d2799ce..550a5b9f1 100644 --- a/config/locales/en/responders.yml +++ b/config/locales/en/responders.yml @@ -7,9 +7,9 @@ en: direct_message: "You message has been sent successfully." poll: "Poll created successfully." poll_booth: "Booth created successfully." - poll_question_answer: "Answer created successfully" - poll_question_answer_video: "Video created successfully" - poll_question_answer_image: "Image uploaded successfully" + poll_question_option: "Answer created successfully" + poll_question_option_video: "Video created successfully" + poll_question_option_image: "Image uploaded successfully" proposal: "Proposal created successfully." proposal_notification: "Your message has been sent correctly." budget_investment: "Budget Investment created successfully." @@ -34,7 +34,7 @@ en: destroy: budget_investment: "Investment project deleted successfully." topic: "Topic deleted successfully." - poll_question_answer_image: "Image deleted successfully." - poll_question_answer_video: "Answer video deleted successfully." + poll_question_option_image: "Image deleted successfully." + poll_question_option_video: "Answer video deleted successfully." valuator_group: "Valuator group deleted successfully" vote: "Vote deleted successfully" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index a9fc0a0e8..4aa224ae7 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -459,13 +459,13 @@ es: image: title: Título attachment: "Selecciona una imagen" - poll/question/answer: + poll/question/option: title: Respuesta description: Descripción - poll/question/answer/translation: + poll/question/option/translation: title: Respuesta description: "Descripción (opcional)" - poll/question/answer/video: + poll/question/option/video: title: Título url: Vídeo externo newsletter: diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index bb91f8d66..0e658e9ec 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -162,7 +162,7 @@ es: legislation/process: el proceso legislation/question: la pregunta poll/shift: el turno - poll/question/answer: la respuesta + poll/question/option: la respuesta user: la cuenta verification/sms: el teléfono signature_sheet: la hoja de firmas diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml index 8928540e5..49a78fad1 100644 --- a/config/locales/es/responders.yml +++ b/config/locales/es/responders.yml @@ -7,9 +7,9 @@ es: direct_message: "Tu mensaje ha sido enviado correctamente." poll: "Votación creada correctamente." poll_booth: "Urna creada correctamente." - poll_question_answer: "Respuesta creada correctamente" - poll_question_answer_video: "Vídeo creado correctamente" - poll_question_answer_image: "Imagen cargada correctamente" + poll_question_option: "Respuesta creada correctamente" + poll_question_option_video: "Vídeo creado correctamente" + poll_question_option_image: "Imagen cargada correctamente" proposal: "Propuesta creada correctamente." proposal_notification: "Tu mensaje ha sido enviado correctamente." budget_investment: "Proyecto de gasto creado correctamente." @@ -34,7 +34,7 @@ es: destroy: budget_investment: "Proyecto de gasto eliminado." topic: "Tema eliminado." - poll_question_answer_image: "Imagen eliminada correctamente." - poll_question_answer_video: "Vídeo de respuesta eliminado." + poll_question_option_image: "Imagen eliminada correctamente." + poll_question_option_video: "Vídeo de respuesta eliminado." valuator_group: "Grupo de evaluadores eliminado correctamente" vote: "Voto eliminado correctamente" diff --git a/config/routes/admin.rb b/config/routes/admin.rb index c38eaf672..6f3f3d561 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -175,13 +175,13 @@ namespace :admin do end resources :questions, shallow: true do - resources :answers, except: [:index, :show], controller: "questions/answers", shallow: false - resources :answers, only: [], controller: "questions/answers" do - resources :images, controller: "questions/answers/images" - resources :videos, controller: "questions/answers/videos", shallow: false - resources :documents, only: [:index, :create], controller: "questions/answers/documents" + resources :options, except: [:index, :show], controller: "questions/options", shallow: false + resources :options, only: [], controller: "questions/options" do + resources :images, controller: "questions/options/images" + resources :videos, controller: "questions/options/videos", shallow: false + resources :documents, only: [:index, :create], controller: "questions/options/documents" end - post "/answers/order_answers", to: "questions/answers#order_answers" + post "/options/order_options", to: "questions/options#order_options" end resource :active_polls, only: [:create, :edit, :update] @@ -336,12 +336,12 @@ resolve "Poll::Officer" do |officer, options| [:officer, options.merge(id: officer)] end -resolve "Poll::Question::Answer" do |answer, options| - [:question, :answer, options.merge(question_id: answer.question, id: answer)] +resolve "Poll::Question::Option" do |option, options| + [:question, :option, options.merge(question_id: option.question, id: option)] end -resolve "Poll::Question::Answer::Video" do |video, options| - [:answer, :video, options.merge(answer_id: video.answer, id: video)] +resolve "Poll::Question::Option::Video" do |video, options| + [:option, :video, options.merge(option_id: video.option, id: video)] end resolve "Legislation::DraftVersion" do |version, options| diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index 9dd7883ea..b32b4ca39 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -64,17 +64,17 @@ section "Creating Poll Questions & Answers" do question.save! Faker::Lorem.words(number: (2..4).to_a.sample).each_with_index do |title, index| description = "

#{Faker::Lorem.paragraphs.join("

")}

" - answer = Poll::Question::Answer.new(question: question, + option = Poll::Question::Option.new(question: question, title: title.capitalize, description: description, given_order: index + 1) Setting.enabled_locales.map do |locale| Globalize.with_locale(locale) do - answer.title = "#{title} (#{locale})" - answer.description = "#{description} (#{locale})" + option.title = "#{title} (#{locale})" + option.description = "#{description} (#{locale})" end end - answer.save! + option.save! end end end @@ -160,7 +160,7 @@ section "Creating Poll Voters" do Poll::Answer.create!(question_id: question.id, author: user, - answer: question.question_answers.sample.title) + answer: question.question_options.sample.title) end end @@ -210,7 +210,7 @@ section "Creating Poll Results" do author = Poll::Officer.first.user poll.questions.each do |question| - question.question_answers.each do |answer| + question.question_options.each do |answer| Poll::PartialResult.create!(officer_assignment: officer_assignment, booth_assignment: booth_assignment, date: Date.current, @@ -240,17 +240,17 @@ section "Creating Poll Questions from Proposals" do question.save! Faker::Lorem.words(number: (2..4).to_a.sample).each_with_index do |title, index| description = "

#{Faker::ChuckNorris.fact}

" - answer = Poll::Question::Answer.new(question: question, + option = Poll::Question::Option.new(question: question, title: title.capitalize, description: description, given_order: index + 1) Setting.enabled_locales.map do |locale| Globalize.with_locale(locale) do - answer.title = "#{title} (#{locale})" - answer.description = "#{description} (#{locale})" + option.title = "#{title} (#{locale})" + option.description = "#{description} (#{locale})" end end - answer.save! + option.save! end end end @@ -270,17 +270,17 @@ section "Creating Successful Proposals" do question.save! Faker::Lorem.words(number: (2..4).to_a.sample).each_with_index do |title, index| description = "

#{Faker::ChuckNorris.fact}

" - answer = Poll::Question::Answer.new(question: question, + option = Poll::Question::Option.new(question: question, title: title.capitalize, description: description, given_order: index + 1) Setting.enabled_locales.map do |locale| Globalize.with_locale(locale) do - answer.title = "#{title} (#{locale})" - answer.description = "#{description} (#{locale})" + option.title = "#{title} (#{locale})" + option.description = "#{description} (#{locale})" end end - answer.save! + option.save! end end end diff --git a/spec/components/admin/menu_component_spec.rb b/spec/components/admin/menu_component_spec.rb index 0a7ccf82f..c8ca22c9c 100644 --- a/spec/components/admin/menu_component_spec.rb +++ b/spec/components/admin/menu_component_spec.rb @@ -19,4 +19,20 @@ describe Admin::MenuComponent, controller: Admin::NewslettersController do expect(page).to have_css "button[aria-expanded='false']", exact_text: "Settings" end + + describe "#polls_link" do + it "is marked as current when managing poll options", + controller: Admin::Poll::Questions::OptionsController do + render_inline Admin::MenuComponent.new + + expect(page).to have_css "[aria-current]", exact_text: "Polls" + end + + it "is marked as current when managing poll options content", + controller: Admin::Poll::Questions::Options::VideosController do + render_inline Admin::MenuComponent.new + + expect(page).to have_css "[aria-current]", exact_text: "Polls" + end + end end diff --git a/spec/components/admin/poll/questions/answers/documents/index_component_spec.rb b/spec/components/admin/poll/questions/options/documents/index_component_spec.rb similarity index 59% rename from spec/components/admin/poll/questions/answers/documents/index_component_spec.rb rename to spec/components/admin/poll/questions/options/documents/index_component_spec.rb index 053c37ce5..135a1d572 100644 --- a/spec/components/admin/poll/questions/answers/documents/index_component_spec.rb +++ b/spec/components/admin/poll/questions/options/documents/index_component_spec.rb @@ -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 diff --git a/spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb b/spec/components/admin/poll/questions/options/documents/table_actions_component_spec.rb similarity index 68% rename from spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb rename to spec/components/admin/poll/questions/options/documents/table_actions_component_spec.rb index 218b46c41..651856659 100644 --- a/spec/components/admin/poll/questions/answers/documents/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/options/documents/table_actions_component_spec.rb @@ -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" diff --git a/spec/components/admin/poll/questions/answers/table_actions_component_spec.rb b/spec/components/admin/poll/questions/options/table_actions_component_spec.rb similarity index 51% rename from spec/components/admin/poll/questions/answers/table_actions_component_spec.rb rename to spec/components/admin/poll/questions/options/table_actions_component_spec.rb index 4b8243209..f991395ac 100644 --- a/spec/components/admin/poll/questions/answers/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/options/table_actions_component_spec.rb @@ -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" diff --git a/spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb b/spec/components/admin/poll/questions/options/videos/table_actions_component_spec.rb similarity index 58% rename from spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb rename to spec/components/admin/poll/questions/options/videos/table_actions_component_spec.rb index 199e83c7a..d55532abb 100644 --- a/spec/components/admin/poll/questions/answers/videos/table_actions_component_spec.rb +++ b/spec/components/admin/poll/questions/options/videos/table_actions_component_spec.rb @@ -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" diff --git a/spec/components/polls/questions/answers_component_spec.rb b/spec/components/polls/questions/options_component_spec.rb similarity index 82% rename from spec/components/polls/questions/answers_component_spec.rb rename to spec/components/polls/questions/options_component_spec.rb index e63fa68c6..c50416cd5 100644 --- a/spec/components/polls/questions/answers_component_spec.rb +++ b/spec/components/polls/questions/options_component_spec.rb @@ -1,12 +1,12 @@ require "rails_helper" -describe Polls::Questions::AnswersComponent do +describe Polls::Questions::OptionsComponent do include Rails.application.routes.url_helpers let(:poll) { create(:poll) } let(:question) { create(:poll_question, :yes_no, poll: poll) } it "renders answers in given order" do - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect("Yes").to appear_before("No") end @@ -14,7 +14,7 @@ describe Polls::Questions::AnswersComponent do it "renders buttons to vote question answers" do sign_in(create(:user, :verified)) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_button "Yes" expect(page).to have_button "No" @@ -26,7 +26,7 @@ describe Polls::Questions::AnswersComponent do create(:poll_answer, author: user, question: question, answer: "Yes") sign_in(user) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_button "You have voted Yes" expect(page).to have_button "Vote No" @@ -40,7 +40,7 @@ describe Polls::Questions::AnswersComponent do create(:poll_answer, author: user, question: question, answer: "Answer C") sign_in(user) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_button "You have voted Answer A" expect(page).to have_button "Vote Answer B", disabled: true @@ -48,7 +48,7 @@ describe Polls::Questions::AnswersComponent do end it "when user is not signed in, renders answers links pointing to user sign in path" do - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_link "Yes", href: new_user_session_path expect(page).to have_link "No", href: new_user_session_path @@ -57,7 +57,7 @@ describe Polls::Questions::AnswersComponent do it "when user is not verified, renders answers links pointing to user verification in path" do sign_in(create(:user)) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_link "Yes", href: verification_path expect(page).to have_link "No", href: verification_path @@ -68,7 +68,7 @@ describe Polls::Questions::AnswersComponent do create(:poll_voter, :from_booth, poll: poll, user: user) sign_in(user) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_css "span.disabled", text: "Yes" expect(page).to have_css "span.disabled", text: "No" @@ -78,7 +78,7 @@ describe Polls::Questions::AnswersComponent do question = create(:poll_question, :yes_no, poll: create(:poll, :expired)) sign_in(create(:user, :level_two)) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_css "span.disabled", text: "Yes" expect(page).to have_css "span.disabled", text: "No" @@ -93,7 +93,7 @@ describe Polls::Questions::AnswersComponent do poll.geozones << geozone sign_in(create(:user, :level_two)) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_css "span.disabled", text: "Yes" expect(page).to have_css "span.disabled", text: "No" @@ -103,7 +103,7 @@ describe Polls::Questions::AnswersComponent do poll.geozones << geozone sign_in(create(:user, :level_two, geozone: geozone)) - render_inline Polls::Questions::AnswersComponent.new(question) + render_inline Polls::Questions::OptionsComponent.new(question) expect(page).to have_button "Yes" expect(page).to have_button "No" diff --git a/spec/components/polls/questions/question_component_spec.rb b/spec/components/polls/questions/question_component_spec.rb index 4ca884af5..b580045e8 100644 --- a/spec/components/polls/questions/question_component_spec.rb +++ b/spec/components/polls/questions/question_component_spec.rb @@ -3,9 +3,9 @@ require "rails_helper" describe Polls::Questions::QuestionComponent do it "renders more information links when any question answer has additional information" do question = create(:poll_question) - answer_a = create(:poll_question_answer, question: question, title: "Answer A") - answer_b = create(:poll_question_answer, question: question, title: "Answer B") - allow_any_instance_of(Poll::Question::Answer).to receive(:with_read_more?).and_return(true) + answer_a = create(:poll_question_option, question: question, title: "Answer A") + answer_b = create(:poll_question_option, question: question, title: "Answer B") + allow_any_instance_of(Poll::Question::Option).to receive(:with_read_more?).and_return(true) render_inline Polls::Questions::QuestionComponent.new(question: question) diff --git a/spec/components/polls/questions/read_more_component_spec.rb b/spec/components/polls/questions/read_more_component_spec.rb index 26c9899ca..239e7b28c 100644 --- a/spec/components/polls/questions/read_more_component_spec.rb +++ b/spec/components/polls/questions/read_more_component_spec.rb @@ -4,51 +4,51 @@ describe Polls::Questions::ReadMoreComponent do include Rails.application.routes.url_helpers let(:poll) { create(:poll) } let(:question) { create(:poll_question, poll: poll, title: "Question title?") } - let(:answer) { create(:poll_question_answer, question: question) } + let(:option) { create(:poll_question_option, question: question) } it "renders question title" do - create(:poll_question_answer, question: question, description: "Question answer description") + create(:poll_question_option, question: question, description: "Question option description") render_inline Polls::Questions::ReadMoreComponent.new(question: question) expect(page).to have_content "Question title?" end - it "renders answers in the given order" do - create(:poll_question_answer, title: "Answer A", question: question, given_order: 2) - create(:poll_question_answer, title: "Answer B", question: question, given_order: 1) + it "renders options in the given order" do + create(:poll_question_option, title: "Answer A", question: question, given_order: 2) + create(:poll_question_option, title: "Answer B", question: question, given_order: 1) render_inline Polls::Questions::ReadMoreComponent.new(question: question) expect("Answer B").to appear_before("Answer A") end - it "does not render when answers does not have more information" do - answer.update!(description: nil) + it "does not render when options does not have more information" do + option.update!(description: nil) render_inline Polls::Questions::ReadMoreComponent.new(question: question) expect(page).not_to be_rendered end - it "renders answers with videos" do - create(:poll_answer_video, answer: answer, title: "Awesome video", url: "youtube.com/watch?v=123") + it "renders options with videos" do + create(:poll_option_video, option: option, title: "Awesome video", url: "youtube.com/watch?v=123") render_inline Polls::Questions::ReadMoreComponent.new(question: question) expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123") end - it "renders answers with images" do - create(:image, imageable: answer, title: "The yes movement") + it "renders options with images" do + create(:image, imageable: option, title: "The yes movement") render_inline Polls::Questions::ReadMoreComponent.new(question: question) expect(page).to have_css "img[alt='The yes movement']" end - it "renders answers with documents" do - create(:document, documentable: answer, title: "The yes movement") + it "renders options with documents" do + create(:document, documentable: option, title: "The yes movement") render_inline Polls::Questions::ReadMoreComponent.new(question: question) diff --git a/spec/controllers/admin/poll/questions/answers/documents_controller_spec.rb b/spec/controllers/admin/poll/questions/options/documents_controller_spec.rb similarity index 54% rename from spec/controllers/admin/poll/questions/answers/documents_controller_spec.rb rename to spec/controllers/admin/poll/questions/options/documents_controller_spec.rb index 84e02f0f6..b33e7591a 100644 --- a/spec/controllers/admin/poll/questions/answers/documents_controller_spec.rb +++ b/spec/controllers/admin/poll/questions/options/documents_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/poll/questions/answers/images_controller_spec.rb b/spec/controllers/admin/poll/questions/options/images_controller_spec.rb similarity index 62% rename from spec/controllers/admin/poll/questions/answers/images_controller_spec.rb rename to spec/controllers/admin/poll/questions/options/images_controller_spec.rb index 6e2c27b82..d19acc184 100644 --- a/spec/controllers/admin/poll/questions/answers/images_controller_spec.rb +++ b/spec/controllers/admin/poll/questions/options/images_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/poll/questions/answers/videos_controller_spec.rb b/spec/controllers/admin/poll/questions/options/videos_controller_spec.rb similarity index 55% rename from spec/controllers/admin/poll/questions/answers/videos_controller_spec.rb rename to spec/controllers/admin/poll/questions/options/videos_controller_spec.rb index 6a2e7bcf4..a65d0243b 100644 --- a/spec/controllers/admin/poll/questions/answers/videos_controller_spec.rb +++ b/spec/controllers/admin/poll/questions/options/videos_controller_spec.rb @@ -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 diff --git a/spec/controllers/admin/poll/questions/answers_controller_spec.rb b/spec/controllers/admin/poll/questions/options_controller_spec.rb similarity index 67% rename from spec/controllers/admin/poll/questions/answers_controller_spec.rb rename to spec/controllers/admin/poll/questions/options_controller_spec.rb index bdee4c59a..2245947d9 100644 --- a/spec/controllers/admin/poll/questions/answers_controller_spec.rb +++ b/spec/controllers/admin/poll/questions/options_controller_spec.rb @@ -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 diff --git a/spec/controllers/documents_controller_spec.rb b/spec/controllers/documents_controller_spec.rb index 2fc0638cc..c28108ea2 100644 --- a/spec/controllers/documents_controller_spec.rb +++ b/spec/controllers/documents_controller_spec.rb @@ -3,8 +3,8 @@ require "rails_helper" describe DocumentsController do describe "DELETE destroy" do context "Poll answers administration", :admin do - let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) } - let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) } + let(:current_answer) { create(:poll_question_option, poll: create(:poll)) } + let(:future_answer) { create(:poll_question_option, poll: create(:poll, :future)) } it "is not possible for an already started poll" do document = create(:document, documentable: current_answer) @@ -17,10 +17,10 @@ describe DocumentsController do it "is possible for a not started poll" do document = create(:document, documentable: future_answer) - request.env["HTTP_REFERER"] = admin_answer_documents_path(future_answer) + request.env["HTTP_REFERER"] = admin_option_documents_path(future_answer) delete :destroy, params: { id: document } - expect(response).to redirect_to admin_answer_documents_path(future_answer) + expect(response).to redirect_to admin_option_documents_path(future_answer) expect(flash[:notice]).to eq "Document was deleted successfully." expect(Document.count).to eq 0 end diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index a7eb4a1b5..4f61232bc 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -60,15 +60,15 @@ FactoryBot.define do trait :yes_no do after(:create) do |question| - create(:poll_question_answer, question: question, title: "Yes") - create(:poll_question_answer, question: question, title: "No") + create(:poll_question_option, question: question, title: "Yes") + create(:poll_question_option, question: question, title: "No") end end trait :abc do after(:create) do |question, evaluator| %w[A B C].each do |letter| - create(:poll_question_answer, question: question, title: "Answer #{letter}") + create(:poll_question_option, question: question, title: "Answer #{letter}") end end end @@ -88,7 +88,7 @@ FactoryBot.define do end end - factory :poll_question_answer, class: "Poll::Question::Answer" do + factory :poll_question_option, class: "Poll::Question::Option" do sequence(:title) { |n| "Answer title #{n}" } sequence(:description) { |n| "Answer description #{n}" } sequence(:given_order) { |n| n } @@ -98,29 +98,29 @@ FactoryBot.define do question { association(:poll_question, poll: poll) } trait :with_image do - after(:create) { |answer| create(:image, imageable: answer) } + after(:create) { |option| create(:image, imageable: option) } end trait :with_document do - after(:create) { |answer| create(:document, documentable: answer) } + after(:create) { |option| create(:document, documentable: option) } end trait :with_video do - after(:create) { |answer| create(:poll_answer_video, answer: answer) } + after(:create) { |option| create(:poll_option_video, option: option) } end - factory :future_poll_question_answer do + factory :future_poll_question_option do poll { association(:poll, :future) } end end - factory :poll_answer_video, class: "Poll::Question::Answer::Video" do + factory :poll_option_video, class: "Poll::Question::Option::Video" do title { "Sample video title" } url { "https://youtu.be/nhuNb0XtRhQ" } transient { poll { association(:poll) } } - answer { association(:poll_question_answer, poll: poll) } + option { association(:poll_question_option, poll: poll) } end factory :poll_booth, class: "Poll::Booth" do @@ -204,14 +204,14 @@ FactoryBot.define do factory :poll_answer, class: "Poll::Answer" do question factory: [:poll_question, :yes_no] author factory: [:user, :level_two] - answer { question.question_answers.sample.title } + answer { question.question_options.sample.title } end factory :poll_partial_result, class: "Poll::PartialResult" do question factory: [:poll_question, :yes_no] author factory: :user origin { "web" } - answer { question.question_answers.sample.title } + answer { question.question_options.sample.title } end factory :poll_recount, class: "Poll::Recount" do diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index 7fb48b225..f24a6f4b4 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -20,14 +20,14 @@ describe Abilities::Administrator do let(:future_poll) { create(:poll, :future) } let(:current_poll_question) { create(:poll_question) } let(:future_poll_question) { create(:poll_question, poll: future_poll) } - let(:current_poll_question_answer) { create(:poll_question_answer) } - let(:future_poll_question_answer) { create(:poll_question_answer, poll: future_poll) } - let(:current_poll_answer_video) { create(:poll_answer_video, answer: current_poll_question_answer) } - let(:future_poll_answer_video) { create(:poll_answer_video, answer: future_poll_question_answer) } - let(:current_poll_answer_image) { build(:image, imageable: current_poll_question_answer) } - let(:future_poll_answer_image) { build(:image, imageable: future_poll_question_answer) } - let(:current_poll_answer_document) { build(:document, documentable: current_poll_question_answer) } - let(:future_poll_answer_document) { build(:document, documentable: future_poll_question_answer) } + let(:current_poll_question_option) { create(:poll_question_option) } + let(:future_poll_question_option) { create(:poll_question_option, poll: future_poll) } + let(:current_poll_option_video) { create(:poll_option_video, option: current_poll_question_option) } + let(:future_poll_option_video) { create(:poll_option_video, option: future_poll_question_option) } + let(:current_poll_option_image) { build(:image, imageable: current_poll_question_option) } + let(:future_poll_option_image) { build(:image, imageable: future_poll_question_option) } + let(:current_poll_option_document) { build(:document, documentable: current_poll_question_option) } + let(:future_poll_option_document) { build(:document, documentable: future_poll_question_option) } let(:past_process) { create(:legislation_process, :past) } let(:past_draft_process) { create(:legislation_process, :past, :not_published) } @@ -131,27 +131,27 @@ describe Abilities::Administrator do it { should_not be_able_to(:update, current_poll_question) } it { should_not be_able_to(:destroy, current_poll_question) } - it { should be_able_to(:read, Poll::Question::Answer) } - it { should be_able_to(:order_answers, Poll::Question::Answer) } - it { should be_able_to(:create, future_poll_question_answer) } - it { should be_able_to(:update, future_poll_question_answer) } - it { should be_able_to(:destroy, future_poll_question_answer) } - it { should_not be_able_to(:create, current_poll_question_answer) } - it { should_not be_able_to(:update, current_poll_question_answer) } - it { should_not be_able_to(:destroy, current_poll_question_answer) } + it { should be_able_to(:read, Poll::Question::Option) } + it { should be_able_to(:order_options, Poll::Question::Option) } + it { should be_able_to(:create, future_poll_question_option) } + it { should be_able_to(:update, future_poll_question_option) } + it { should be_able_to(:destroy, future_poll_question_option) } + it { should_not be_able_to(:create, current_poll_question_option) } + it { should_not be_able_to(:update, current_poll_question_option) } + it { should_not be_able_to(:destroy, current_poll_question_option) } - it { should be_able_to(:create, future_poll_answer_video) } - it { should be_able_to(:update, future_poll_answer_video) } - it { should be_able_to(:destroy, future_poll_answer_video) } - it { should_not be_able_to(:create, current_poll_answer_video) } - it { should_not be_able_to(:update, current_poll_answer_video) } - it { should_not be_able_to(:destroy, current_poll_answer_video) } + it { should be_able_to(:create, future_poll_option_video) } + it { should be_able_to(:update, future_poll_option_video) } + it { should be_able_to(:destroy, future_poll_option_video) } + it { should_not be_able_to(:create, current_poll_option_video) } + it { should_not be_able_to(:update, current_poll_option_video) } + it { should_not be_able_to(:destroy, current_poll_option_video) } - it { should be_able_to(:destroy, future_poll_answer_image) } - it { should_not be_able_to(:destroy, current_poll_answer_image) } + it { should be_able_to(:destroy, future_poll_option_image) } + it { should_not be_able_to(:destroy, current_poll_option_image) } - it { should be_able_to(:destroy, future_poll_answer_document) } - it { should_not be_able_to(:destroy, current_poll_answer_document) } + it { should be_able_to(:destroy, future_poll_option_document) } + it { should_not be_able_to(:destroy, current_poll_option_document) } it { is_expected.to be_able_to :manage, Dashboard::AdministratorTask } it { is_expected.to be_able_to :manage, dashboard_administrator_task } diff --git a/spec/models/poll/answer_spec.rb b/spec/models/poll/answer_spec.rb index ac5acb402..fd77d5666 100644 --- a/spec/models/poll/answer_spec.rb +++ b/spec/models/poll/answer_spec.rb @@ -47,11 +47,11 @@ describe Poll::Answer do expect(Poll::Answer.count).to be 2 end - it "is valid for answers included in the Poll::Question's question_answers list" do + it "is valid for answers included in the Poll::Question's question_options list" do question = create(:poll_question) - create(:poll_question_answer, title: "One", question: question) - create(:poll_question_answer, title: "Two", question: question) - create(:poll_question_answer, title: "Three", question: question) + create(:poll_question_option, title: "One", question: question) + create(:poll_question_option, title: "Two", question: question) + create(:poll_question_option, title: "Three", question: question) expect(build(:poll_answer, question: question, answer: "One")).to be_valid expect(build(:poll_answer, question: question, answer: "Two")).to be_valid diff --git a/spec/models/poll/partial_result_spec.rb b/spec/models/poll/partial_result_spec.rb index 3e92379a2..2c05b69d2 100644 --- a/spec/models/poll/partial_result_spec.rb +++ b/spec/models/poll/partial_result_spec.rb @@ -4,9 +4,9 @@ describe Poll::PartialResult do describe "validations" do it "validates that the answers are included in the Poll::Question's list" do question = create(:poll_question) - create(:poll_question_answer, title: "One", question: question) - create(:poll_question_answer, title: "Two", question: question) - create(:poll_question_answer, title: "Three", question: question) + create(:poll_question_option, title: "One", question: question) + create(:poll_question_option, title: "Two", question: question) + create(:poll_question_option, title: "Three", question: question) expect(build(:poll_partial_result, question: question, answer: "One")).to be_valid expect(build(:poll_partial_result, question: question, answer: "Two")).to be_valid diff --git a/spec/models/poll/question/answer_spec.rb b/spec/models/poll/question/answer_spec.rb deleted file mode 100644 index 14777cad5..000000000 --- a/spec/models/poll/question/answer_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -require "rails_helper" - -describe Poll::Question::Answer do - it_behaves_like "globalizable", :poll_question_answer - - describe "#with_content" do - it "returns answers with a description" do - answer = create(:poll_question_answer, description: "I've got a description") - - expect(Poll::Question::Answer.with_content).to eq [answer] - end - - it "returns answers with images and no description" do - answer = create(:poll_question_answer, :with_image, description: "") - - expect(Poll::Question::Answer.with_content).to eq [answer] - end - - it "returns answers with documents and no description" do - answer = create(:poll_question_answer, :with_document, description: "") - - expect(Poll::Question::Answer.with_content).to eq [answer] - end - - it "returns answers with videos and no description" do - answer = create(:poll_question_answer, :with_video, description: "") - - expect(Poll::Question::Answer.with_content).to eq [answer] - end - - it "does not return answers with no description and no images, documents nor videos" do - create(:poll_question_answer, description: "") - - expect(Poll::Question::Answer.with_content).to be_empty - end - end - - describe "#with_read_more?" do - it "returns false when the answer does not have description, images, videos nor documents" do - answer = build(:poll_question_answer, description: nil) - - expect(answer.with_read_more?).to be_falsy - end - - it "returns true when the answer has description, images, videos or documents" do - answer = build(:poll_question_answer, description: "Answer description") - - expect(answer.with_read_more?).to be_truthy - - answer = build(:poll_question_answer, :with_image) - - expect(answer.with_read_more?).to be_truthy - - answer = build(:poll_question_answer, :with_document) - - expect(answer.with_read_more?).to be_truthy - - answer = build(:poll_question_answer, :with_video) - - expect(answer.with_read_more?).to be_truthy - end - end -end diff --git a/spec/models/poll/question/option_spec.rb b/spec/models/poll/question/option_spec.rb new file mode 100644 index 000000000..f719064ff --- /dev/null +++ b/spec/models/poll/question/option_spec.rb @@ -0,0 +1,63 @@ +require "rails_helper" + +describe Poll::Question::Option do + it_behaves_like "globalizable", :poll_question_option + + describe "#with_content" do + it "returns options with a description" do + option = create(:poll_question_option, description: "I've got a description") + + expect(Poll::Question::Option.with_content).to eq [option] + end + + it "returns options with images and no description" do + option = create(:poll_question_option, :with_image, description: "") + + expect(Poll::Question::Option.with_content).to eq [option] + end + + it "returns options with documents and no description" do + option = create(:poll_question_option, :with_document, description: "") + + expect(Poll::Question::Option.with_content).to eq [option] + end + + it "returns options with videos and no description" do + option = create(:poll_question_option, :with_video, description: "") + + expect(Poll::Question::Option.with_content).to eq [option] + end + + it "does not return options with no description and no images, documents nor videos" do + create(:poll_question_option, description: "") + + expect(Poll::Question::Option.with_content).to be_empty + end + end + + describe "#with_read_more?" do + it "returns false when the option does not have description, images, videos nor documents" do + option = build(:poll_question_option, description: nil) + + expect(option.with_read_more?).to be_falsy + end + + it "returns true when the option has description, images, videos or documents" do + option = build(:poll_question_option, description: "Option description") + + expect(option.with_read_more?).to be_truthy + + option = build(:poll_question_option, :with_image) + + expect(option.with_read_more?).to be_truthy + + option = build(:poll_question_option, :with_document) + + expect(option.with_read_more?).to be_truthy + + option = build(:poll_question_option, :with_video) + + expect(option.with_read_more?).to be_truthy + end + end +end diff --git a/spec/routing/polymorphic_routes_spec.rb b/spec/routing/polymorphic_routes_spec.rb index 9810cfcda..ce2cca70b 100644 --- a/spec/routing/polymorphic_routes_spec.rb +++ b/spec/routing/polymorphic_routes_spec.rb @@ -115,9 +115,9 @@ describe "Polymorphic routes" do end it "routes poll answer videos" do - video = create(:poll_answer_video) + video = create(:poll_option_video) - expect(admin_polymorphic_path(video)).to eq admin_answer_video_path(video.answer, video) + expect(admin_polymorphic_path(video)).to eq admin_option_video_path(video.option, video) end it "routes milestones for resources with no hierarchy" do diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index d75404e8a..6121f0a0f 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -125,7 +125,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Render image preview after sending the form with validation errors", - unless: imageable_factory_name == "poll_question_answer" do + unless: imageable_factory_name == "poll_question_option" do do_login_for user, management: management visit send(path, arguments) diff --git a/spec/system/admin/poll/booth_assigments_spec.rb b/spec/system/admin/poll/booth_assigments_spec.rb index 59edff9d6..0402b0d39 100644 --- a/spec/system/admin/poll/booth_assigments_spec.rb +++ b/spec/system/admin/poll/booth_assigments_spec.rb @@ -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, diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index 2b52e2182..272ee3268 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -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 diff --git a/spec/system/admin/poll/questions/answers/documents/documents_spec.rb b/spec/system/admin/poll/questions/options/documents/documents_spec.rb similarity index 63% rename from spec/system/admin/poll/questions/answers/documents/documents_spec.rb rename to spec/system/admin/poll/questions/options/documents/documents_spec.rb index 9a65fc182..b3611c4c3 100644 --- a/spec/system/admin/poll/questions/answers/documents/documents_spec.rb +++ b/spec/system/admin/poll/questions/options/documents/documents_spec.rb @@ -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 diff --git a/spec/system/admin/poll/questions/answers/images/images_spec.rb b/spec/system/admin/poll/questions/options/images/images_spec.rb similarity index 65% rename from spec/system/admin/poll/questions/answers/images/images_spec.rb rename to spec/system/admin/poll/questions/options/images/images_spec.rb index a6e35acc8..53558072e 100644 --- a/spec/system/admin/poll/questions/answers/images/images_spec.rb +++ b/spec/system/admin/poll/questions/options/images/images_spec.rb @@ -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 diff --git a/spec/system/admin/poll/questions/answers/answers_spec.rb b/spec/system/admin/poll/questions/options/options_spec.rb similarity index 85% rename from spec/system/admin/poll/questions/answers/answers_spec.rb rename to spec/system/admin/poll/questions/options/options_spec.rb index 21e53e2b1..6f79f8378 100644 --- a/spec/system/admin/poll/questions/answers/answers_spec.rb +++ b/spec/system/admin/poll/questions/options/options_spec.rb @@ -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) diff --git a/spec/system/admin/poll/questions/answers/videos/videos_spec.rb b/spec/system/admin/poll/questions/options/videos/videos_spec.rb similarity index 74% rename from spec/system/admin/poll/questions/answers/videos/videos_spec.rb rename to spec/system/admin/poll/questions/options/videos/videos_spec.rb index 67278fbdd..c903f4e51 100644 --- a/spec/system/admin/poll/questions/answers/videos/videos_spec.rb +++ b/spec/system/admin/poll/questions/options/videos/videos_spec.rb @@ -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 diff --git a/spec/system/admin/translatable_spec.rb b/spec/system/admin/translatable_spec.rb index b65513649..51e25ce9a 100644 --- a/spec/system/admin/translatable_spec.rb +++ b/spec/system/admin/translatable_spec.rb @@ -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 diff --git a/spec/system/officing/results_spec.rb b/spec/system/officing/results_spec.rb index 8f65e714c..a3147093d 100644 --- a/spec/system/officing/results_spec.rb +++ b/spec/system/officing/results_spec.rb @@ -9,11 +9,11 @@ describe "Officing Results", :with_frozen_time do before do create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) - create(:poll_question_answer, title: "Yes", question: question_1, given_order: 1) - create(:poll_question_answer, title: "No", question: question_1, given_order: 2) + create(:poll_question_option, title: "Yes", question: question_1, given_order: 1) + create(:poll_question_option, title: "No", question: question_1, given_order: 2) - create(:poll_question_answer, title: "Today", question: question_2, given_order: 1) - create(:poll_question_answer, title: "Tomorrow", question: question_2, given_order: 2) + create(:poll_question_option, title: "Today", question: question_2, given_order: 1) + create(:poll_question_option, title: "Tomorrow", question: question_2, given_order: 2) login_as(poll_officer.user) set_officing_booth(booth) @@ -86,7 +86,7 @@ describe "Officing Results", :with_frozen_time do booth_assignment: poll_officer.officer_assignments.first.booth_assignment, date: Date.current, question: question_1, - answer: question_1.question_answers.first.title, + answer: question_1.question_options.first.title, author: poll_officer.user, amount: 7777 ) @@ -160,12 +160,12 @@ describe "Officing Results", :with_frozen_time do expect(page).to have_content(booth.name) 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 |answer, i| within("#question_#{question_1.id}_#{i}_result") { expect(page).to have_content(answer.title) } 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 |answer, i| within("#question_#{question_2.id}_#{i}_result") { expect(page).to have_content(answer.title) } end diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index c8b286c9a..ffde159e0 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -152,8 +152,8 @@ describe "Polls" do scenario "Buttons to slide through images work back and forth" do question = create(:poll_question, :yes_no, poll: poll) - create(:image, imageable: question.question_answers.last, title: "The no movement") - create(:image, imageable: question.question_answers.last, title: "No movement planning") + create(:image, imageable: question.question_options.last, title: "The no movement") + create(:image, imageable: question.question_options.last, title: "No movement planning") visit poll_path(poll) diff --git a/spec/system/polls/questions_spec.rb b/spec/system/polls/questions_spec.rb index a655a2677..b6b92e215 100644 --- a/spec/system/polls/questions_spec.rb +++ b/spec/system/polls/questions_spec.rb @@ -13,8 +13,8 @@ describe "Poll Questions" do scenario "shows answers with an image and no description" do poll = create(:poll) - answer = create(:poll_question_answer, poll: poll, title: "Pedestrian road", description: "") - create(:image, imageable: answer, title: "Trees on both sides of the road") + option = create(:poll_question_option, poll: poll, title: "Pedestrian road", description: "") + create(:image, imageable: option, title: "Trees on both sides of the road") visit poll_path(poll) diff --git a/spec/system/polls/results_spec.rb b/spec/system/polls/results_spec.rb index 2fbfe82a1..b9549e703 100644 --- a/spec/system/polls/results_spec.rb +++ b/spec/system/polls/results_spec.rb @@ -8,13 +8,13 @@ describe "Poll Results" do poll = create(:poll, results_enabled: true) question1 = create(:poll_question, poll: poll) - answer1 = create(:poll_question_answer, question: question1, title: "Yes") - answer2 = create(:poll_question_answer, question: question1, title: "No") + answer1 = create(:poll_question_option, question: question1, title: "Yes") + answer2 = create(:poll_question_option, question: question1, title: "No") question2 = create(:poll_question, poll: poll) - answer3 = create(:poll_question_answer, question: question2, title: "Blue") - answer4 = create(:poll_question_answer, question: question2, title: "Green") - answer5 = create(:poll_question_answer, question: question2, title: "Yellow") + answer3 = create(:poll_question_option, question: question2, title: "Blue") + answer4 = create(:poll_question_option, question: question2, title: "Green") + answer5 = create(:poll_question_option, question: question2, title: "Yellow") login_as user1 vote_for_poll_via_web(poll, question1, "Yes")
<% if most_voted_answer?(answer) %> <%= t("polls.show.results.most_voted_answer") %> @@ -14,7 +14,7 @@
<%= answer.total_votes %> (<%= answer.total_votes_percentage.round(2) %>%) diff --git a/app/components/polls/results/question_component.rb b/app/components/polls/results/question_component.rb index f62a6b69d..77b5d9a09 100644 --- a/app/components/polls/results/question_component.rb +++ b/app/components/polls/results/question_component.rb @@ -10,6 +10,6 @@ class Polls::Results::QuestionComponent < ApplicationComponent end def most_voted_answer?(answer) - answer.id == question.most_voted_answer_id + answer.id == question.most_voted_option_id end end diff --git a/app/controllers/admin/poll/questions/answers/documents_controller.rb b/app/controllers/admin/poll/questions/answers/documents_controller.rb deleted file mode 100644 index 6eb70dcc8..000000000 --- a/app/controllers/admin/poll/questions/answers/documents_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -class Admin::Poll::Questions::Answers::DocumentsController < Admin::Poll::BaseController - include DocumentAttributes - - load_and_authorize_resource :answer, class: "::Poll::Question::Answer" - - def index - end - - def create - @answer.attributes = documents_params - authorize! :update, @answer - - if @answer.save - redirect_to admin_answer_documents_path(@answer), - notice: t("admin.documents.create.success_notice") - else - render :index - end - end - - private - - def documents_params - params.require(:poll_question_answer).permit(allowed_params) - end - - def allowed_params - [documents_attributes: document_attributes] - end -end diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb deleted file mode 100644 index 768f8a532..000000000 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController - include ImageAttributes - - load_and_authorize_resource :answer, class: "::Poll::Question::Answer" - load_and_authorize_resource only: [:destroy] - - def index - end - - def new - end - - def create - @answer.attributes = images_params - authorize! :update, @answer - - if @answer.save - redirect_to admin_answer_images_path(@answer), - notice: t("flash.actions.create.poll_question_answer_image") - else - render :new - end - end - - def destroy - @image.destroy! - - redirect_to admin_answer_images_path(@image.imageable), - notice: t("flash.actions.destroy.poll_question_answer_image") - end - - private - - def images_params - params.require(:poll_question_answer).permit(allowed_params) - end - - def allowed_params - [:answer_id, images_attributes: image_attributes] - end -end diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb deleted file mode 100644 index ad613fc41..000000000 --- a/app/controllers/admin/poll/questions/answers/videos_controller.rb +++ /dev/null @@ -1,46 +0,0 @@ -class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseController - load_and_authorize_resource :answer, class: "::Poll::Question::Answer" - load_and_authorize_resource class: "::Poll::Question::Answer::Video", through: :answer - - def index - end - - def new - end - - def create - if @video.save - redirect_to admin_answer_videos_path(@answer), - notice: t("flash.actions.create.poll_question_answer_video") - else - render :new - end - end - - def edit - end - - def update - if @video.update(video_params) - redirect_to admin_answer_videos_path(@answer), notice: t("flash.actions.save_changes.notice") - else - render :edit - end - end - - def destroy - @video.destroy! - notice = t("flash.actions.destroy.poll_question_answer_video") - redirect_to admin_answer_videos_path(@answer), notice: notice - end - - private - - def video_params - params.require(:poll_question_answer_video).permit(allowed_params) - end - - def allowed_params - [:title, :url] - end -end diff --git a/app/controllers/admin/poll/questions/options/documents_controller.rb b/app/controllers/admin/poll/questions/options/documents_controller.rb new file mode 100644 index 000000000..75d437214 --- /dev/null +++ b/app/controllers/admin/poll/questions/options/documents_controller.rb @@ -0,0 +1,30 @@ +class Admin::Poll::Questions::Options::DocumentsController < Admin::Poll::BaseController + include DocumentAttributes + + load_and_authorize_resource :option, class: "::Poll::Question::Option" + + def index + end + + def create + @option.attributes = documents_params + authorize! :update, @option + + if @option.save + redirect_to admin_option_documents_path(@option), + notice: t("admin.documents.create.success_notice") + else + render :index + end + end + + private + + def documents_params + params.require(:poll_question_option).permit(allowed_params) + end + + def allowed_params + [documents_attributes: document_attributes] + end +end diff --git a/app/controllers/admin/poll/questions/options/images_controller.rb b/app/controllers/admin/poll/questions/options/images_controller.rb new file mode 100644 index 000000000..b4b859643 --- /dev/null +++ b/app/controllers/admin/poll/questions/options/images_controller.rb @@ -0,0 +1,41 @@ +class Admin::Poll::Questions::Options::ImagesController < Admin::Poll::BaseController + include ImageAttributes + + load_and_authorize_resource :option, class: "::Poll::Question::Option" + load_and_authorize_resource only: [:destroy] + + def index + end + + def new + end + + def create + @option.attributes = images_params + authorize! :update, @option + + if @option.save + redirect_to admin_option_images_path(@option), + notice: t("flash.actions.create.poll_question_option_image") + else + render :new + end + end + + def destroy + @image.destroy! + + redirect_to admin_option_images_path(@image.imageable), + notice: t("flash.actions.destroy.poll_question_option_image") + end + + private + + def images_params + params.require(:poll_question_option).permit(allowed_params) + end + + def allowed_params + [:option_id, images_attributes: image_attributes] + end +end diff --git a/app/controllers/admin/poll/questions/options/videos_controller.rb b/app/controllers/admin/poll/questions/options/videos_controller.rb new file mode 100644 index 000000000..d9c5aad21 --- /dev/null +++ b/app/controllers/admin/poll/questions/options/videos_controller.rb @@ -0,0 +1,46 @@ +class Admin::Poll::Questions::Options::VideosController < Admin::Poll::BaseController + load_and_authorize_resource :option, class: "::Poll::Question::Option" + load_and_authorize_resource class: "::Poll::Question::Option::Video", through: :option + + def index + end + + def new + end + + def create + if @video.save + redirect_to admin_option_videos_path(@option), + notice: t("flash.actions.create.poll_question_option_video") + else + render :new + end + end + + def edit + end + + def update + if @video.update(video_params) + redirect_to admin_option_videos_path(@option), notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + + def destroy + @video.destroy! + notice = t("flash.actions.destroy.poll_question_option_video") + redirect_to admin_option_videos_path(@option), notice: notice + end + + private + + def video_params + params.require(:poll_question_option_video).permit(allowed_params) + end + + def allowed_params + [:title, :url] + end +end diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/options_controller.rb similarity index 60% rename from app/controllers/admin/poll/questions/answers_controller.rb rename to app/controllers/admin/poll/questions/options_controller.rb index 874d99a23..5994e248e 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/options_controller.rb @@ -1,18 +1,18 @@ -class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController +class Admin::Poll::Questions::OptionsController < Admin::Poll::BaseController include Translatable load_and_authorize_resource :question, class: "::Poll::Question" - load_and_authorize_resource class: "::Poll::Question::Answer", + load_and_authorize_resource class: "::Poll::Question::Option", through: :question, - through_association: :question_answers + through_association: :question_options def new end def create - if @answer.save + if @option.save redirect_to admin_question_path(@question), - notice: t("flash.actions.create.poll_question_answer") + notice: t("flash.actions.create.poll_question_option") else render :new end @@ -22,7 +22,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end def update - if @answer.update(answer_params) + if @option.update(option_params) redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice") else @@ -31,24 +31,24 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end def destroy - @answer.destroy! + @option.destroy! redirect_to admin_question_path(@question), notice: t("admin.answers.destroy.success_notice") end - def order_answers - ::Poll::Question::Answer.order_answers(params[:ordered_list]) + def order_options + ::Poll::Question::Option.order_options(params[:ordered_list]) head :ok end private - def answer_params - params.require(:poll_question_answer).permit(allowed_params) + def option_params + params.require(:poll_question_option).permit(allowed_params) end def allowed_params attributes = [:title, :description, :given_order] - [*attributes, translation_params(Poll::Question::Answer)] + [*attributes, translation_params(Poll::Question::Option)] end end diff --git a/app/controllers/dashboard/polls_controller.rb b/app/controllers/dashboard/polls_controller.rb index 8b4570454..ba70228c3 100644 --- a/app/controllers/dashboard/polls_controller.rb +++ b/app/controllers/dashboard/polls_controller.rb @@ -66,10 +66,10 @@ class Dashboard::PollsController < Dashboard::BaseController def question_attributes [:id, :title, :author_id, :proposal_id, :_destroy, - question_answers_attributes: question_answers_attributes] + question_options_attributes: question_options_attributes] end - def question_answers_attributes + def question_options_attributes [:id, :_destroy, :title, :description, :given_order, :question_id, documents_attributes: document_attributes] end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 33b952d46..4ebd7fba2 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -43,7 +43,7 @@ class Officing::ResultsController < Officing::BaseController results.each_pair do |answer_index, count| next if count.blank? - answer = question.question_answers.find_by(given_order: answer_index.to_i + 1).title + answer = question.question_options.find_by(given_order: answer_index.to_i + 1).title go_back_to_new if question.blank? partial_result = ::Poll::PartialResult.find_or_initialize_by( diff --git a/app/controllers/polls/answers_controller.rb b/app/controllers/polls/answers_controller.rb index 9e4988c05..174cc673c 100644 --- a/app/controllers/polls/answers_controller.rb +++ b/app/controllers/polls/answers_controller.rb @@ -12,7 +12,7 @@ class Polls::AnswersController < ApplicationController redirect_to request.referer end format.js do - render "polls/questions/answers" + render "polls/questions/options" end end end diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index a21acc9bc..0e7f9a1c9 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -13,7 +13,7 @@ class Polls::QuestionsController < ApplicationController redirect_to request.referer end format.js do - render :answers + render :options end end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index c6abe703c..9422a4cf5 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -96,16 +96,16 @@ module Abilities can [:update, :destroy], Poll::Question do |question| !question.poll.started? end - can [:read, :order_answers], Poll::Question::Answer - can [:create, :update, :destroy], Poll::Question::Answer do |answer| - can?(:update, answer.question) + can [:read, :order_options], Poll::Question::Option + can [:create, :update, :destroy], Poll::Question::Option do |option| + can?(:update, option.question) end - can :read, Poll::Question::Answer::Video - can [:create, :update, :destroy], Poll::Question::Answer::Video do |video| - can?(:update, video.answer) + can :read, Poll::Question::Option::Video + can [:create, :update, :destroy], Poll::Question::Option::Video do |video| + can?(:update, video.option) end can [:destroy], Image do |image| - image.imageable_type == "Poll::Question::Answer" && can?(:update, image.imageable) + image.imageable_type == "Poll::Question::Option" && can?(:update, image.imageable) end can :manage, SiteCustomization::Page @@ -127,7 +127,7 @@ module Abilities can [:create], Document can [:destroy], Document do |document| - document.documentable_type == "Poll::Question::Answer" && can?(:update, document.documentable) + document.documentable_type == "Poll::Question::Option" && can?(:update, document.documentable) end can [:create, :destroy], DirectUpload diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index e14469539..369630981 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -71,11 +71,11 @@ module Abilities can [:create, :destroy], Follow, user_id: user.id can [:destroy], Document do |document| - document.documentable_type != "Poll::Question::Answer" && document.documentable&.author_id == user.id + document.documentable_type != "Poll::Question::Option" && document.documentable&.author_id == user.id end can [:destroy], Image do |image| - image.imageable_type != "Poll::Question::Answer" && image.imageable&.author_id == user.id + image.imageable_type != "Poll::Question::Option" && image.imageable&.author_id == user.id end can [:create, :destroy], DirectUpload diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index d77873d6f..b860195c5 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -14,8 +14,8 @@ class Poll::Question < ApplicationRecord has_many :comments, as: :commentable, inverse_of: :commentable has_many :answers, class_name: "Poll::Answer" - has_many :question_answers, -> { order "given_order asc" }, - class_name: "Poll::Question::Answer", + has_many :question_options, -> { order "given_order asc" }, + class_name: "Poll::Question::Option", inverse_of: :question, dependent: :destroy has_many :partial_results @@ -25,7 +25,7 @@ class Poll::Question < ApplicationRecord validates :author, presence: true validates :poll_id, presence: true, if: proc { |question| question.poll.nil? } - accepts_nested_attributes_for :question_answers, reject_if: :all_blank, allow_destroy: true + accepts_nested_attributes_for :question_options, reject_if: :all_blank, allow_destroy: true scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) } @@ -63,23 +63,23 @@ class Poll::Question < ApplicationRecord where(poll_id: Poll.answerable_by(user).pluck(:id)) end - def answers_total_votes - question_answers.reduce(0) { |total, question_answer| total + question_answer.total_votes } + def options_total_votes + question_options.reduce(0) { |total, question_option| total + question_option.total_votes } end - def most_voted_answer_id - question_answers.max_by(&:total_votes)&.id + def most_voted_option_id + question_options.max_by(&:total_votes)&.id end def possible_answers - question_answers.joins(:translations).pluck(:title) + question_options.joins(:translations).pluck(:title) end - def answers_with_read_more? - answers_with_read_more.any? + def options_with_read_more? + options_with_read_more.any? end - def answers_with_read_more - question_answers.select(&:with_read_more?) + def options_with_read_more + question_options.select(&:with_read_more?) end end diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb deleted file mode 100644 index e353dd365..000000000 --- a/app/models/poll/question/answer/video.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Poll::Question::Answer::Video < ApplicationRecord - belongs_to :answer, class_name: "Poll::Question::Answer" - include Videoable - - validates :title, presence: true -end diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/option.rb similarity index 66% rename from app/models/poll/question/answer.rb rename to app/models/poll/question/option.rb index a41f9e4a9..59e38aa33 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/option.rb @@ -1,4 +1,6 @@ -class Poll::Question::Answer < ApplicationRecord +class Poll::Question::Option < ApplicationRecord + self.table_name = "poll_question_answers" + include Galleryable include Documentable @@ -9,7 +11,10 @@ class Poll::Question::Answer < ApplicationRecord accepts_nested_attributes_for :documents, allow_destroy: true belongs_to :question, class_name: "Poll::Question" - has_many :videos, class_name: "Poll::Question::Answer::Video", dependent: :destroy + has_many :videos, class_name: "Poll::Question::Option::Video", + dependent: :destroy, + foreign_key: "answer_id", + inverse_of: :option validates_translation :title, presence: true validates :given_order, presence: true, uniqueness: { scope: :question_id } @@ -22,9 +27,9 @@ class Poll::Question::Answer < ApplicationRecord .where.missing(:videos) end - def self.order_answers(ordered_array) - ordered_array.each_with_index do |answer_id, order| - find(answer_id).update_column(:given_order, (order + 1)) + def self.order_options(ordered_array) + ordered_array.each_with_index do |option_id, order| + find(option_id).update_column(:given_order, (order + 1)) end end @@ -38,7 +43,7 @@ class Poll::Question::Answer < ApplicationRecord end def total_votes_percentage - question.answers_total_votes.zero? ? 0 : (total_votes * 100.0) / question.answers_total_votes + question.options_total_votes.zero? ? 0 : (total_votes * 100.0) / question.options_total_votes end def with_read_more? diff --git a/app/models/poll/question/option/video.rb b/app/models/poll/question/option/video.rb new file mode 100644 index 000000000..25b9335a1 --- /dev/null +++ b/app/models/poll/question/option/video.rb @@ -0,0 +1,6 @@ +class Poll::Question::Option::Video < ApplicationRecord + belongs_to :option, class_name: "Poll::Question::Option", foreign_key: "answer_id", inverse_of: :videos + include Videoable + + validates :title, presence: true +end diff --git a/app/views/admin/poll/questions/answers/documents/index.html.erb b/app/views/admin/poll/questions/answers/documents/index.html.erb deleted file mode 100644 index 037ab68f2..000000000 --- a/app/views/admin/poll/questions/answers/documents/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render Admin::Poll::Questions::Answers::Documents::IndexComponent.new(@answer) %> diff --git a/app/views/admin/poll/questions/answers/videos/new.html.erb b/app/views/admin/poll/questions/answers/videos/new.html.erb deleted file mode 100644 index 9552916ea..000000000 --- a/app/views/admin/poll/questions/answers/videos/new.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<%= back_link_to admin_answer_videos_path(@answer) %> - -

- <%= t("admin.answers.videos.new.title") %> -

- -
- <%= render "form", form_url: admin_answer_videos_path(@answer) %> -
diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/options/_form.html.erb similarity index 67% rename from app/views/admin/poll/questions/answers/_form.html.erb rename to app/views/admin/poll/questions/options/_form.html.erb index 7ecc89c8c..52f72d757 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/options/_form.html.erb @@ -1,11 +1,11 @@ -<%= render "shared/globalize_locales", resource: @answer %> +<%= render "shared/globalize_locales", resource: @option %> -<%= translatable_form_for(@answer, url: form_url) do |f| %> +<%= translatable_form_for(@option, url: form_url) do |f| %> - <%= render "shared/errors", resource: @answer %> + <%= render "shared/errors", resource: @option %> <%= f.hidden_field :given_order, - value: @answer.persisted? ? @answer.given_order : @answer.class.last_position(@answer.question_id || @question.id) + 1 %> + value: @option.persisted? ? @option.given_order : @option.class.last_position(@option.question_id || @question.id) + 1 %>
<%= f.translatable_fields do |translations_form| %> diff --git a/app/views/admin/poll/questions/options/documents/index.html.erb b/app/views/admin/poll/questions/options/documents/index.html.erb new file mode 100644 index 000000000..2518c8f7a --- /dev/null +++ b/app/views/admin/poll/questions/options/documents/index.html.erb @@ -0,0 +1 @@ +<%= render Admin::Poll::Questions::Options::Documents::IndexComponent.new(@option) %> diff --git a/app/views/admin/poll/questions/answers/edit.html.erb b/app/views/admin/poll/questions/options/edit.html.erb similarity index 69% rename from app/views/admin/poll/questions/answers/edit.html.erb rename to app/views/admin/poll/questions/options/edit.html.erb index 3abeef3b6..c8975cecb 100644 --- a/app/views/admin/poll/questions/answers/edit.html.erb +++ b/app/views/admin/poll/questions/options/edit.html.erb @@ -1,7 +1,7 @@ <%= back_link_to admin_question_path(@question) %> @@ -10,5 +10,5 @@
- <%= render "form", form_url: admin_question_answer_path(@question, @answer) %> + <%= render "form", form_url: admin_question_option_path(@question, @option) %>
diff --git a/app/views/admin/poll/questions/answers/images/index.html.erb b/app/views/admin/poll/questions/options/images/index.html.erb similarity index 76% rename from app/views/admin/poll/questions/answers/images/index.html.erb rename to app/views/admin/poll/questions/options/images/index.html.erb index 27484ce98..7531e0f5d 100644 --- a/app/views/admin/poll/questions/answers/images/index.html.erb +++ b/app/views/admin/poll/questions/options/images/index.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to admin_question_path(@answer.question) %> +<%= back_link_to admin_question_path(@option.question) %>
@@ -6,9 +6,9 @@ <%= t("admin.answers.images.index.title") %> -<% if can?(:update, @answer) %> +<% if can?(:update, @option) %> <%= link_to t("admin.questions.answers.images.add_image"), - new_admin_answer_image_path(@answer), + new_admin_option_image_path(@option), class: "button hollow float-right" %> <% else %>
@@ -17,11 +17,11 @@ <% end %> -<% @answer.images.each do |image| %> +<% @option.images.each do |image| %>
<%= render_image(image, :large, true) if image.present? %> diff --git a/app/views/admin/poll/questions/answers/images/new.html.erb b/app/views/admin/poll/questions/options/images/new.html.erb similarity index 67% rename from app/views/admin/poll/questions/answers/images/new.html.erb rename to app/views/admin/poll/questions/options/images/new.html.erb index 3c85c0b57..0a6df9037 100644 --- a/app/views/admin/poll/questions/answers/images/new.html.erb +++ b/app/views/admin/poll/questions/options/images/new.html.erb @@ -1,6 +1,6 @@
- <%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %> - <%= render "shared/errors", resource: @answer %> + <%= form_for(@option, url: admin_option_images_path(@option), method: :post) do |f| %> + <%= render "shared/errors", resource: @option %> <%= render Images::NestedComponent.new(f, image_fields: :images) %> diff --git a/app/views/admin/poll/questions/answers/new.html.erb b/app/views/admin/poll/questions/options/new.html.erb similarity index 81% rename from app/views/admin/poll/questions/answers/new.html.erb rename to app/views/admin/poll/questions/options/new.html.erb index 863fdb56c..6ba1372f1 100644 --- a/app/views/admin/poll/questions/answers/new.html.erb +++ b/app/views/admin/poll/questions/options/new.html.erb @@ -8,5 +8,5 @@

<%= t("admin.answers.new.title") %>

- <%= render "form", form_url: admin_question_answers_path %> + <%= render "form", form_url: admin_question_options_path %>
diff --git a/app/views/admin/poll/questions/answers/videos/_form.html.erb b/app/views/admin/poll/questions/options/videos/_form.html.erb similarity index 100% rename from app/views/admin/poll/questions/answers/videos/_form.html.erb rename to app/views/admin/poll/questions/options/videos/_form.html.erb diff --git a/app/views/admin/poll/questions/answers/videos/edit.html.erb b/app/views/admin/poll/questions/options/videos/edit.html.erb similarity index 51% rename from app/views/admin/poll/questions/answers/videos/edit.html.erb rename to app/views/admin/poll/questions/options/videos/edit.html.erb index 39d592ff5..aecdc3734 100644 --- a/app/views/admin/poll/questions/answers/videos/edit.html.erb +++ b/app/views/admin/poll/questions/options/videos/edit.html.erb @@ -1,9 +1,9 @@ -<%= back_link_to admin_answer_videos_path(@answer) %> +<%= back_link_to admin_option_videos_path(@option) %>

<%= t("admin.answers.videos.edit.title") %>

- <%= render "form", form_url: admin_answer_video_path(@answer, @video) %> + <%= render "form", form_url: admin_option_video_path(@option, @video) %>
diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/options/videos/index.html.erb similarity index 79% rename from app/views/admin/poll/questions/answers/videos/index.html.erb rename to app/views/admin/poll/questions/options/videos/index.html.erb index c9e82498a..b0db3b416 100644 --- a/app/views/admin/poll/questions/answers/videos/index.html.erb +++ b/app/views/admin/poll/questions/options/videos/index.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to admin_question_path(@answer.question) %> +<%= back_link_to admin_question_path(@option.question) %>
@@ -6,9 +6,9 @@ <%= t("admin.answers.videos.index.title") %> -<% if can?(:create, Poll::Question::Answer.new(question: @answer.question)) %> +<% if can?(:create, Poll::Question::Option.new(question: @option.question)) %> <%= link_to t("admin.answers.videos.index.add_video"), - new_admin_answer_video_path(@answer), + new_admin_option_video_path(@option), class: "button success float-right" %> <% else %>
@@ -33,7 +33,7 @@
<%= video.title %> <%= link_to video.url, video.url %> - <%= render Admin::Poll::Questions::Answers::Videos::TableActionsComponent.new(video) %> + <%= render Admin::Poll::Questions::Options::Videos::TableActionsComponent.new(video) %>
<%= answer.title %> <%= wysiwyg(answer.description) %> (<%= answer.documents.count rescue 0 %>)
<%= link_to t("admin.questions.show.answers.documents_list"), - admin_answer_documents_path(answer) %> + admin_option_documents_path(answer) %>
(<%= answer.videos.count %>)
<%= link_to t("admin.questions.show.answers.video_list"), - admin_answer_videos_path(answer) %> + admin_option_videos_path(answer) %>
- <%= render Admin::Poll::Questions::Answers::TableActionsComponent.new(answer) %> + <%= render Admin::Poll::Questions::Options::TableActionsComponent.new(answer) %>
<%= answer.title %><%= by_answer[answer.title].present? ? by_answer[answer.title].sum(&:amount) : 0 %><%= option.title %><%= by_answer[option.title].present? ? by_answer[option.title].sum(&:amount) : 0 %>
<%= answer.title %><%= by_answer[answer.title].present? ? by_answer[answer.title].first.amount : 0 %><%= option.title %><%= by_answer[option.title].present? ? by_answer[option.title].first.amount : 0 %>