From 39a2d25921017fc123661fc210d476781ce2aeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 5 Sep 2017 18:32:33 +0200 Subject: [PATCH 01/10] Created migration to add video_url to poll questions --- ...5111444_add_video_url_to_poll_questions.rb | 5 +++ db/schema.rb | 43 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170905111444_add_video_url_to_poll_questions.rb diff --git a/db/migrate/20170905111444_add_video_url_to_poll_questions.rb b/db/migrate/20170905111444_add_video_url_to_poll_questions.rb new file mode 100644 index 000000000..800ca915e --- /dev/null +++ b/db/migrate/20170905111444_add_video_url_to_poll_questions.rb @@ -0,0 +1,5 @@ +class AddVideoUrlToPollQuestions < ActiveRecord::Migration + def change + add_column :poll_questions, :video_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 60ae69a0c..cbd91beac 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: 20170720092638) do +ActiveRecord::Schema.define(version: 20170905111444) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -662,6 +662,7 @@ ActiveRecord::Schema.define(version: 20170720092638) do t.datetime "created_at" t.datetime "updated_at" t.tsvector "tsv" + t.string "video_url" end add_index "poll_questions", ["author_id"], name: "index_poll_questions_on_author_id", using: :btree @@ -669,6 +670,20 @@ ActiveRecord::Schema.define(version: 20170720092638) do add_index "poll_questions", ["proposal_id"], name: "index_poll_questions_on_proposal_id", using: :btree add_index "poll_questions", ["tsv"], name: "index_poll_questions_on_tsv", using: :gin + create_table "poll_recounts", force: :cascade do |t| + t.integer "booth_assignment_id" + t.integer "officer_assignment_id" + t.integer "count" + t.text "count_log", default: "" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.date "date", null: false + t.text "officer_assignment_id_log", default: "" + end + + add_index "poll_recounts", ["booth_assignment_id"], name: "index_poll_recounts_on_booth_assignment_id", using: :btree + add_index "poll_recounts", ["officer_assignment_id"], name: "index_poll_recounts_on_officer_assignment_id", using: :btree + create_table "poll_voters", force: :cascade do |t| t.string "document_number" t.string "document_type" @@ -883,6 +898,32 @@ ActiveRecord::Schema.define(version: 20170720092638) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree + create_table "tolk_locales", force: :cascade do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "tolk_locales", ["name"], name: "index_tolk_locales_on_name", unique: true, using: :btree + + create_table "tolk_phrases", force: :cascade do |t| + t.text "key" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "tolk_translations", force: :cascade do |t| + t.integer "phrase_id" + t.integer "locale_id" + t.text "text" + t.text "previous_text" + t.boolean "primary_updated", default: false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "tolk_translations", ["phrase_id", "locale_id"], name: "index_tolk_translations_on_phrase_id_and_locale_id", unique: true, using: :btree + create_table "users", force: :cascade do |t| t.string "email", default: "" t.string "encrypted_password", default: "", null: false From 4af44a45a131f7081231df5c48b3850769764487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 6 Sep 2017 12:00:46 +0200 Subject: [PATCH 02/10] Documents upload for questions working --- app/controllers/admin/poll/questions_controller.rb | 7 ++++++- app/controllers/polls/questions_controller.rb | 2 ++ app/models/poll/question.rb | 5 +++++ app/views/admin/poll/questions/_form.html.erb | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index ab7297a95..3bbe1c395 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -1,4 +1,6 @@ class Admin::Poll::QuestionsController < Admin::BaseController + include CommentableActions + load_and_authorize_resource :poll load_and_authorize_resource :question, class: 'Poll::Question' @@ -20,6 +22,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController def create @question.author = @question.proposal.try(:author) || current_user + recover_documents_from_cache(@question) if @question.save redirect_to admin_question_path(@question) @@ -29,6 +32,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController end def show + @document = Document.new(documentable: @question) end def edit @@ -54,7 +58,8 @@ class Admin::Poll::QuestionsController < Admin::BaseController private def question_params - params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers) + params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url, + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id]) end def search_params diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 1849dff97..bb1560f54 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -10,6 +10,8 @@ class Polls::QuestionsController < ApplicationController @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) set_comment_flags(@comment_tree.comments) + @document = Document.new(documentable: @question) + question_answer = @question.answers.where(author_id: current_user.try(:id)).first @answers_by_question_id = {@question.id => question_answer.try(:answer)} end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 28dd8ed4a..8e02dcfe2 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -1,6 +1,11 @@ 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/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb index 959aa4ddf..2b32ed680 100644 --- a/app/views/admin/poll/questions/_form.html.erb +++ b/app/views/admin/poll/questions/_form.html.erb @@ -26,6 +26,17 @@ ckeditor: { language: I18n.locale } %> +
+ <%= render 'documents/nested_documents', documentable: @question %> +
+ +
+ <%= f.label :video_url, t("proposals.form.proposal_video_url") %> +

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

