diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb new file mode 100644 index 000000000..a231c1a20 --- /dev/null +++ b/app/controllers/admin/poll/questions/answers/videos_controller.rb @@ -0,0 +1,57 @@ +class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseController + before_action :load_answer, only: [:index, :new, :create] + before_action :load_video, only: [:edit, :update, :destroy] + + def index + end + + def new + @video = ::Poll::Question::Answer::Video.new + end + + def create + @video = ::Poll::Question::Answer::Video.new(video_params) + + 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(@video.answer_id), + notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + + def destroy + if @video.destroy + notice = t("flash.actions.destroy.poll_question_answer_video") + else + notice = t("flash.actions.destroy.error") + end + redirect_to :back, notice: notice + end + + private + + def video_params + params.require(:poll_question_answer_video).permit(:title, :url, :answer_id) + end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:answer_id]) + end + + def load_video + @video = ::Poll::Question::Answer::Video.find(params[:id]) + end +end diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index 107c06740..5cf587735 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -56,8 +56,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController private def question_params - params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :valid_answers, :video_url, - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :valid_answers, :video_url) end def search_params diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 27d33ea04..c66db216f 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -41,4 +41,8 @@ module PollsHelper booth.name + location end + def voted_before_sign_in(question) + current_user.current_sign_in_at >= question.answers.find_or_initialize_by(author: current_user).updated_at + end + end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 1e94e0180..e6ef482a9 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -1,11 +1,6 @@ class Poll::Question < ActiveRecord::Base include Measurable include Searchable - include Documentable - documentable max_documents_allowed: 1, - max_file_size: 3.megabytes, - accepted_content_types: [ "application/pdf" ] - accepts_nested_attributes_for :documents, allow_destroy: true acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 1746c480c..fb32de9fc 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -2,6 +2,7 @@ class Poll::Question::Answer < ActiveRecord::Base include Galleryable belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' + has_many :videos, class_name: 'Poll::Question::Answer::Video' validates :title, presence: true diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb new file mode 100644 index 000000000..3d214af96 --- /dev/null +++ b/app/models/poll/question/answer/video.rb @@ -0,0 +1,16 @@ +class Poll::Question::Answer::Video < ActiveRecord::Base + belongs_to :answer, class_name: 'Poll::Question::Answer', foreign_key: 'answer_id' + + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + + validates :title, presence: true + validate :valid_url? + + def valid_url? + return if url.blank? + return if url.match(VIMEO_REGEX) + return if url.match(YOUTUBE_REGEX) + errors.add(:url, :invalid) + end +end diff --git a/app/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb index 5345a64b1..d197112f5 100644 --- a/app/views/admin/poll/questions/_form.html.erb +++ b/app/views/admin/poll/questions/_form.html.erb @@ -4,7 +4,6 @@ <%= f.hidden_field :proposal_id %> -
<%= f.select :poll_id, @@ -15,10 +14,6 @@ <%= f.text_field :title, maxlength: Poll::Question.title_max_length %> -
- <%= render 'documents/nested_documents', documentable: @question, f: f %> -
-
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>

<%= t("proposals.form.proposal_video_url_note") %>

diff --git a/app/views/admin/poll/questions/answers/videos/_form.html.erb b/app/views/admin/poll/questions/answers/videos/_form.html.erb new file mode 100644 index 000000000..28035c397 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@video, url: form_url) do |f| %> + + <%= render 'shared/errors', resource: @video %> + + <%= f.hidden_field :answer_id, value: @video.answer_id || @answer.id %> + +
+
+ + <%= f.text_field :title %> + <%= f.text_field :url %> + +
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %> +
+
+ +
+
+<% end %> diff --git a/app/views/admin/poll/questions/answers/videos/edit.html.erb b/app/views/admin/poll/questions/answers/videos/edit.html.erb new file mode 100644 index 000000000..31b59c2dd --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/edit.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to %> + +

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

+ +
+ <%= render "form", form_url: admin_video_path(@video) %> +
diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb new file mode 100644 index 000000000..0ea64c570 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -0,0 +1,47 @@ +<%= back_link_to admin_question_path(@answer.question_id) %> + +
+ +

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