+ <%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false, + aria: {describedby: "video-url-help-text"} %> +
+
<%= f.submit(class: "button expanded", value: t("shared.save")) %> From 11ab061b9be8bac3b5cf6b5efcd04ebbaf0d5935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 6 Sep 2017 17:27:05 +0200 Subject: [PATCH 03/10] Added documents to question view Added same subnavigation as proposals for comments and documents in poll questions. --- .../polls/questions/_filter_subnav.html.erb | 22 +++++++++++++++++++ app/views/polls/questions/show.html.erb | 14 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/views/polls/questions/_filter_subnav.html.erb diff --git a/app/views/polls/questions/_filter_subnav.html.erb b/app/views/polls/questions/_filter_subnav.html.erb new file mode 100644 index 000000000..738fc3700 --- /dev/null +++ b/app/views/polls/questions/_filter_subnav.html.erb @@ -0,0 +1,22 @@ +
+
+
    +
  • + <%= link_to "#tab-comments" do %> +

    + <%= t("proposals.show.comments_tab") %> + (<%= @question.comments_count %>) +

    + <% end %> +
  • +
  • + <%= link_to "#tab-documents" do %> +

    + <%= t("documents.tab") %> + (<%= @question.documents.count %>) +

    + <% end %> +
  • +
+
+
diff --git a/app/views/polls/questions/show.html.erb b/app/views/polls/questions/show.html.erb index da46ebbcc..a11ea5bd7 100644 --- a/app/views/polls/questions/show.html.erb +++ b/app/views/polls/questions/show.html.erb @@ -62,4 +62,16 @@
-<%= render "comments" %> +
+ <%= render "polls/questions/filter_subnav" %> + +
+ <%= render "polls/questions/comments" %> +
+ +
+ <%= render 'documents/documents', + documents: @question.documents, + max_documents_allowed: Poll::Question.max_documents_allowed %> +
+
From 288cedc4c4f79edf704ad48b178f5e11c6dee811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 6 Sep 2017 18:25:41 +0200 Subject: [PATCH 04/10] Poll questions documents tests added --- spec/factories.rb | 4 ++++ spec/models/abilities/administrator_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 7b1f6a417..ce92c88d3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -380,6 +380,10 @@ FactoryGirl.define do trait :budget_investment_document do association :documentable, factory: :budget_investment end + + trait :poll_question_document do + association :documentable, factory: :poll_question + end end factory :comment do diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index bbec927a0..dcb099ecd 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -14,9 +14,11 @@ describe "Abilities::Administrator" do let(:proposal) { create(:proposal) } let(:budget_investment) { create(:budget_investment) } let(:legislation_question) { create(:legislation_question) } + let(:poll_question) { create(:poll_question) } let(:proposal_document) { build(:document, documentable: proposal) } let(:budget_investment_document) { build(:document, documentable: budget_investment) } + let(:poll_question_document) { build(:document, documentable: poll_question) } let(:hidden_debate) { create(:debate, :hidden) } let(:hidden_comment) { create(:comment, :hidden) } @@ -83,4 +85,8 @@ describe "Abilities::Administrator" do it { should be_able_to(:new, budget_investment_document) } it { should be_able_to(:create, budget_investment_document) } it { should be_able_to(:destroy, budget_investment_document) } + + it { should be_able_to(:new, poll_question_document) } + it { should be_able_to(:create, poll_question_document) } + it { should be_able_to(:destroy, poll_question_document) } end From 12e6b9e681ac91e743d3dbd3491d1a5aa13bdc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 6 Sep 2017 19:11:28 +0200 Subject: [PATCH 05/10] Added video link to question public view --- app/assets/stylesheets/participation.scss | 1 + app/views/polls/questions/show.html.erb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index e10c0327f..3c37e9657 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -314,6 +314,7 @@ .debate-show, .proposal-show, +.poll-question-show, .investment-project-show, .budget-investment-show, .polls-show, diff --git a/app/views/polls/questions/show.html.erb b/app/views/polls/questions/show.html.erb index a11ea5bd7..bab6605d9 100644 --- a/app/views/polls/questions/show.html.erb +++ b/app/views/polls/questions/show.html.erb @@ -55,6 +55,19 @@ +<% if @question.video_url.present? %> +
+ +
+ +<% end %> +

<%= t('poll_questions.show.more_info') %>

From 33f621850ad9e1bf2e1a3dab5ba5f9cb788d8330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 6 Sep 2017 20:20:01 +0200 Subject: [PATCH 06/10] Fixed schema --- db/schema.rb | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 7f4d4a569..9b4ffd97b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -677,20 +677,6 @@ ActiveRecord::Schema.define(version: 20170905111444) do add_index "poll_questions", ["proposal_id"], name: "index_poll_questions_on_proposal_id", using: :btree add_index "poll_questions", ["tsv"], name: "index_poll_questions_on_tsv", using: :gin - create_table "poll_recounts", force: :cascade do |t| - t.integer "booth_assignment_id" - t.integer "officer_assignment_id" - t.integer "count" - t.text "count_log", default: "" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.date "date", null: false - t.text "officer_assignment_id_log", default: "" - end - - add_index "poll_recounts", ["booth_assignment_id"], name: "index_poll_recounts_on_booth_assignment_id", using: :btree - add_index "poll_recounts", ["officer_assignment_id"], name: "index_poll_recounts_on_officer_assignment_id", using: :btree - create_table "poll_shifts", force: :cascade do |t| t.integer "booth_id" t.integer "officer_id" @@ -919,32 +905,6 @@ ActiveRecord::Schema.define(version: 20170905111444) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree - create_table "tolk_locales", force: :cascade do |t| - t.string "name" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "tolk_locales", ["name"], name: "index_tolk_locales_on_name", unique: true, using: :btree - - create_table "tolk_phrases", force: :cascade do |t| - t.text "key" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "tolk_translations", force: :cascade do |t| - t.integer "phrase_id" - t.integer "locale_id" - t.text "text" - t.text "previous_text" - t.boolean "primary_updated", default: false - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "tolk_translations", ["phrase_id", "locale_id"], name: "index_tolk_translations_on_phrase_id_and_locale_id", unique: true, using: :btree - create_table "topics", force: :cascade do |t| t.string "title", null: false t.text "description" @@ -1012,7 +972,7 @@ ActiveRecord::Schema.define(version: 20170905111444) do t.boolean "email_digest", default: true t.boolean "email_on_direct_message", default: true t.boolean "official_position_badge", default: false - t.datetime "password_changed_at", default: '2017-06-22 11:21:30', null: false + t.datetime "password_changed_at", default: '2017-09-06 18:19:39', null: false t.boolean "created_from_signature", default: false t.integer "failed_email_digests_count", default: 0 t.text "former_users_data_log", default: "" From 3ff89b247605cf572d9307894c9085493dda410d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 6 Sep 2017 20:29:59 +0200 Subject: [PATCH 07/10] CSS minor fix --- app/views/polls/questions/show.html.erb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/views/polls/questions/show.html.erb b/app/views/polls/questions/show.html.erb index bab6605d9..f67633129 100644 --- a/app/views/polls/questions/show.html.erb +++ b/app/views/polls/questions/show.html.erb @@ -56,13 +56,15 @@
<% if @question.video_url.present? %> -
- diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c91719104..d62d80e75 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -590,6 +590,8 @@ en: title: Title valid_answers: Valid answers description: Description + video_url: External video + documents: Documents preview: View on website recounts: index: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 58fd31aa1..76fc72204 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -509,7 +509,7 @@ es: assignments: "Turnos en esta urna" no_assignments: "Esta urna no tiene turnos asignados" flash: - create: "Añadido turno de presidente de mesa" + create: "Añadido turno de presidente de mesa" destroy: "Eliminado turno de presidente de mesa" poll_booth_assignments: flash: @@ -590,6 +590,8 @@ es: title: Título valid_answers: Respuestas válidas description: Descripción + video_url: Video externo + documents: Documentos preview: Ver en la web recounts: index: From 27ac4c58154ba75fad27d8816732b8839eeae0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 7 Sep 2017 17:19:07 +0200 Subject: [PATCH 09/10] Added poll questions documents and video specs New tests to ensure video URL is shown in the admin preview. Also that the video URL and documents are correctly saved after creating a question. --- spec/features/admin/poll/questions_spec.rb | 3 +++ spec/features/polls/questions_spec.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index e9b9f277a..392b2aabf 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -38,6 +38,7 @@ feature 'Admin poll questions' do Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy.... } + video_url = "https://puppyvideos.com" visit admin_questions_path click_link "Create question" @@ -45,11 +46,13 @@ feature 'Admin poll questions' do select 'Movies', from: 'poll_question_poll_id' fill_in 'poll_question_title', with: title fill_in 'poll_question_description', with: description + fill_in 'poll_question_video_url', with: video_url click_button 'Save' expect(page).to have_content(title) expect(page).to have_content(description) + expect(page).to have_content(video_url) end scenario 'Create from successful proposal index' do diff --git a/spec/features/polls/questions_spec.rb b/spec/features/polls/questions_spec.rb index 6f2225175..7368c7857 100644 --- a/spec/features/polls/questions_spec.rb +++ b/spec/features/polls/questions_spec.rb @@ -25,6 +25,25 @@ feature 'Poll Questions' do expect(page).to have_content(question_with_author_visible_name.author_visible_name) end + scenario '#show view has video_url present' do + poll = create(:poll) + normal_question = create(:poll_question, poll: poll, video_url: "https://puppyvideos.com") + + visit question_path(normal_question) + + expect(page).to have_link(normal_question.video_url) + end + + scenario '#show view has document present' do + poll = create(:poll) + normal_question = create(:poll_question, poll: poll) + document = create(:document, documentable: normal_question) + + visit question_path(normal_question) + + expect(page).to have_link(document.title) + end + context 'Answering' do let(:geozone) { create(:geozone) } let(:poll) { create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) } From fb5211f25159c60e4eccda9d786b3202f70c35d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 7 Sep 2017 17:51:55 +0200 Subject: [PATCH 10/10] Fixed test --- spec/features/polls/questions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/polls/questions_spec.rb b/spec/features/polls/questions_spec.rb index 7368c7857..1563ca81a 100644 --- a/spec/features/polls/questions_spec.rb +++ b/spec/features/polls/questions_spec.rb @@ -41,7 +41,7 @@ feature 'Poll Questions' do visit question_path(normal_question) - expect(page).to have_link(document.title) + expect(page).to have_content(document.title) end context 'Answering' do