+ +<%= link_to t("admin.answers.videos.index.add_video"), + new_admin_answer_video_path, + class: "button success float-right" %> + +
+ + + + + + + + + + + + <% @answer.videos.each do |video| %> + + + + + + <% end %> + +
<%= t("admin.answers.videos.index.video_title") %><%= t("admin.answers.videos.index.video_url") %> + <%= t("admin.actions.actions") %> +
<%= video.title %><%= link_to "#{video.url}", video.url %> + + <%= link_to t("shared.edit"), + edit_admin_video_path(video), + class: "button hollow" %> + + <%= link_to t("shared.delete"), + admin_video_path(video), + class: "button hollow alert", + method: :delete %> +
+ +
diff --git a/app/views/admin/poll/questions/answers/videos/new.html.erb b/app/views/admin/poll/questions/answers/videos/new.html.erb new file mode 100644 index 000000000..d114b9104 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/new.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to admin_answer_videos_path(@answer) %> + +

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

+ +
+ <%= render "form", form_url: admin_answer_videos_path %> +
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index fd405d62f..371af51d2 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -43,6 +43,7 @@ <%= t("admin.questions.show.answers.title") %> <%= t("admin.questions.show.answers.description") %> <%= t("admin.questions.show.answers.images") %> + <%= t("admin.questions.show.answers.videos") %> <% @question.question_answers.each do |answer| %> @@ -52,8 +53,10 @@ (<%= answer.images.count %>)
<%= link_to t("admin.questions.show.answers.images_list"), - admin_answer_images_path(answer) %> - + admin_answer_images_path(answer) %> + <%= link_to t("admin.questions.show.answers.video_list", + count: answer.videos.count), + admin_answer_videos_path(answer) %> <% end %> @@ -65,11 +68,3 @@ <%= @question.video_url %>

<% end %> - -<% if @question.documents.any? %> -

- <%= t("admin.questions.show.documents") %> -
- <%= @question.documents.first.title %> -

-<% end %> diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index ba6cfc2e6..d71b6dcfe 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -16,7 +16,7 @@ - <% answer.images.each_with_index do |image, index| %> + <% answer.images.reverse.each_with_index do |image, index| %>
  • <%= link_to image.attachment.url(:original), target: "_blank" do %> <%= image_tag image.attachment.url(:medium), diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 2bef6de72..7fb4a5d71 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,9 +1,9 @@
    <% if can? :answer, question %> <% question.question_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer.title %> - "> + <% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %> + "> <%= answer.title %> <% else %> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index b632fac55..5d02aa891 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -38,6 +38,11 @@ <%= t("polls.show.already_voted_in_booth") %>
    <% else %> + <% if current_user && !@poll.votable_by?(current_user) %> +
    + <%= t("polls.show.already_voted_in_web") %> +
    + <% end %> <% @questions.each do |question| %> <%= render 'polls/questions/question', question: question %> <% end %> @@ -52,33 +57,38 @@ <%= safe_html_with_links simple_format(@poll.description) %>
  • - + <% end %>
    -
    +
    <% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
    + data-toggler=".medium-6" data-equalizer-watch> -

    <%= answer.title %>

    + <% if answer.description.present? %> +

    <%= answer.title %>

    + <% end %> <% if answer.images.any? %> <%= render "gallery", answer: answer %> <% end %> -
    - <%= safe_html_with_links simple_format(answer.description) %> -
    + <% if answer.description.present? %> +
    + <%= safe_html_with_links simple_format(answer.description) %> +
    + <% end %>
    <% end %>
    -
    diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 78435aa58..bf2cbb712 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -216,6 +216,9 @@ en: poll/question/answer: title: Answer description: Description + poll/question/answer/video: + title: Title + url: External video errors: models: user: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index b2b6aca3a..a415dbec6 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -599,12 +599,13 @@ en: author: Author title: Title valid_answers: Valid answers - add_answer: "Add answer" + add_answer: Add answer video_url: External video - documents: Documents (1) answers: title: Answer description: Description + videos: Videos + video_list: Video list (%{count}) images: Images images_list: Images list answers: @@ -617,6 +618,16 @@ en: images_list: Images list edit: title: Edit answer + videos: + index: + title: Videos + add_video: Add video + video_title: Title + video_url: External video + new: + title: New video + edit: + title: Edit video recounts: index: title: "Recounts" diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 11693d20f..82abea68b 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -478,7 +478,8 @@ en: help_text_1: "Voting takes place when a citizen proposal supports reaches 1% of the census with voting rights. Voting can also include questions that the City Council ask to the citizens decision." help_text_2: "To participate in the next vote you have to sign up on %{org} and verify your account. All registered voters in the city over 16 years old can vote. The results of all votes are binding on the government." show: - already_voted_in_booth: "You have already participated in a booth for this poll." + already_voted_in_booth: "You have already participated in a physical booth. You can not participate again." + already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten." back: Back to voting cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate." signin: Sign in diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml index fd187c495..88f68a955 100644 --- a/config/locales/en/responders.yml +++ b/config/locales/en/responders.yml @@ -9,6 +9,7 @@ en: poll: "Poll created successfully." poll_booth: "Booth created successfully." poll_question_answer: "Answer created successfully" + poll_question_answer_video: "Video created successfully" proposal: "Proposal created successfully." proposal_notification: "Your message has been sent correctly." spending_proposal: "Spending proposal created successfully. You can access it from %{activity}" @@ -31,3 +32,4 @@ en: budget_investment: "Investment project deleted succesfully." error: "Could not delete" topic: "Topic deleted successfully." + poll_question_answer_video: "Answer video deleted successfully." diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 03bcdfc60..f61e3bd53 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -210,6 +210,9 @@ es: poll/question/answer: title: Respuesta description: Descripción + poll/question/answer/video: + title: Título + url: Vídeo externo errors: models: user: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index d2b405fe7..9e6b66783 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -599,14 +599,14 @@ es: author: Autor title: Título valid_answers: Respuestas válidas - add_answer: "Añadir respuesta" - description: Descripción + add_answer: Añadir respuesta video_url: Video externo - documents: Documentos (1) preview: Ver en la web answers: title: Respuesta description: Descripción + videos: Vídeos + video_list: Lista de vídeos (%{count}) images: Imágenes images_list: Lista de imágenes answers: @@ -621,6 +621,16 @@ es: images_list: Lista de imágenes edit: title: Editar respuesta + videos: + index: + title: Vídeos + add_video: Añadir vídeo + video_title: Título + video_url: External video + new: + title: Nuevo video + edit: + title: Editar vídeo recounts: index: title: "Recuentos" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 981f85ca6..c613e6b40 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -478,7 +478,8 @@ es: help_text_1: "Las votaciones se convocan cuando una propuesta ciudadana alcanza el 1% de apoyos del censo con derecho a voto. En las votaciones también se pueden incluir cuestiones que el Ayuntamiento somete a decisión directa de la ciudadanía." help_text_2: "Para participar en la próxima votación tienes que registrarte en %{org} y verificar tu cuenta. Pueden votar todas las personas empadronadas en la ciudad mayores de 16 años. Los resultados de todas las votaciones serán vinculantes para el gobierno." show: - already_voted_in_booth: "Ya has participado en esta votación en una urna." + already_voted_in_booth: "Ya has participado en esta votación en urnas presenciales, no puedes volver a participar." + already_voted_in_web: "Ya has participado en esta votación. Si vuelves a votar se sobreescribirá tu resultado anterior." back: Volver a votaciones cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar." signin: iniciar sesión diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml index a35387ff3..01f19d96e 100644 --- a/config/locales/es/responders.yml +++ b/config/locales/es/responders.yml @@ -9,6 +9,7 @@ es: poll: "Votación creada correctamente." poll_booth: "Urna creada correctamente." poll_question_answer: "Respuesta creada correctamente" + poll_question_answer_video: "Vídeo creado correctamente" proposal: "Propuesta creada correctamente." proposal_notification: "Tu message ha sido enviado correctamente." spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}" @@ -31,3 +32,4 @@ es: budget_investment: "Propuesta de inversión eliminada." error: "No se pudo borrar" topic: "Tema eliminado." + poll_question_answer_video: "Vídeo de respuesta eliminado." diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index 59350d85d..82e9d180e 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -150,6 +150,9 @@ fr: poll/question/answer: title: Réponse description: Description + poll/question/answer/video: + title: Titre + url: Vidéo externe errors: models: user: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index df288a934..d80e55fc9 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -382,10 +382,14 @@ fr: author: Auteur title: Titre valid_answers: Réponses valides - add_answer: "Ajouter une réponse" - answer: "Réponse" - description: Description + add_answer: Ajouter une réponse + documents: Documents (1) preview: Voir l'aperçu + answers: + title: Réponse + description: Description + videos: Vidéos + video_list: Liste des vidéos (%{count}) answers: show: title: Titre @@ -396,6 +400,16 @@ fr: title: Nouvelle réponse edit: title: Modifier réponse + videos: + index: + title: Vidéos + add_video: Ajouter une vidéo + video_title: Titre + video_url: Vidéo externe + new: + title: Nouveau vidéo + edit: + title: Modifier la vidéo recounts: index: title: "Dépouillements" diff --git a/config/locales/fr/responders.yml b/config/locales/fr/responders.yml index 9897e3455..1d1cfae0c 100644 --- a/config/locales/fr/responders.yml +++ b/config/locales/fr/responders.yml @@ -8,6 +8,8 @@ fr: direct_message: "Votre message a été envoyé avec succès." poll: "Vote créé avec succès." poll_booth: "Urne créée avec succès." + poll_question_answer: "Réponse créée avec succès" + poll_question_answer_video: "Vidéo créée avec succès" proposal: "Proposition créée avec succès." proposal_notification: "Votre message a correctement été envoyé." spending_proposal: "Proposition de dépense créée avec succès. Vous pouvez y accéder depuis %{activity}" @@ -27,3 +29,4 @@ fr: spending_proposal: "Proposition de dépense supprimée avec succès." budget_investment: "Budget d'investissement supprimé avec succès." error: "Suppression impossible" + poll_question_answer_video: "Réponse vidéo supprimée avec succès." diff --git a/config/routes.rb b/config/routes.rb index 3a8f4b9cd..72d6c4d35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,11 +300,11 @@ Rails.application.routes.draw do end end - resources :questions do + resources :questions, shallow: true do resources :answers, except: [:index, :destroy, :delete], controller: 'questions/answers', shallow: true do resources :images, controller: 'questions/answers/images' + resources :videos, controller: 'questions/answers/videos' end - end end diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index b151a45cf..3ce1a439f 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -559,7 +559,6 @@ print "Creating Poll Questions" open_at = rand(2.months.ago..2.months.from_now) question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - description: description, valid_answers: Faker::Lorem.words((2..7).to_a.sample).join(', '), poll: poll) end diff --git a/db/migrate/20171004210108_create_poll_question_answer_videos.rb b/db/migrate/20171004210108_create_poll_question_answer_videos.rb new file mode 100644 index 000000000..7cce33b29 --- /dev/null +++ b/db/migrate/20171004210108_create_poll_question_answer_videos.rb @@ -0,0 +1,11 @@ +class CreatePollQuestionAnswerVideos < ActiveRecord::Migration + def change + create_table :poll_question_answer_videos do |t| + t.string :title + t.string :url + t.integer :answer_id, index: true + end + + add_foreign_key :poll_question_answer_videos, :poll_question_answers, column: :answer_id + end +end diff --git a/db/schema.rb b/db/schema.rb index dbbd3ec46..22e362a1f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171004151553) do +ActiveRecord::Schema.define(version: 20171004210108) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -668,6 +668,14 @@ ActiveRecord::Schema.define(version: 20171004151553) do add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree + create_table "poll_question_answer_videos", force: :cascade do |t| + t.string "title" + t.string "url" + t.integer "answer_id" + end + + add_index "poll_question_answer_videos", ["answer_id"], name: "index_poll_question_answer_videos_on_answer_id", using: :btree + create_table "poll_question_answers", force: :cascade do |t| t.string "title" t.text "description" @@ -1152,6 +1160,7 @@ ActiveRecord::Schema.define(version: 20171004151553) do add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_partial_results", "poll_questions", column: "question_id" add_foreign_key "poll_partial_results", "users", column: "author_id" + add_foreign_key "poll_question_answer_videos", "poll_question_answers", column: "answer_id" add_foreign_key "poll_question_answers", "poll_questions", column: "question_id" add_foreign_key "poll_questions", "polls" add_foreign_key "poll_questions", "proposals" diff --git a/spec/features/admin/poll/questions/answers/videos/videos_spec.rb b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb new file mode 100644 index 000000000..ee04ce128 --- /dev/null +++ b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +feature 'Videos' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + scenario "Create" do + question = create(:poll_question) + answer = create(:poll_question_answer, question: question) + video_title = "'Magical' by Junko Ohashi" + video_url = "https://www.youtube.com/watch?v=-JMf43st-1A" + + visit admin_question_path(question) + + within("#poll_question_answer_#{answer.id}") do + click_link "Video list (#{answer.videos.count})" + end + + click_link "Add video" + + fill_in 'poll_question_answer_video_title', with: video_title + fill_in 'poll_question_answer_video_url', with: video_url + + click_button "Save" + + expect(page).to have_content(video_title) + expect(page).to have_content(video_url) + end + +end diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index 7e103c647..5c8cba9c1 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -111,22 +111,4 @@ feature 'Admin poll questions' do pending "Mark all city by default when creating a poll question from a successful proposal" - it_behaves_like "nested documentable", - "administrator", - "poll_question", - "new_admin_question_path", - { }, - "documentable_fill_new_valid_poll_question", - "Save", - "Star Wars: Episode IV - A New Hope" - - it_behaves_like "nested documentable", - "administrator", - "poll_question", - "edit_admin_question_path", - { "id": "id" }, - nil, - "Save", - "Changes saved" - end diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 22b90740a..c3211e1ab 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -209,8 +209,7 @@ feature 'Polls' do visit poll_path(poll) expect(page).to have_link('Han Solo') - expect(page).to_not have_link('Chewbacca') - expect(page).to have_content('Chewbacca') + expect(page).to have_link('Chewbacca') end scenario 'Level 2 users answering', :js do diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 453924674..e558b7261 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -91,9 +91,32 @@ feature "Voter" do visit poll_path(poll) expect(page).to_not have_link('Yes') - expect(page).to have_content "You have already participated in a booth for this poll." + expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) end + + scenario "Trying to vote in web again", :js do + login_as user + vote_for_poll_via_web(poll, question) + + visit poll_path(poll) + + expect(page).to have_content "You have already participated in this poll. If you vote again it will be overwritten." + within("#poll_question_#{question.id}_answers") do + expect(page).to_not have_link('Yes') + end + + click_link "Sign out" + + login_as user + visit poll_path(poll) + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_link('Yes') + expect(page).to have_link('No') + end + + end end end diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 8780936a7..255f018e5 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -263,7 +263,6 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end - end end @@ -275,7 +274,7 @@ rescue return end -def documentable_attach_new_file(documentable_factory_name, index, path, success = true) +def documentable_attach_new_file(_documentable_factory_name, index, path, success = true) click_link "Add new document" document = all(".document")[index] document_input = document.find("input[type=file]", visible: false) @@ -318,8 +317,3 @@ def documentable_fill_new_valid_budget_investment fill_in_ckeditor "budget_investment_description", with: "Budget investment description" check :budget_investment_terms_of_service end - -def documentable_fill_new_valid_poll_question - page.select documentable.poll.name, from: 'poll_question_poll_id' - fill_in 'poll_question_title', with: "Star Wars: Episode IV - A New Hope" -end