<%= t("welcome.debates.title") %>
@@ -47,6 +47,5 @@#{Faker::Lorem.paragraphs.join('
')}
" open_at = rand(2.months.ago..2.months.from_now) - answers = Faker::Lorem.words((2..4).to_a.sample).map { |answer| answer.capitalize } question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - valid_answers: answers.join(', '), poll: poll) - answers.each do |answer| - Poll::Question::Answer.create!(question: question, title: answer, description: Faker::ChuckNorris.fact) + Faker::Lorem.words((2..4).to_a.sample).each do |answer| + Poll::Question::Answer.create!(question: question, title: answer.capitalize, description: Faker::ChuckNorris.fact) end end @@ -595,7 +613,10 @@ print "Creating Poll Questions from Proposals" 3.times do proposal = Proposal.reorder("RANDOM()").first poll = Poll.current.first - question = Poll::Question.create(valid_answers: "Yes, No", poll: poll) + question = Poll::Question.create(poll: poll) + Faker::Lorem.words((2..4).to_a.sample).each do |answer| + Poll::Question::Answer.create!(question: question, title: answer.capitalize, description: Faker::ChuckNorris.fact) + end question.copy_attributes_from_proposal(proposal) question.save! end @@ -606,7 +627,10 @@ print "Creating Successful Proposals" 10.times do proposal = Proposal.reorder("RANDOM()").first poll = Poll.current.first - question = Poll::Question.create(valid_answers: "Yes, No", poll: poll) + question = Poll::Question.create(poll: poll) + Faker::Lorem.words((2..4).to_a.sample).each do |answer| + Poll::Question::Answer.create!(question: question, title: answer.capitalize, description: Faker::ChuckNorris.fact) + end question.copy_attributes_from_proposal(proposal) question.save! end @@ -632,6 +656,49 @@ print "Creating Poll Voters" Poll::Voter.create(poll: poll, user: user) end +puts " ✅" +print "Creating Poll Recounts" + +Poll.all.each do |poll| + poll.booth_assignments.each do |booth_assignment| + officer_assignment = poll.officer_assignments.first + author = Poll::Officer.first.user + + Poll::Recount.create!(officer_assignment: officer_assignment, + booth_assignment: booth_assignment, + author: author, + date: poll.ends_at, + white_amount: rand(0..10), + null_amount: rand(0..10), + total_amount: rand(100..9999), + origin: "booth") + end +end + +puts " ✅" +print "Creating Poll Results" + +Poll.all.each do |poll| + poll.booth_assignments.each do |booth_assignment| + officer_assignment = poll.officer_assignments.first + author = Poll::Officer.first.user + + poll.questions.each do |question| + question.question_answers.each do |answer| + Poll::PartialResult.create!(officer_assignment: officer_assignment, + booth_assignment: booth_assignment, + date: Date.current, + question: question, + answer: answer.title, + author: author, + amount: rand(999), + origin: "booth") + end + end + end + +end + puts " ✅" print "Creating legislation processes" @@ -652,8 +719,7 @@ print "Creating legislation processes" allegations_phase_enabled: true, draft_publication_enabled: true, result_publication_enabled: true, - published: true - ) + published: true) end ::Legislation::Process.all.each do |process| diff --git a/db/migrate/20171002133547_remove_poll_white_null_total_results.rb b/db/migrate/20171002133547_remove_poll_white_null_total_results.rb new file mode 100644 index 000000000..5fff82ef3 --- /dev/null +++ b/db/migrate/20171002133547_remove_poll_white_null_total_results.rb @@ -0,0 +1,16 @@ +class RemovePollWhiteNullTotalResults < ActiveRecord::Migration + def change + remove_index :poll_null_results, column: [:booth_assignment_id] + remove_index :poll_null_results, column: [:officer_assignment_id] + + remove_index :poll_white_results, column: [:booth_assignment_id] + remove_index :poll_white_results, column: [:officer_assignment_id] + + remove_index :poll_total_results, column: [:booth_assignment_id] + remove_index :poll_total_results, column: [:officer_assignment_id] + + drop_table :poll_null_results + drop_table :poll_total_results + drop_table :poll_white_results + end +end diff --git a/db/migrate/20171003143034_add_comments_count_to_polls.rb b/db/migrate/20171003143034_add_comments_count_to_polls.rb new file mode 100644 index 000000000..675acae3f --- /dev/null +++ b/db/migrate/20171003143034_add_comments_count_to_polls.rb @@ -0,0 +1,7 @@ +class AddCommentsCountToPolls < ActiveRecord::Migration + def change + add_column :polls, :comments_count, :integer, default: 0 + add_column :polls, :author_id, :integer + add_column :polls, :hidden_at, :datetime + end +end diff --git a/db/migrate/20171010143623_add_given_order_to_poll_question_answers.rb b/db/migrate/20171010143623_add_given_order_to_poll_question_answers.rb new file mode 100644 index 000000000..6161e55e4 --- /dev/null +++ b/db/migrate/20171010143623_add_given_order_to_poll_question_answers.rb @@ -0,0 +1,5 @@ +class AddGivenOrderToPollQuestionAnswers < ActiveRecord::Migration + def change + add_column :poll_question_answers, :given_order, :integer, default: 1 + end +end diff --git a/db/migrate/20171017221546_remove_poll_question_valid_answers.rb b/db/migrate/20171017221546_remove_poll_question_valid_answers.rb new file mode 100644 index 000000000..e4c1ebb11 --- /dev/null +++ b/db/migrate/20171017221546_remove_poll_question_valid_answers.rb @@ -0,0 +1,5 @@ +class RemovePollQuestionValidAnswers < ActiveRecord::Migration + def change + remove_column :poll_questions, :valid_answers + end +end diff --git a/db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb b/db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb new file mode 100644 index 000000000..e4650643b --- /dev/null +++ b/db/migrate/20171019095042_add_most_voted_to_poll_question_answer.rb @@ -0,0 +1,5 @@ +class AddMostVotedToPollQuestionAnswer < ActiveRecord::Migration + def change + add_column :poll_question_answers, :most_voted, :boolean, default: false + end +end diff --git a/db/migrate/20171020163240_add_results_and_stats_to_polls.rb b/db/migrate/20171020163240_add_results_and_stats_to_polls.rb new file mode 100644 index 000000000..af6f82aaa --- /dev/null +++ b/db/migrate/20171020163240_add_results_and_stats_to_polls.rb @@ -0,0 +1,6 @@ +class AddResultsAndStatsToPolls < ActiveRecord::Migration + def change + add_column :polls, :results_enabled, :boolean, default: false + add_column :polls, :stats_enabled, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 9aa04f187..f8dd19c13 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: 20171006145053) do +ActiveRecord::Schema.define(version: 20171020163240) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -647,21 +647,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do t.string "location" end - create_table "poll_null_results", force: :cascade do |t| - t.integer "author_id" - t.integer "amount" - t.string "origin" - t.date "date" - t.integer "booth_assignment_id" - t.integer "officer_assignment_id" - t.text "amount_log", default: "" - t.text "officer_assignment_id_log", default: "" - t.text "author_id_log", default: "" - end - - add_index "poll_null_results", ["booth_assignment_id"], name: "index_poll_null_results_on_booth_assignment_id", using: :btree - add_index "poll_null_results", ["officer_assignment_id"], name: "index_poll_null_results_on_officer_assignment_id", using: :btree - create_table "poll_officer_assignments", force: :cascade do |t| t.integer "booth_assignment_id" t.integer "officer_id" @@ -714,6 +699,8 @@ ActiveRecord::Schema.define(version: 20171006145053) do t.string "title" t.text "description" t.integer "question_id" + t.integer "given_order", default: 1 + t.boolean "most_voted", default: false end add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree @@ -724,7 +711,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do t.integer "author_id" t.string "author_visible_name" t.string "title" - t.string "valid_answers" t.integer "comments_count" t.datetime "hidden_at" t.datetime "created_at" @@ -772,21 +758,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree - create_table "poll_total_results", force: :cascade do |t| - t.integer "author_id" - t.integer "amount" - t.string "origin" - t.date "date" - t.integer "booth_assignment_id" - t.integer "officer_assignment_id" - t.text "amount_log", default: "" - t.text "officer_assignment_id_log", default: "" - t.text "author_id_log", default: "" - end - - add_index "poll_total_results", ["booth_assignment_id"], name: "index_poll_total_results_on_booth_assignment_id", using: :btree - add_index "poll_total_results", ["officer_assignment_id"], name: "index_poll_total_results_on_officer_assignment_id", using: :btree - create_table "poll_voters", force: :cascade do |t| t.string "document_number" t.string "document_type" @@ -812,21 +783,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do add_index "poll_voters", ["poll_id"], name: "index_poll_voters_on_poll_id", using: :btree add_index "poll_voters", ["user_id"], name: "index_poll_voters_on_user_id", using: :btree - create_table "poll_white_results", force: :cascade do |t| - t.integer "author_id" - t.integer "amount" - t.string "origin" - t.date "date" - t.integer "booth_assignment_id" - t.integer "officer_assignment_id" - t.text "amount_log", default: "" - t.text "officer_assignment_id_log", default: "" - t.text "author_id_log", default: "" - end - - add_index "poll_white_results", ["booth_assignment_id"], name: "index_poll_white_results_on_booth_assignment_id", using: :btree - add_index "poll_white_results", ["officer_assignment_id"], name: "index_poll_white_results_on_officer_assignment_id", using: :btree - create_table "polls", force: :cascade do |t| t.string "name" t.datetime "starts_at" @@ -835,6 +791,11 @@ ActiveRecord::Schema.define(version: 20171006145053) do t.boolean "geozone_restricted", default: false t.text "summary" t.text "description" + t.integer "comments_count", default: 0 + t.integer "author_id" + t.datetime "hidden_at" + t.boolean "results_enabled", default: false + t.boolean "stats_enabled", default: false end add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree @@ -1193,8 +1154,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do add_foreign_key "organizations", "users" add_foreign_key "poll_answers", "poll_questions", column: "question_id" add_foreign_key "poll_booth_assignments", "polls" - add_foreign_key "poll_null_results", "poll_booth_assignments", column: "booth_assignment_id" - add_foreign_key "poll_null_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_officer_assignments", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_partial_results", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id" @@ -1208,8 +1167,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do add_foreign_key "poll_recounts", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_recounts", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_voters", "polls" - add_foreign_key "poll_white_results", "poll_booth_assignments", column: "booth_assignment_id" - add_foreign_key "poll_white_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "proposals", "communities" add_foreign_key "users", "geozones" add_foreign_key "valuators", "users" diff --git a/knapsack_rspec_report.json b/knapsack_rspec_report.json index 595276b2b..5f1fc06b5 100644 --- a/knapsack_rspec_report.json +++ b/knapsack_rspec_report.json @@ -1,226 +1,227 @@ { - "spec/helpers/comments_helper_spec.rb": 0.010898828506469727, - "spec/controllers/graphql_controller_spec.rb": 0.7817962169647217, - "spec/controllers/concerns/has_orders_spec.rb": 0.09597063064575195, - "spec/features/officing/results_spec.rb": 2.6492855548858643, - "spec/models/poll/question_spec.rb": 0.09519433975219727, - "spec/features/organizations_spec.rb": 1.9025108814239502, - "spec/models/legislation/process_spec.rb": 0.09253501892089844, - "spec/lib/acts_as_paranoid_aliases_spec.rb": 0.2438969612121582, - "spec/features/officing_spec.rb": 1.4767742156982422, - "spec/lib/age_spec.rb": 0.0006227493286132812, - "spec/models/proposal_spec.rb": 5.535696983337402, - "spec/models/abilities/administrator_spec.rb": 2.2431821823120117, - "spec/models/poll/final_recount_spec.rb": 0.1787703037261963, - "spec/lib/graph_ql/query_type_creator_spec.rb": 0.012041091918945312, - "spec/models/verification/management/email_spec.rb": 0.06403493881225586, - "spec/models/flag_spec.rb": 0.46442556381225586, - "spec/features/tags/budget_investments_spec.rb": 23.748523235321045, - "spec/features/campaigns_spec.rb": 1.3289697170257568, - "spec/features/admin/activity_spec.rb": 7.763890743255615, - "spec/features/polls/questions_spec.rb": 2.61055326461792, - "spec/features/polls/polls_spec.rb": 2.313369035720825, - "spec/features/home_spec.rb": 0.9780440330505371, - "spec/models/poll/partial_result_spec.rb": 0.3302469253540039, - "spec/models/lock_spec.rb": 0.09437012672424316, - "spec/lib/graph_ql/api_types_creator_spec.rb": 0.0069005489349365234, - "spec/helpers/users_helper_spec.rb": 0.3229796886444092, - "spec/lib/local_census_spec.rb": 0.011091947555541992, - "spec/helpers/text_helper_spec.rb": 0.0005347728729248047, - "spec/customization_engine_spec.rb": 1.3630127906799316, - "spec/models/legislation/answer_spec.rb": 0.6906075477600098, - "spec/models/budget/ballot/line_spec.rb": 0.5054352283477783, - "spec/features/admin/proposals_spec.rb": 1.6710176467895508, - "spec/features/proposal_ballots_spec.rb": 0.3399386405944824, - "spec/models/site_customization/content_block_spec.rb": 0.014521121978759766, - "spec/features/admin/site_customization/content_blocks_spec.rb": 1.2890841960906982, - "spec/models/site_customization/page_spec.rb": 0.011090993881225586, - "spec/features/verification/email_spec.rb": 1.0991628170013428, - "spec/models/proposal_notification_spec.rb": 0.2569601535797119, - "spec/features/registration_form_spec.rb": 0.7285032272338867, - "spec/features/communities_spec.rb": 1.7133822441101074, - "spec/features/admin/moderators_spec.rb": 1.2922589778900146, - "spec/helpers/geozones_helper_spec.rb": 0.09812736511230469, - "spec/features/welcome_spec.rb": 1.5019774436950684, - "spec/controllers/comments_controller_spec.rb": 0.36508607864379883, - "spec/features/admin/legislation/questions_spec.rb": 3.81538724899292, - "spec/controllers/users/registrations_controller_spec.rb": 0.018311023712158203, - "spec/features/comments/debates_spec.rb": 12.265411615371704, - "spec/features/users_spec.rb": 11.05901050567627, - "spec/models/budget/group_spec.rb": 0.04957008361816406, - "spec/features/admin/poll/questions_spec.rb": 1.9041199684143066, - "spec/helpers/admin_helper_spec.rb": 0.00651097297668457, - "spec/models/abilities/organization_spec.rb": 0.24821996688842773, - "spec/features/moderation/comments_spec.rb": 6.318082332611084, - "spec/features/admin/poll/polls_spec.rb": 8.88325023651123, - "spec/models/activity_spec.rb": 0.9704892635345459, - "spec/features/verification/level_two_verification_spec.rb": 0.421832799911499, - "spec/models/poll/officer_assignment_spec.rb": 0.029267072677612305, - "spec/features/admin/verifications_spec.rb": 0.507885217666626, - "spec/mailers/mailer_spec.rb": 0.07406282424926758, - "spec/models/legislation/draft_version_spec.rb": 0.025011777877807617, - "spec/models/budget/investment_spec.rb": 9.084597826004028, - "spec/features/proposals_spec.rb": 183.71455550193787, - "spec/features/tags_spec.rb": 2.949070453643799, - "spec/features/tags/debates_spec.rb": 4.345250368118286, - "spec/features/admin/geozones_spec.rb": 1.935765027999878, - "spec/features/admin/feature_flags_spec.rb": 0.8357558250427246, - "spec/models/user_spec.rb": 2.436626434326172, - "spec/features/moderation/debates_spec.rb": 6.05112886428833, - "spec/models/legislation/annotation_spec.rb": 0.21427702903747559, - "spec/features/comments/proposals_spec.rb": 32.52879500389099, - "spec/controllers/legislation/answers_controller_spec.rb": 0.3481717109680176, - "spec/features/verification/sms_spec.rb": 1.2817349433898926, - "spec/features/admin/budget_investments_spec.rb": 16.1332266330719, - "spec/features/notifications_spec.rb": 14.857182264328003, - "spec/lib/tag_sanitizer_spec.rb": 0.0005936622619628906, - "spec/controllers/admin/api/stats_controller_spec.rb": 0.3948392868041992, - "spec/features/comments/topics_spec.rb": 29.646622896194458, - "spec/models/debate_spec.rb": 5.2278876304626465, - "spec/lib/email_digests_spec.rb": 0.6660604476928711, - "spec/models/abilities/everyone_spec.rb": 0.06328749656677246, - "spec/features/direct_messages_spec.rb": 1.3006987571716309, - "spec/features/debates_spec.rb": 28.736626386642456, - "spec/models/setting_spec.rb": 0.07938265800476074, - "spec/models/legislation/question_option_spec.rb": 0.058206796646118164, - "spec/models/verification/management/document_spec.rb": 0.013574600219726562, - "spec/models/poll/booth_spec.rb": 0.07824325561523438, - "spec/features/admin/legislation/draft_versions_spec.rb": 3.750009059906006, - "spec/features/admin/poll/officers_spec.rb": 1.4151291847229004, - "spec/features/moderation_spec.rb": 1.9578778743743896, - "spec/features/legislation/questions_spec.rb": 1.7689197063446045, - "spec/features/officing/residence_spec.rb": 0.971078634262085, - "spec/models/follow_spec.rb": 0.12199592590332031, - "spec/lib/census_api_spec.rb": 0.0019702911376953125, - "spec/models/tag_cloud_spec.rb": 1.5725350379943848, - "spec/models/budget_spec.rb": 0.2335052490234375, - "spec/features/management/localization_spec.rb": 1.1911811828613281, - "spec/features/legislation/draft_versions_spec.rb": 8.151643514633179, - "spec/models/budget/heading_spec.rb": 0.09901237487792969, - "spec/models/poll/poll_spec.rb": 0.46999382972717285, - "spec/models/custom/residence_spec.rb": 0.050164222717285156, - "spec/models/notification_spec.rb": 0.39408183097839355, - "spec/features/budgets/ballots_spec.rb": 27.406018257141113, - "spec/mailers/devise_mailer_spec.rb": 0.16486406326293945, - "spec/features/admin/debates_spec.rb": 1.546919345855713, - "spec/features/valuation/budgets_spec.rb": 0.2552778720855713, - "spec/models/abilities/common_spec.rb": 6.724466562271118, - "spec/models/residence_spec.rb": 0.24986696243286133, - "spec/features/officing/voters_spec.rb": 2.954087257385254, - "spec/models/vote_spec.rb": 1.3241477012634277, - "spec/lib/migrate_spending_proposals_to_investments_spec.rb": 1.1774518489837646, - "spec/controllers/management/users_controller_spec.rb": 0.007733821868896484, - "spec/helpers/proposals_helper_spec.rb": 0.21885180473327637, - "spec/features/ckeditor_spec.rb": 0.7726309299468994, - "spec/lib/census_caller_spec.rb": 0.009332895278930664, - "spec/features/tracks_spec.rb": 2.7082908153533936, - "spec/features/admin/budgets_spec.rb": 4.468225002288818, - "spec/features/admin/valuators_spec.rb": 1.3326430320739746, - "spec/features/admin/banners_spec.rb": 3.302579164505005, - "spec/features/account_spec.rb": 2.30243182182312, - "spec/features/budgets/budgets_spec.rb": 1.0318260192871094, - "spec/models/poll/answer_spec.rb": 0.11362218856811523, - "spec/features/comments/budget_investments_spec.rb": 16.92409658432007, - "spec/features/budgets/results_spec.rb": 2.589841365814209, - "spec/features/valuation_spec.rb": 2.126727819442749, - "spec/features/stats_spec.rb": 0.8516559600830078, - "spec/features/admin/poll/booths_spec.rb": 1.766916275024414, - "spec/models/legislation/process/phase_spec.rb": 0.0886683464050293, - "spec/models/budget/investment/milestone_spec.rb": 0.1419520378112793, - "spec/models/letter_spec.rb": 0.08197903633117676, - "spec/features/admin/stats_spec.rb": 3.6946730613708496, - "spec/models/identity_spec.rb": 0.004762887954711914, - "spec/features/verification/letter_spec.rb": 1.7480952739715576, - "spec/models/topic_spec.rb": 0.30414509773254395, - "spec/features/users_auth_spec.rb": 7.242254257202148, - "spec/lib/acts_as_taggable_on_spec.rb": 0.7477433681488037, - "spec/features/official_positions_spec.rb": 1.9427640438079834, - "spec/features/admin/newsletters_spec.rb": 0.22768402099609375, - "spec/features/admin/hidden_users_spec.rb": 1.4156956672668457, - "spec/features/comments/legislation_annotations_spec.rb": 18.616747856140137, - "spec/features/admin/site_customization/pages_spec.rb": 1.0219447612762451, - "spec/models/poll/shift_spec.rb": 0.2051677703857422, - "spec/models/geozone_spec.rb": 0.12972474098205566, - "spec/helpers/verification_helper_spec.rb": 0.0009250640869140625, - "spec/lib/cache_spec.rb": 0.06447911262512207, - "spec/features/verification/verification_path_spec.rb": 1.2300751209259033, - "spec/features/sessions_spec.rb": 0.3665180206298828, - "spec/controllers/management/base_controller_spec.rb": 0.019928932189941406, - "spec/features/verification/verified_user_spec.rb": 0.787623405456543, - "spec/models/direct_message_spec.rb": 0.49156641960144043, - "spec/features/admin/tags_spec.rb": 1.045637845993042, - "spec/features/admin/comments_spec.rb": 3.4312756061553955, - "spec/features/moderation/users_spec.rb": 1.1841027736663818, - "spec/models/budget/reclassified_vote_spec.rb": 0.22663235664367676, - "spec/features/admin/organizations_spec.rb": 3.4465878009796143, - "spec/features/proposal_notifications_spec.rb": 4.40612268447876, - "spec/features/emails_spec.rb": 13.047018051147461, - "spec/controllers/debates_controller_spec.rb": 0.3078582286834717, - "spec/features/budgets/investments_spec.rb": 126.55784440040588, - "spec/features/verification/residence_spec.rb": 1.8894774913787842, - "spec/models/abilities/moderator_spec.rb": 2.7029502391815186, - "spec/helpers/votes_helper_spec.rb": 0.363523006439209, - "spec/features/tags/proposals_spec.rb": 8.272820949554443, - "spec/models/signature_spec.rb": 1.6858570575714111, - "spec/models/legislation/process/publication_spec.rb": 0.0707387924194336, - "spec/models/community_spec.rb": 0.13965797424316406, - "spec/models/sms_spec.rb": 0.024147987365722656, - "spec/lib/graphql_spec.rb": 3.7293970584869385, - "spec/lib/tasks/communities_spec.rb": 0.17484474182128906, - "spec/features/management/proposals_spec.rb": 4.549585580825806, - "spec/models/document_spec.rb": 1.2667145729064941, - "spec/features/site_customization/content_blocks_spec.rb": 0.3020951747894287, - "spec/features/localization_spec.rb": 0.5679850578308105, - "spec/models/signature_sheet_spec.rb": 0.7970001697540283, - "spec/features/budgets/votes_spec.rb": 4.38911509513855, - "spec/features/verification/level_three_verification_spec.rb": 1.2754230499267578, - "spec/features/admin/users_spec.rb": 0.3584918975830078, - "spec/models/abilities/valuator_spec.rb": 1.1300320625305176, - "spec/models/officing/residence_spec.rb": 0.3599817752838135, - "spec/features/admin/officials_spec.rb": 0.940401554107666, - "spec/features/admin/settings_spec.rb": 0.37268495559692383, - "spec/models/ahoy/data_source_spec.rb": 0.04887723922729492, - "spec/helpers/settings_helper_spec.rb": 0.020088911056518555, - "spec/models/budget/result_spec.rb": 0.7962813377380371, - "spec/models/poll/null_result_spec.rb": 0.17995309829711914, - "spec/models/valuator_spec.rb": 0.02411341667175293, - "spec/lib/manager_authenticator_spec.rb": 0.0031435489654541016, - "spec/lib/tasks/settings_spec.rb": 0.07562613487243652, - "spec/controllers/legislation/annotations_controller_spec.rb": 0.712010383605957, - "spec/models/comment_spec.rb": 1.7274408340454102, - "spec/features/comments/legislation_questions_spec.rb": 15.219935894012451, - "spec/features/admin_spec.rb": 1.1390578746795654, - "spec/features/admin/poll/booth_assigments_spec.rb": 3.737426280975342, - "spec/controllers/pages_controller_spec.rb": 0.3043200969696045, - "spec/features/admin/administrators_spec.rb": 2.7916433811187744, - "spec/models/poll/total_result_spec.rb": 0.549537181854248, - "spec/features/management/managed_users_spec.rb": 4.38576078414917, - "spec/models/poll/officer_spec.rb": 0.49225711822509766, - "spec/features/user_invites_spec.rb": 0.21891093254089355, - "spec/helpers/application_helper_spec.rb": 0.13661718368530273, - "spec/features/management/account_spec.rb": 0.9717822074890137, - "spec/features/management/document_verifications_spec.rb": 1.0395607948303223, - "spec/features/admin/site_customization/images_spec.rb": 1.2623581886291504, - "spec/models/organization_spec.rb": 0.16587495803833008, - "spec/features/management/email_verifications_spec.rb": 0.46370506286621094, - "spec/features/legislation/processes_spec.rb": 3.2473270893096924, - "spec/features/admin/managers_spec.rb": 1.1836414337158203, - "spec/models/legislation/question_spec.rb": 0.4404168128967285, - "spec/features/management/budget_investments_spec.rb": 7.179029703140259, - "spec/features/admin/signature_sheets_spec.rb": 1.4004056453704834, - "spec/features/admin/poll/shifts_spec.rb": 2.6800806522369385, - "spec/i18n_spec.rb": 58.107173204422, - "spec/features/site_customization/custom_pages_spec.rb": 0.454498291015625, - "spec/features/admin/legislation/processes_spec.rb": 3.3492519855499268, - "spec/features/votes_spec.rb": 16.538654088974, - "spec/features/admin/budget_investment_milestones_spec.rb": 1.3747622966766357, - "spec/models/poll/white_result_spec.rb": 0.23045921325683594, - "spec/controllers/management/sessions_controller_spec.rb": 0.06758952140808105, - "spec/features/management/users_spec.rb": 2.044326066970825, - "spec/controllers/concerns/has_filters_spec.rb": 0.275907039642334, - "spec/features/moderation/proposals_spec.rb": 5.00596022605896, - "spec/lib/wysiwyg_sanitizer_spec.rb": 0.0016448497772216797, - "spec/models/budget/ballot_spec.rb": 0.6595156192779541, - "spec/models/poll/voter_spec.rb": 0.2982313632965088, - "spec/features/valuation/budget_investments_spec.rb": 6.490516185760498 + "spec/models/setting_spec.rb": 0.07869887351989746, + "spec/features/admin/managers_spec.rb": 5.029380798339844, + "spec/features/management/managed_users_spec.rb": 3.1642160415649414, + "spec/features/admin/poll/booths_spec.rb": 1.4152588844299316, + "spec/features/admin/comments_spec.rb": 3.889301061630249, + "spec/helpers/admin_helper_spec.rb": 0.005057334899902344, + "spec/models/abilities/moderator_spec.rb": 2.3274271488189697, + "spec/controllers/admin/api/stats_controller_spec.rb": 0.4249396324157715, + "spec/features/admin/organizations_spec.rb": 3.339292049407959, + "spec/features/admin/newsletters_spec.rb": 0.2460641860961914, + "spec/helpers/geozones_helper_spec.rb": 0.08249163627624512, + "spec/lib/graph_ql/api_types_creator_spec.rb": 0.006573915481567383, + "spec/features/emails_spec.rb": 18.91256046295166, + "spec/features/admin/hidden_users_spec.rb": 1.3854436874389648, + "spec/features/welcome_spec.rb": 1.1956276893615723, + "spec/features/sessions_spec.rb": 0.3943772315979004, + "spec/models/custom/residence_spec.rb": 0.07002687454223633, + "spec/models/poll/booth_spec.rb": 0.05489993095397949, + "spec/models/direct_message_spec.rb": 0.3973381519317627, + "spec/features/valuation/budget_investments_spec.rb": 7.6013023853302, + "spec/models/map_location_spec.rb": 0.12476563453674316, + "spec/models/budget/heading_spec.rb": 0.09248590469360352, + "spec/models/user_spec.rb": 2.9006423950195312, + "spec/features/admin/site_customization/content_blocks_spec.rb": 1.6733989715576172, + "spec/mailers/mailer_spec.rb": 0.08513784408569336, + "spec/models/site_customization/page_spec.rb": 0.015056133270263672, + "spec/features/management/budget_investments_spec.rb": 8.112786293029785, + "spec/features/admin/activity_spec.rb": 12.442089080810547, + "spec/features/registration_form_spec.rb": 1.0509357452392578, + "spec/controllers/legislation/annotations_controller_spec.rb": 0.8151364326477051, + "spec/lib/census_caller_spec.rb": 0.018165111541748047, + "spec/features/users_auth_spec.rb": 6.5102221965789795, + "spec/features/tags/proposals_spec.rb": 10.001718521118164, + "spec/features/account_spec.rb": 2.2510504722595215, + "spec/features/admin/users_spec.rb": 0.4342050552368164, + "spec/lib/cache_spec.rb": 0.057682037353515625, + "spec/features/valuation_spec.rb": 1.3436784744262695, + "spec/models/budget/investment_spec.rb": 12.89230751991272, + "spec/lib/migrate_spending_proposals_to_investments_spec.rb": 0.904367208480835, + "spec/helpers/settings_helper_spec.rb": 0.02300858497619629, + "spec/helpers/application_helper_spec.rb": 0.09152626991271973, + "spec/models/legislation/draft_version_spec.rb": 0.020322084426879883, + "spec/models/legislation/question_spec.rb": 0.3402721881866455, + "spec/models/document_spec.rb": 1.3238348960876465, + "spec/models/poll/question_spec.rb": 0.12588191032409668, + "spec/features/admin/poll/polls_spec.rb": 11.77881646156311, + "spec/lib/manager_authenticator_spec.rb": 0.006296873092651367, + "spec/features/admin/debates_spec.rb": 1.688420295715332, + "spec/features/moderation/debates_spec.rb": 5.343512773513794, + "spec/controllers/debates_controller_spec.rb": 0.40573883056640625, + "spec/models/tag_cloud_spec.rb": 1.6984672546386719, + "spec/models/budget/investment/milestone_spec.rb": 0.15051603317260742, + "spec/models/proposal_notification_spec.rb": 0.2914905548095703, + "spec/features/budgets/investments_spec.rb": 93.5263159275055, + "spec/i18n_spec.rb": 96.26275777816772, + "spec/models/community_spec.rb": 0.16270899772644043, + "spec/controllers/graphql_controller_spec.rb": 0.5831413269042969, + "spec/models/legislation/annotation_spec.rb": 0.16232728958129883, + "spec/lib/acts_as_taggable_on_spec.rb": 0.5747356414794922, + "spec/lib/census_api_spec.rb": 0.0021581649780273438, + "spec/features/moderation/comments_spec.rb": 6.70704984664917, + "spec/models/poll/voter_spec.rb": 0.32018303871154785, + "spec/features/proposal_notifications_spec.rb": 3.906450033187866, + "spec/models/budget/result_spec.rb": 0.8468267917633057, + "spec/helpers/users_helper_spec.rb": 0.25751638412475586, + "spec/features/valuation/budgets_spec.rb": 0.2564871311187744, + "spec/controllers/users/registrations_controller_spec.rb": 0.022383689880371094, + "spec/controllers/management/base_controller_spec.rb": 0.06711888313293457, + "spec/features/admin/officials_spec.rb": 0.893528938293457, + "spec/features/comments/topics_spec.rb": 29.998314142227173, + "spec/features/users_spec.rb": 11.885858297348022, + "spec/models/topic_spec.rb": 0.27634167671203613, + "spec/models/follow_spec.rb": 0.1256728172302246, + "spec/lib/local_census_spec.rb": 0.005529880523681641, + "spec/features/verification/sms_spec.rb": 1.5214743614196777, + "spec/helpers/comments_helper_spec.rb": 0.010879278182983398, + "spec/models/valuator_spec.rb": 0.02650904655456543, + "spec/features/proposal_ballots_spec.rb": 0.3937220573425293, + "spec/features/proposals_spec.rb": 142.48229122161865, + "spec/features/legislation/processes_spec.rb": 2.863476514816284, + "spec/features/ckeditor_spec.rb": 0.8433480262756348, + "spec/models/letter_spec.rb": 0.0695810317993164, + "spec/features/admin/budget_investments_spec.rb": 18.484699964523315, + "spec/models/officing/residence_spec.rb": 0.3402073383331299, + "spec/controllers/concerns/has_orders_spec.rb": 0.1844041347503662, + "spec/features/admin/legislation/processes_spec.rb": 4.020649433135986, + "spec/features/management/users_spec.rb": 2.288966178894043, + "spec/lib/tasks/communities_spec.rb": 0.15353775024414062, + "spec/models/abilities/organization_spec.rb": 0.24793481826782227, + "spec/features/polls/polls_spec.rb": 2.591568946838379, + "spec/features/communities_spec.rb": 1.6137127876281738, + "spec/models/legislation/process/phase_spec.rb": 0.07121586799621582, + "spec/features/officing_spec.rb": 0.979363203048706, + "spec/features/site_customization/custom_pages_spec.rb": 0.5588700771331787, + "spec/features/comments/legislation_questions_spec.rb": 14.133169889450073, + "spec/features/organizations_spec.rb": 0.46280837059020996, + "spec/controllers/legislation/answers_controller_spec.rb": 0.39082813262939453, + "spec/models/image_spec.rb": 7.636544466018677, + "spec/features/management/account_spec.rb": 1.150636911392212, + "spec/models/abilities/common_spec.rb": 5.959435701370239, + "spec/features/comments/debates_spec.rb": 13.69457721710205, + "spec/models/poll/shift_spec.rb": 0.19109749794006348, + "spec/features/site_customization/content_blocks_spec.rb": 0.3058288097381592, + "spec/models/poll/recount_spec.rb": 0.1983809471130371, + "spec/features/verification/level_two_verification_spec.rb": 0.4596068859100342, + "spec/features/verification/level_three_verification_spec.rb": 1.456559658050537, + "spec/lib/tasks/settings_spec.rb": 0.04654407501220703, + "spec/features/admin/budget_investment_milestones_spec.rb": 1.3974273204803467, + "spec/features/management/localization_spec.rb": 1.1653187274932861, + "spec/features/admin/tags_spec.rb": 1.0751111507415771, + "spec/features/officing/results_spec.rb": 1.2672057151794434, + "spec/features/admin/poll/booth_assigments_spec.rb": 4.1742753982543945, + "spec/models/poll/officer_assignment_spec.rb": 0.024514198303222656, + "spec/controllers/management/sessions_controller_spec.rb": 0.07244610786437988, + "spec/features/admin/signature_sheets_spec.rb": 1.4268932342529297, + "spec/models/debate_spec.rb": 4.550540924072266, + "spec/features/comments/proposals_spec.rb": 25.726442337036133, + "spec/models/poll/partial_result_spec.rb": 0.32181620597839355, + "spec/features/admin/legislation/draft_versions_spec.rb": 3.4613990783691406, + "spec/models/budget_spec.rb": 0.14807415008544922, + "spec/models/sms_spec.rb": 0.018825769424438477, + "spec/features/admin/proposals_spec.rb": 1.837270975112915, + "spec/models/geozone_spec.rb": 0.11852264404296875, + "spec/features/admin/banners_spec.rb": 3.0584604740142822, + "spec/models/legislation/process/publication_spec.rb": 0.06270265579223633, + "spec/lib/graph_ql/query_type_creator_spec.rb": 0.009456157684326172, + "spec/features/moderation_spec.rb": 1.001516342163086, + "spec/features/campaigns_spec.rb": 0.8359789848327637, + "spec/features/admin/verifications_spec.rb": 0.6421175003051758, + "spec/features/localization_spec.rb": 0.756089448928833, + "spec/features/admin/poll/questions_spec.rb": 41.59848093986511, + "spec/features/tags/debates_spec.rb": 3.4022486209869385, + "spec/helpers/text_helper_spec.rb": 0.0006229877471923828, + "spec/features/admin/moderators_spec.rb": 1.3467354774475098, + "spec/models/flag_spec.rb": 0.5202171802520752, + "spec/mailers/devise_mailer_spec.rb": 0.2588930130004883, + "spec/features/user_invites_spec.rb": 0.18819189071655273, + "spec/features/legislation/draft_versions_spec.rb": 9.352471828460693, + "spec/features/home_spec.rb": 3.0868682861328125, + "spec/features/budgets/results_spec.rb": 2.4918482303619385, + "spec/features/budgets/votes_spec.rb": 4.285862922668457, + "spec/features/comments/budget_investments_spec.rb": 16.1397545337677, + "spec/features/admin/stats_spec.rb": 2.678718090057373, + "spec/features/polls/questions_spec.rb": 2.594414472579956, + "spec/features/admin/poll/shifts_spec.rb": 4.629284143447876, + "spec/helpers/votes_helper_spec.rb": 0.31733107566833496, + "spec/models/ahoy/data_source_spec.rb": 0.04695439338684082, + "spec/models/residence_spec.rb": 0.20260858535766602, + "spec/features/admin_spec.rb": 0.6963987350463867, + "spec/controllers/comments_controller_spec.rb": 0.2683417797088623, + "spec/lib/age_spec.rb": 0.0007379055023193359, + "spec/models/legislation/answer_spec.rb": 0.14532899856567383, + "spec/features/tags_spec.rb": 3.0131027698516846, + "spec/features/admin/valuators_spec.rb": 1.0099408626556396, + "spec/models/notification_spec.rb": 0.37938618659973145, + "spec/views/welcome/index.html.erb_spec.rb": 0.1471250057220459, + "spec/customization_engine_spec.rb": 1.5587348937988281, + "spec/models/poll/officer_spec.rb": 0.2980079650878906, + "spec/features/budgets/ballots_spec.rb": 25.24861741065979, + "spec/controllers/concerns/has_filters_spec.rb": 0.1412961483001709, + "spec/features/moderation/proposals_spec.rb": 5.947849273681641, + "spec/features/management/document_verifications_spec.rb": 0.9574480056762695, + "spec/features/legislation/questions_spec.rb": 1.605849027633667, + "spec/models/proposal_spec.rb": 5.872406482696533, + "spec/models/legislation/question_option_spec.rb": 0.0395960807800293, + "spec/features/budgets/budgets_spec.rb": 0.8722023963928223, + "spec/lib/email_digests_spec.rb": 0.440814733505249, + "spec/features/official_positions_spec.rb": 1.5717194080352783, + "spec/features/officing/residence_spec.rb": 0.9819045066833496, + "spec/features/officing/voters_spec.rb": 2.078903913497925, + "spec/features/direct_messages_spec.rb": 1.6070659160614014, + "spec/models/abilities/everyone_spec.rb": 0.059804677963256836, + "spec/lib/acts_as_paranoid_aliases_spec.rb": 0.33096909523010254, + "spec/features/debates_spec.rb": 32.84718298912048, + "spec/features/votes_spec.rb": 18.217467069625854, + "spec/models/activity_spec.rb": 1.0154414176940918, + "spec/controllers/pages_controller_spec.rb": 0.19468045234680176, + "spec/features/admin/feature_flags_spec.rb": 0.726452112197876, + "spec/models/signature_sheet_spec.rb": 0.6403882503509521, + "spec/features/admin/poll/officers_spec.rb": 1.2912020683288574, + "spec/models/lock_spec.rb": 0.08562397956848145, + "spec/helpers/proposals_helper_spec.rb": 0.17275524139404297, + "spec/features/tags/budget_investments_spec.rb": 14.154245615005493, + "spec/models/vote_spec.rb": 0.9258472919464111, + "spec/features/admin/site_customization/pages_spec.rb": 1.0365827083587646, + "spec/features/moderation/users_spec.rb": 1.3000907897949219, + "spec/features/comments/legislation_annotations_spec.rb": 19.67066717147827, + "spec/features/admin/legislation/questions_spec.rb": 4.043334007263184, + "spec/models/comment_spec.rb": 1.6633994579315186, + "spec/features/admin/site_customization/images_spec.rb": 1.2299704551696777, + "spec/models/abilities/valuator_spec.rb": 1.1985805034637451, + "spec/models/organization_spec.rb": 0.12121891975402832, + "spec/models/budget/ballot_spec.rb": 0.6403298377990723, + "spec/lib/wysiwyg_sanitizer_spec.rb": 0.0018651485443115234, + "spec/features/stats_spec.rb": 0.8169982433319092, + "spec/models/poll/answer_spec.rb": 0.13266730308532715, + "spec/features/admin/settings_spec.rb": 3.1228368282318115, + "spec/features/verification/verification_path_spec.rb": 1.1146795749664307, + "spec/controllers/management/users_controller_spec.rb": 0.004178762435913086, + "spec/models/direct_upload_spec.rb": 1.1311051845550537, + "spec/features/management/email_verifications_spec.rb": 0.3727388381958008, + "spec/models/abilities/administrator_spec.rb": 2.355985164642334, + "spec/models/budget/ballot/line_spec.rb": 0.49976515769958496, + "spec/features/verification/letter_spec.rb": 1.5464122295379639, + "spec/features/notifications_spec.rb": 19.54401397705078, + "spec/features/admin/administrators_spec.rb": 1.7901337146759033, + "spec/models/signature_spec.rb": 1.5397937297821045, + "spec/models/identity_spec.rb": 0.0023458003997802734, + "spec/models/verification/management/document_spec.rb": 0.017922163009643555, + "spec/models/legislation/process_spec.rb": 0.09648776054382324, + "spec/models/budget/group_spec.rb": 0.049637794494628906, + "spec/models/verification/management/email_spec.rb": 0.057023048400878906, + "spec/helpers/verification_helper_spec.rb": 0.0009088516235351562, + "spec/features/verification/residence_spec.rb": 2.2246382236480713, + "spec/features/tracks_spec.rb": 2.320988178253174, + "spec/lib/tag_sanitizer_spec.rb": 0.0005729198455810547, + "spec/features/admin/budgets_spec.rb": 4.4486541748046875, + "spec/models/site_customization/content_block_spec.rb": 0.010473012924194336, + "spec/features/verification/email_spec.rb": 0.5266687870025635, + "spec/models/budget/reclassified_vote_spec.rb": 0.19786882400512695, + "spec/features/management/proposals_spec.rb": 4.107697486877441, + "spec/models/poll/poll_spec.rb": 0.38217735290527344, + "spec/features/admin/geozones_spec.rb": 1.561723232269287, + "spec/lib/graphql_spec.rb": 3.063258647918701, + "spec/features/verification/verified_user_spec.rb": 0.8179008960723877 } \ No newline at end of file diff --git a/lib/census_api.rb b/lib/census_api.rb index 931781c6d..4fdbd37cb 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -84,7 +84,7 @@ class CensusApi end def stubbed_response(document_type, document_number) - if document_number == "12345678Z" && document_type == "1" + if (document_number == "12345678Z" || document_number == "12345678Y") && document_type == "1" stubbed_valid_response else stubbed_invalid_response diff --git a/spec/factories.rb b/spec/factories.rb index a28471efc..b98fc7adb 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -489,6 +489,11 @@ FactoryGirl.define do ends_at { 15.days.ago } end + trait :recounting do + starts_at { 1.month.ago } + ends_at { Date.current } + end + trait :published do published true end @@ -498,13 +503,25 @@ FactoryGirl.define do poll association :author, factory: :user sequence(:title) { |n| "Question title #{n}" } - valid_answers { Faker::Lorem.words(3).join(', ') } + + trait :with_answers do + after(:create) do |question, _evaluator| + create(:poll_question_answer, question: question, title: "Yes") + create(:poll_question_answer, question: question, title: "No") + end + end end factory :poll_question_answer, class: 'Poll::Question::Answer' do association :question, factory: :poll_question - sequence(:title) { |n| "Question title #{n}" } - sequence(:description) { |n| "Question description #{n}" } + sequence(:title) { |n| "Answer title #{n}" } + sequence(:description) { |n| "Answer description #{n}" } + end + + factory :poll_answer_video, class: 'Poll::Question::Answer::Video' do + association :answer, factory: :poll_question_answer + title "Sample video title" + url "https://youtu.be/nhuNb0XtRhQ" end factory :poll_booth, class: 'Poll::Booth' do @@ -531,6 +548,14 @@ FactoryGirl.define do association :booth, factory: :poll_booth association :officer, factory: :poll_officer date Date.current + + trait :vote_collection_task do + task 0 + end + + trait :recount_scrutiny_task do + task 1 + end end factory :poll_voter, class: 'Poll::Voter' do @@ -555,31 +580,16 @@ FactoryGirl.define do end factory :poll_answer, class: 'Poll::Answer' do - association :question, factory: :poll_question + association :question, factory: [:poll_question, :with_answers] association :author, factory: [:user, :level_two] - answer { question.valid_answers.sample } + answer { question.question_answers.sample.title } end factory :poll_partial_result, class: 'Poll::PartialResult' do - association :question, factory: :poll_question - association :author, factory: :user - origin { 'web' } - answer { question.valid_answers.sample } - end - - factory :poll_white_result, class: 'Poll::WhiteResult' do - association :author, factory: :user - origin { 'web' } - end - - factory :poll_null_result, class: 'Poll::NullResult' do - association :author, factory: :user - origin { 'web' } - end - - factory :poll_total_result, class: 'Poll::TotalResult' do + association :question, factory: [:poll_question, :with_answers] association :author, factory: :user origin { 'web' } + answer { question.question_answers.sample.title } end factory :poll_recount, class: 'Poll::Recount' do diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 77881efaa..cceec1a3e 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -7,66 +7,109 @@ feature 'Admin booths assignments' do login_as(admin.user) end - scenario 'Assign booth to poll', :js do - poll = create(:poll) - booth = create(:poll_booth) + feature 'Admin Booth Assignment management' do - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (0)' + let!(:poll) { create(:poll) } + let!(:booth) { create(:poll_booth) } + + scenario 'List Polls and Booths to manage', :js do + second_poll = create(:poll) + second_booth = create(:poll_booth) + + visit booth_assignments_admin_polls_path + + expect(page).to have_content(poll.name) + expect(page).to have_content(second_poll.name) + + within("#poll_#{second_poll.id}") do + click_link 'Manage assignments' + end + + expect(page).to have_content "Assignments for poll '#{second_poll.name}'" + + expect(page).to have_content(booth.name) + expect(page).to have_content(second_booth.name) end - expect(page).to have_content 'There are no booths assigned to this poll.' + scenario 'Assign booth to poll', :js do + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (0)' + end - fill_in 'search-booths', with: booth.name - click_button 'Search' - expect(page).to have_content(booth.name) + expect(page).to have_content 'There are no booths assigned to this poll.' + expect(page).to_not have_content booth.name - within('#search-booths-results') do - click_link 'Assign booth' + fill_in 'search-booths', with: booth.name + click_button 'Search' + expect(page).to have_content(booth.name) + + visit manage_admin_poll_booth_assignments_path(poll) + + expect(page).to have_content "Assignments for poll '#{poll.name}'" + + within("#poll_booth_#{booth.id}") do + expect(page).to have_content(booth.name) + expect(page).to have_content "Unassigned" + + click_link 'Assign booth' + + expect(page).not_to have_content "Unassigned" + expect(page).to have_content "Assigned" + expect(page).to have_link "Unassign booth" + end + + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (1)' + end + + expect(page).to_not have_content 'There are no booths assigned to this poll.' + expect(page).to have_content booth.name end - expect(page).to have_content 'Booth assigned' + scenario 'Unassign booth from poll', :js do + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (1)' + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (1)' + end + + expect(page).not_to have_content 'There are no booths assigned to this poll.' + expect(page).to have_content booth.name + + fill_in 'search-booths', with: booth.name + click_button 'Search' + expect(page).to have_content(booth.name) + + visit manage_admin_poll_booth_assignments_path(poll) + + expect(page).to have_content "Assignments for poll '#{poll.name}'" + + within("#poll_booth_#{booth.id}") do + expect(page).to have_content(booth.name) + expect(page).to have_content "Assigned" + + click_link 'Unassign booth' + + expect(page).to have_content "Unassigned" + expect(page).not_to have_content "Assigned" + expect(page).to have_link "Assign booth" + end + + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (0)' + end + + expect(page).to have_content 'There are no booths assigned to this poll.' + expect(page).not_to have_content booth.name end - - expect(page).to_not have_content 'There are no booths assigned to this poll.' - expect(page).to have_content booth.name - end - - scenario 'Remove booth from poll', :js do - poll = create(:poll) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (1)' - end - - expect(page).to_not have_content 'There are no booths assigned to this poll.' - expect(page).to have_content booth.name - - within("#poll_booth_assignment_#{assignment.id}") do - click_link 'Remove booth from poll' - end - - expect(page).to have_content 'Booth not assigned anymore' - - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (0)' - end - - expect(page).to have_content 'There are no booths assigned to this poll.' - expect(page).to_not have_content booth.name end feature 'Show' do - scenario 'Lists all assigned poll oficers' do + scenario 'Lists all assigned poll officers' do poll = create(:poll) booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) @@ -126,5 +169,104 @@ feature 'Admin booths assignments' do end end + scenario 'Results for a booth assignment' do + poll = create(:poll) + booth_assignment = create(:poll_booth_assignment, poll: poll) + other_booth_assignment = create(:poll_booth_assignment, poll: poll) + + question_1 = create(:poll_question, poll: poll) + create(:poll_question_answer, title: 'Yes', question: question_1) + create(:poll_question_answer, title: 'No', question: question_1) + + 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_partial_result, + booth_assignment: booth_assignment, + question: question_1, + answer: 'Yes', + amount: 11) + + create(:poll_partial_result, + booth_assignment: booth_assignment, + question: question_1, + answer: 'No', + amount: 4) + + create(:poll_partial_result, + booth_assignment: booth_assignment, + question: question_2, + answer: 'Today', + amount: 5) + + create(:poll_partial_result, + booth_assignment: booth_assignment, + question: question_2, + answer: 'Tomorrow', + amount: 6) + + create(:poll_partial_result, + booth_assignment: other_booth_assignment, + question: question_1, + answer: 'Yes', + amount: 9999) + + create(:poll_recount, + booth_assignment: booth_assignment, + white_amount: 21, + null_amount: 44, + total_amount: 66) + + create(:poll_recount, + booth_assignment: other_booth_assignment, + white_amount: 999, + null_amount: 999, + total_amount: 999) + + visit admin_poll_booth_assignment_path(poll, booth_assignment) + + click_link 'Results' + + expect(page).to have_content(question_1.title) + + within("#question_#{question_1.id}_0_result") do + expect(page).to have_content("Yes") + expect(page).to have_content(11) + end + + within("#question_#{question_1.id}_1_result") do + expect(page).to have_content("No") + expect(page).to have_content(4) + end + + expect(page).to have_content(question_2.title) + + within("#question_#{question_2.id}_0_result") do + expect(page).to have_content("Today") + expect(page).to have_content(5) + end + + within("#question_#{question_2.id}_1_result") do + expect(page).to have_content("Tomorrow") + expect(page).to have_content(6) + end + + within('#white_results') { expect(page).to have_content('21') } + within('#null_results') { expect(page).to have_content('44') } + within('#total_results') { expect(page).to have_content('66') } + end + + scenario "No results" do + poll = create(:poll) + booth_assignment = create(:poll_booth_assignment, poll: poll) + + visit admin_poll_booth_assignment_path(poll, booth_assignment) + + click_link "Results" + + expect(page).to have_content "There are no results" + end + end end diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index 22b77b397..1aa487b26 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -60,6 +60,7 @@ feature 'Admin booths' do expect(page).to have_content booth_for_current_poll.name expect(page).to have_content booth_for_incoming_poll.name expect(page).to_not have_content booth_for_expired_poll.name + expect(page).to_not have_link "Edit booth" end scenario 'Show' do @@ -91,10 +92,11 @@ feature 'Admin booths' do booth = create(:poll_booth) assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - visit available_admin_booths_path + visit admin_booths_path within("#booth_#{booth.id}") do - click_link "Edit" + expect(page).to_not have_link "Manage shifts" + click_link "Edit booth" end fill_in "poll_booth_name", with: "Next booth" @@ -111,4 +113,18 @@ feature 'Admin booths' do end end + scenario "Back link go back to available list when manage shifts" do + poll = create(:poll, :current) + booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + + visit available_admin_booths_path + + within("#booth_#{booth.id}") do + click_link "Manage shifts" + end + + click_link "Go back" + expect(current_path).to eq(available_admin_booths_path) + end end diff --git a/spec/features/admin/poll/officer_assignments_spec.rb b/spec/features/admin/poll/officer_assignments_spec.rb new file mode 100644 index 000000000..48d10ad39 --- /dev/null +++ b/spec/features/admin/poll/officer_assignments_spec.rb @@ -0,0 +1,67 @@ +require 'rails_helper' + +feature 'Officer Assignments' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + scenario "Index" do + poll = create(:poll) + booth = create(:poll_booth) + + officer1 = create(:poll_officer) + officer2 = create(:poll_officer) + officer3 = create(:poll_officer) + + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer1) + + booth_assignment_2 = create(:poll_booth_assignment, poll: poll) + officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment_2, officer: officer2) + + visit admin_poll_path(poll) + + click_link 'Officers (2)' + + within('#officer_assignments') do + expect(page).to have_content officer1.name + expect(page).to have_content officer2.name + expect(page).to_not have_content officer3.name + end + end + + scenario "Search", :js do + poll = create(:poll) + booth = create(:poll_booth) + + user1 = create(:user, username: "John Snow") + user2 = create(:user, username: "John Silver") + user3 = create(:user, username: "John Edwards") + + officer1 = create(:poll_officer, user: user1) + officer2 = create(:poll_officer, user: user2) + officer3 = create(:poll_officer, user: user3) + + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer1) + + booth_assignment_2 = create(:poll_booth_assignment, poll: poll) + officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment_2, officer: officer2) + + visit admin_poll_path(poll) + + click_link 'Officers (2)' + + fill_in "search-officers", with: "John" + click_button "Search" + + within('#search-officers-results') do + expect(page).to have_content officer1.name + expect(page).to have_content officer2.name + expect(page).to_not have_content officer3.name + end + end + +end \ No newline at end of file diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index d69e7ad75..210b2ff6a 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -60,6 +60,10 @@ feature 'Admin polls' do fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..." fill_in 'poll_description', with: "Upcomming poll's description. This poll..." + + expect(page).to_not have_css("#poll_results_enabled") + expect(page).to_not have_css("#poll_stats_enabled") + click_button "Create poll" expect(page).to have_content "Poll created successfully" @@ -73,20 +77,31 @@ feature 'Admin polls' do create(:image, imageable: poll) visit admin_poll_path(poll) - click_link "Edit" + click_link "Edit poll" end_date = 1.year.from_now expect(page).to have_css("img[alt='#{poll.image.title}']") + expect(page).to have_css("#poll_results_enabled") + expect(page).to have_css("#poll_stats_enabled") + fill_in "poll_name", with: "Next Poll" fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") + check 'poll_results_enabled' + check 'poll_stats_enabled' click_button "Update poll" expect(page).to have_content "Poll updated successfully" expect(page).to have_content "Next Poll" expect(page).to have_content I18n.l(end_date.to_date) + + click_link "Edit poll" + + expect(page).to have_field('poll_results_enabled', checked: true) + expect(page).to have_field('poll_stats_enabled', checked: true) + end scenario 'Edit from index' do @@ -261,8 +276,13 @@ feature 'Admin polls' do booth_assignment_2 = create(:poll_booth_assignment, poll: poll) booth_assignment_3 = create(:poll_booth_assignment, poll: poll) - question_1 = create(:poll_question, poll: poll, valid_answers: "Yes,No") - question_2 = create(:poll_question, poll: poll, valid_answers: "Today,Tomorrow") + question_1 = create(:poll_question, poll: poll) + create(:poll_question_answer, title: 'Yes', question: question_1) + create(:poll_question_answer, title: 'No', question: question_1) + + 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) [booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba| create(:poll_partial_result, @@ -279,30 +299,69 @@ feature 'Admin polls' do create(:poll_recount, booth_assignment: booth_assignment_1, white_amount: 21, - null_amount: 44) + null_amount: 44, + total_amount: 66) visit admin_poll_path(poll) click_link "Results" expect(page).to have_content(question_1.title) - question_1.valid_answers.each_with_index do |answer, i| + question_1.question_answers.each_with_index do |answer, i| within("#question_#{question_1.id}_#{i}_result") do - expect(page).to have_content(answer) + expect(page).to have_content(answer.title) expect(page).to have_content([33, 0][i]) end end expect(page).to have_content(question_2.title) - question_2.valid_answers.each_with_index do |answer, i| + question_2.question_answers.each_with_index do |answer, i| within("#question_#{question_2.id}_#{i}_result") do - expect(page).to have_content(answer) + expect(page).to have_content(answer.title) expect(page).to have_content([0, 15][i]) end end within('#white_results') { expect(page).to have_content('21') } within('#null_results') { expect(page).to have_content('44') } + within('#total_results') { expect(page).to have_content('66') } + end + + scenario "Link to results by booth" do + poll = create(:poll) + booth_assignment1 = create(:poll_booth_assignment, poll: poll) + booth_assignment2 = create(:poll_booth_assignment, poll: poll) + + question = create(:poll_question, poll: poll) + create(:poll_question_answer, title: 'Yes', question: question) + create(:poll_question_answer, title: 'No', question: question) + + create(:poll_partial_result, + booth_assignment: booth_assignment1, + question: question, + answer: 'Yes', + amount: 5) + + create(:poll_partial_result, + booth_assignment: booth_assignment2, + question: question, + answer: 'Yes', + amount: 6) + + visit admin_poll_path(poll) + + click_link "Results" + + expect(page).to have_link("See results", count: 2) + + within("#booth_assignment_#{booth_assignment1.id}_result") do + click_link "See results" + end + + expect(page).to have_content booth_assignment1.booth.name + expect(page).to have_content "Results" + expect(page).to have_content "Yes" + expect(page).to have_content "5" end end end diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb index 66918c4d8..e8af5ff79 100644 --- a/spec/features/admin/poll/questions/answers/answers_spec.rb +++ b/spec/features/admin/poll/questions/answers/answers_spec.rb @@ -4,7 +4,7 @@ feature 'Answers' do background do admin = create(:administrator) - login_as (admin.user) + login_as admin.user end scenario 'Create' do @@ -24,13 +24,31 @@ feature 'Answers' do expect(page).to have_content(description) end + scenario 'Create second answer and place after the first one' do + question = create(:poll_question) + answer = create(:poll_question_answer, title: 'First', question: question, given_order: 1) + title = 'Second' + description = "Description" + + visit admin_question_path(question) + click_link 'Add answer' + + fill_in 'poll_question_answer_title', with: title + fill_in 'poll_question_answer_description', with: description + + click_button 'Save' + + expect(page.body.index('First')).to be < page.body.index('Second') + end + scenario 'Update' do question = create(:poll_question) - answer = create(:poll_question_answer, question: question, title: "Answer title") + answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 2) + answer2 = create(:poll_question_answer, question: question, title: "Another title", given_order: 1) visit admin_answer_path(answer) - click_link 'Edit' + click_link 'Edit answer' old_title = answer.title new_title = 'Ex Machina' @@ -46,6 +64,8 @@ feature 'Answers' do expect(page).to have_content(new_title) expect(page).to_not have_content(old_title) + + expect(page.body.index(new_title)).to be < page.body.index(answer2.title) end end diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 2ac290216..bddd1b6b1 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -35,9 +35,10 @@ feature 'Admin shifts' do create(:poll, :incoming) poll = create(:poll, :current) booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_booth_assignment, poll: create(:poll, :expired), booth: booth) officer = create(:poll_officer) - vote_collection_dates = (poll.starts_at.to_date..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } + vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } visit available_admin_booths_path @@ -52,14 +53,14 @@ feature 'Admin shifts' do expect(page).to have_select('shift_date_vote_collection_date', options: ["Select day", *vote_collection_dates]) expect(page).not_to have_select('shift_date_recount_scrutiny_date') - select I18n.l(poll.starts_at.to_date, format: :long), from: 'shift_date_vote_collection_date' + select I18n.l(Date.current, format: :long), from: 'shift_date_vote_collection_date' click_button "Add shift" expect(page).to have_content "Shift added" within("#shifts") do expect(page).to have_css(".shift", count: 1) - expect(page).to have_content(I18n.l(poll.starts_at.to_date, format: :long)) + expect(page).to have_content(I18n.l(Date.current, format: :long)) expect(page).to have_content("Collect Votes") expect(page).to have_content(officer.name) end @@ -91,6 +92,37 @@ feature 'Admin shifts' do end end + scenario "Vote Collection Shift and Recount & Scrutiny Shift don't include already assigned dates to officer", :js do + poll = create(:poll, :current) + booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + officer = create(:poll_officer) + + shift1 = create(:poll_shift, :vote_collection_task, officer: officer, booth: booth, date: Time.zone.today) + shift2 = create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth, date: Time.zone.tomorrow) + + vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a + .reject { |date| date == Time.zone.today } + .map { |date| I18n.l(date, format: :long) } + recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a + .reject { |date| date == Time.zone.tomorrow } + .map { |date| I18n.l(date, format: :long) } + + visit available_admin_booths_path + + within("#booth_#{booth.id}") do + click_link "Manage shifts" + end + + fill_in "search", with: officer.email + click_button "Search" + click_link "Edit shifts" + + expect(page).to have_select('shift_date_vote_collection_date', options: ["Select day", *vote_collection_dates]) + select "Recount & Scrutiny", from: 'shift_task' + expect(page).to have_select('shift_date_recount_scrutiny_date', options: ["Select day", *recount_scrutiny_dates]) + end + scenario "Error on create", :js do poll = create(:poll, :current) booth = create(:poll_booth) diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index 73d190cb9..40baf6423 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -87,7 +87,6 @@ feature 'Admin settings' do expect(page).to have_content "Map configuration updated succesfully" end - end end diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index dd9c38c6b..8ff205852 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -23,7 +23,7 @@ feature 'Admin tags' do within("form.new_tag") do fill_in "tag_name", with: 'important issues' - click_button 'Create Topic' + click_button 'Create topic' end visit admin_tags_path @@ -39,8 +39,8 @@ feature 'Admin tags' do expect(page).to have_content @tag1.name expect(page).to have_content tag2.name - within("#edit_tag_#{tag2.id}") do - click_link 'Destroy Topic' + within("#tag_#{tag2.id}") do + click_link 'Destroy topic' end visit admin_tags_path @@ -58,8 +58,8 @@ feature 'Admin tags' do expect(page).to have_content @tag1.name expect(page).to have_content tag2.name - within("#edit_tag_#{tag2.id}") do - click_link 'Destroy Topic' + within("#tag_#{tag2.id}") do + click_link 'Destroy topic' end visit admin_tags_path @@ -81,7 +81,7 @@ feature 'Admin tags' do within("form.new_tag") do fill_in "tag_name", with: "wow_category" - click_button 'Create Topic' + click_button 'Create topic' end expect(ActsAsTaggableOn::Tag.category.where(name: "wow_category")).to exist diff --git a/spec/features/comments/polls_spec.rb b/spec/features/comments/polls_spec.rb new file mode 100644 index 000000000..0fe01cf06 --- /dev/null +++ b/spec/features/comments/polls_spec.rb @@ -0,0 +1,522 @@ +require 'rails_helper' +include ActionView::Helpers::DateHelper + +feature 'Commenting polls' do + let(:user) { create :user } + let(:poll) { create :poll } + + scenario 'Index' do + 3.times { create(:comment, commentable: poll) } + + visit poll_path(poll) + + expect(page).to have_css('.comment', count: 3) + + comment = Comment.last + within first('.comment') do + expect(page).to have_content comment.user.name + expect(page).to have_content I18n.l(comment.created_at, format: :datetime) + expect(page).to have_content comment.body + end + end + + scenario 'Show' do + skip "Feature not implemented yet, review soon" + + parent_comment = create(:comment, commentable: poll) + first_child = create(:comment, commentable: poll, parent: parent_comment) + second_child = create(:comment, commentable: poll, parent: parent_comment) + + visit comment_path(parent_comment) + + expect(page).to have_css(".comment", count: 3) + expect(page).to have_content parent_comment.body + expect(page).to have_content first_child.body + expect(page).to have_content second_child.body + expect(page).to have_link "Go back to #{poll.name}", href: poll_path(poll) + + expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) + expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) + expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) + end + + scenario 'Collapsable comments', :js do + parent_comment = create(:comment, body: "Main comment", commentable: poll) + child_comment = create(:comment, body: "First subcomment", commentable: poll, parent: parent_comment) + grandchild_comment = create(:comment, body: "Last subcomment", commentable: poll, parent: child_comment) + + visit poll_path(poll) + + expect(page).to have_css('.comment', count: 3) + + find("#comment_#{child_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 2) + expect(page).to_not have_content grandchild_comment.body + + find("#comment_#{child_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 3) + expect(page).to have_content grandchild_comment.body + + find("#comment_#{parent_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 1) + expect(page).to_not have_content child_comment.body + expect(page).to_not have_content grandchild_comment.body + end + + scenario 'Comment order' do + c1 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) + + visit poll_path(poll, order: :most_voted) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + + visit poll_path(poll, order: :newest) + + expect(c3.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c1.body) + + visit poll_path(poll, order: :oldest) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + end + + scenario 'Creation date works differently in roots and in child comments, when sorting by confidence_score' do + old_root = create(:comment, commentable: poll, created_at: Time.current - 10) + new_root = create(:comment, commentable: poll, created_at: Time.current) + old_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current - 10) + new_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current) + + visit poll_path(poll, order: :most_voted) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + + visit poll_path(poll, order: :newest) + + expect(new_root.body).to appear_before(old_root.body) + expect(new_child.body).to appear_before(old_child.body) + + visit poll_path(poll, order: :oldest) + + expect(old_root.body).to appear_before(new_root.body) + expect(old_child.body).to appear_before(new_child.body) + end + + scenario 'Turns links into html links' do + create :comment, commentable: poll, body: 'Built with http://rubyonrails.org/' + + visit poll_path(poll) + + within first('.comment') do + expect(page).to have_content 'Built with http://rubyonrails.org/' + expect(page).to have_link('http://rubyonrails.org/', href: 'http://rubyonrails.org/') + expect(find_link('http://rubyonrails.org/')[:rel]).to eq('nofollow') + expect(find_link('http://rubyonrails.org/')[:target]).to eq('_blank') + end + end + + scenario 'Sanitizes comment body for security' do + create :comment, commentable: poll, + body: " click me http://www.url.com" + + visit poll_path(poll) + + within first('.comment') do + expect(page).to have_content "click me http://www.url.com" + expect(page).to have_link('http://www.url.com', href: 'http://www.url.com') + expect(page).not_to have_link('click me') + end + end + + scenario 'Paginated comments' do + per_page = 10 + (per_page + 2).times { create(:comment, commentable: poll)} + + visit poll_path(poll) + + expect(page).to have_css('.comment', count: per_page) + within("ul.pagination") do + expect(page).to have_content("1") + expect(page).to have_content("2") + expect(page).to_not have_content("3") + click_link "Next", exact: false + end + + expect(page).to have_css('.comment', count: 2) + end + + feature 'Not logged user' do + scenario 'can not see comments forms' do + create(:comment, commentable: poll) + visit poll_path(poll) + + expect(page).to have_content 'You must Sign in or Sign up to leave a comment' + within('#comments') do + expect(page).to_not have_content 'Write a comment' + expect(page).to_not have_content 'Reply' + end + end + end + + scenario 'Create', :js do + login_as(user) + visit poll_path(poll) + + fill_in "comment-body-poll_#{poll.id}", with: 'Have you thought about...?' + click_button 'Publish comment' + + within "#comments" do + expect(page).to have_content 'Have you thought about...?' + end + + within "#tab-comments-label" do + expect(page).to have_content 'Comments (1)' + end + end + + scenario 'Errors on create', :js do + login_as(user) + visit poll_path(poll) + + click_button 'Publish comment' + + expect(page).to have_content "Can't be blank" + end + + scenario 'Reply', :js do + citizen = create(:user, username: 'Ana') + manuela = create(:user, username: 'Manuela') + comment = create(:comment, commentable: poll, user: citizen) + + login_as(manuela) + visit poll_path(poll) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content 'It will be done next week.' + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario 'Errors on reply', :js do + comment = create(:comment, commentable: poll, user: user) + + login_as(user) + visit poll_path(poll) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + click_button 'Publish reply' + expect(page).to have_content "Can't be blank" + end + + end + + scenario "N replies", :js do + parent = create(:comment, commentable: poll) + + 7.times do + create(:comment, commentable: poll, parent: parent) + parent = parent.children.first + end + + visit poll_path(poll) + expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") + end + + scenario "Flagging as inappropriate", :js do + skip "Feature not implemented yet, review soon" + + comment = create(:comment, commentable: poll) + + login_as(user) + visit poll_path(poll) + + within "#comment_#{comment.id}" do + page.find("#flag-expand-comment-#{comment.id}").click + page.find("#flag-comment-#{comment.id}").click + + expect(page).to have_css("#unflag-expand-comment-#{comment.id}") + end + + expect(Flag.flagged?(user, comment)).to be + end + + scenario "Undoing flagging as inappropriate", :js do + skip "Feature not implemented yet, review soon" + + comment = create(:comment, commentable: poll) + Flag.flag(user, comment) + + login_as(user) + visit poll_path(poll) + + within "#comment_#{comment.id}" do + page.find("#unflag-expand-comment-#{comment.id}").click + page.find("#unflag-comment-#{comment.id}").click + + expect(page).to have_css("#flag-expand-comment-#{comment.id}") + end + + expect(Flag.flagged?(user, comment)).to_not be + end + + scenario "Flagging turbolinks sanity check", :js do + skip "Feature not implemented yet, review soon" + + poll = create(:poll, title: "Should we change the world?") + comment = create(:comment, commentable: poll) + + login_as(user) + visit polls_path + click_link "Should we change the world?" + + within "#comment_#{comment.id}" do + page.find("#flag-expand-comment-#{comment.id}").click + expect(page).to have_selector("#flag-comment-#{comment.id}") + end + end + + scenario "Erasing a comment's author" do + poll = create(:poll) + comment = create(:comment, commentable: poll, body: "this should be visible") + comment.user.erase + + visit poll_path(poll) + within "#comment_#{comment.id}" do + expect(page).to have_content('User deleted') + expect(page).to have_content('this should be visible') + end + end + + feature "Moderators" do + + scenario "can create comment as a moderator", :js do + skip "Feature not implemented yet, review soon" + + moderator = create(:moderator) + + login_as(moderator.user) + visit poll_path(poll) + + fill_in "comment-body-poll_#{poll.id}", with: "I am moderating!" + check "comment-as-moderator-poll_#{poll.id}" + click_button "Publish comment" + + within "#comments" do + expect(page).to have_content "I am moderating!" + expect(page).to have_content "Moderator ##{moderator.id}" + expect(page).to have_css "div.is-moderator" + expect(page).to have_css "img.moderator-avatar" + end + end + + scenario "can create reply as a moderator", :js do + skip "Feature not implemented yet, review soon" + + citizen = create(:user, username: "Ana") + manuela = create(:user, username: "Manuela") + moderator = create(:moderator, user: manuela) + comment = create(:comment, commentable: poll, user: citizen) + + login_as(manuela) + visit poll_path(poll) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + check "comment-as-moderator-comment_#{comment.id}" + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content "I am moderating!" + expect(page).to have_content "Moderator ##{moderator.id}" + expect(page).to have_css "div.is-moderator" + expect(page).to have_css "img.moderator-avatar" + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario "can not comment as an administrator" do + skip "Feature not implemented yet, review soon" + + moderator = create(:moderator) + + login_as(moderator.user) + visit poll_path(poll) + + expect(page).to_not have_content "Comment as administrator" + end + end + + feature "Administrators" do + scenario "can create comment as an administrator", :js do + skip "Feature not implemented yet, review soon" + + admin = create(:administrator) + + login_as(admin.user) + visit poll_path(poll) + + fill_in "comment-body-poll_#{poll.id}", with: "I am your Admin!" + check "comment-as-administrator-poll_#{poll.id}" + click_button "Publish comment" + + within "#comments" do + expect(page).to have_content "I am your Admin!" + expect(page).to have_content "Administrator ##{admin.id}" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + end + + scenario "can create reply as an administrator", :js do + skip "Feature not implemented yet, review soon" + + citizen = create(:user, username: "Ana") + manuela = create(:user, username: "Manuela") + admin = create(:administrator, user: manuela) + comment = create(:comment, commentable: poll, user: citizen) + + login_as(manuela) + visit poll_path(poll) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + check "comment-as-administrator-comment_#{comment.id}" + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content "Top of the world!" + expect(page).to have_content "Administrator ##{admin.id}" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario "can not comment as a moderator" do + skip "Feature not implemented yet, review soon" + + admin = create(:administrator) + + login_as(admin.user) + visit poll_path(poll) + + expect(page).to_not have_content "Comment as moderator" + end + end + + feature 'Voting comments' do + + background do + @manuela = create(:user, verified_at: Time.current) + @pablo = create(:user) + @poll = create(:poll) + @comment = create(:comment, commentable: @poll) + + login_as(@manuela) + end + + scenario 'Show' do + create(:vote, voter: @manuela, votable: @comment, vote_flag: true) + create(:vote, voter: @pablo, votable: @comment, vote_flag: false) + + visit poll_path(@poll) + + within("#comment_#{@comment.id}_votes") do + within(".in_favor") do + expect(page).to have_content "1" + end + + within(".against") do + expect(page).to have_content "1" + end + + expect(page).to have_content "2 votes" + end + end + + scenario 'Create', :js do + visit poll_path(@poll) + + within("#comment_#{@comment.id}_votes") do + find(".in_favor a").click + + within(".in_favor") do + expect(page).to have_content "1" + end + + within(".against") do + expect(page).to have_content "0" + end + + expect(page).to have_content "1 vote" + end + end + + scenario 'Update', :js do + visit poll_path(@poll) + + within("#comment_#{@comment.id}_votes") do + find('.in_favor a').click + find('.against a').click + + within('.in_favor') do + expect(page).to have_content "0" + end + + within('.against') do + expect(page).to have_content "1" + end + + expect(page).to have_content "1 vote" + end + end + + scenario 'Trying to vote multiple times', :js do + visit poll_path(@poll) + + within("#comment_#{@comment.id}_votes") do + find('.in_favor a').click + find('.in_favor a').click + + within('.in_favor') do + expect(page).to have_content "1" + end + + within('.against') do + expect(page).to have_content "0" + end + + expect(page).to have_content "1 vote" + end + end + end + +end diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 3d7c6acf8..39cd84760 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -394,7 +394,7 @@ feature 'Debates' do end scenario 'Debates are ordered by recommendations when there is a user logged', :js do - proposal = create(:proposal, tag_list: "Sport" ) + proposal = create(:proposal, tag_list: "Sport") user = create(:user) create(:follow, followable: proposal, user: user) login_as(user) @@ -830,7 +830,7 @@ feature 'Debates' do debate2 = create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport") debate3 = create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport") debate4 = create(:debate, title: "Do not display", cached_votes_total: 1) - proposal1 = create(:proposal, tag_list: "Sport") + proposal1 = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal1, user: user) visit debates_path diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 21fdf8a64..74b608ed6 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -371,6 +371,54 @@ feature 'Emails' do end + context "Polls" do + + scenario "Do not send email on poll comment", :js do + user1 = create(:user, email_on_comment: true) + user2 = create(:user) + + poll = create(:poll, author: user1) + reset_mailer + + login_as(user2) + visit poll_path(poll) + + fill_in "comment-body-poll_#{poll.id}", with: 'Have you thought about...?' + click_button 'Publish comment' + + expect(page).to have_content 'Have you thought about...?' + + expect { open_last_email }.to raise_error "No email has been sent!" + end + + scenario "Send email on poll comment reply", :js do + user1 = create(:user, email_on_comment_reply: true) + user2 = create(:user) + + poll = create(:poll) + comment = create(:comment, commentable: poll, author: user1) + + login_as(user2) + visit poll_path(poll) + + click_link "Reply" + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' + click_button 'Publish reply' + end + expect(page).to have_content 'It will be done next week.' + + email = open_last_email + expect(email).to have_subject('Someone has responded to your comment') + expect(email).to deliver_to(user1) + expect(email).to_not have_body_text(poll_path(poll)) + expect(email).to have_body_text(comment_path(Comment.last)) + expect(email).to have_body_text(I18n.t("mailers.config.manage_email_subscriptions")) + expect(email).to have_body_text(account_path) + end + + end + context "Users without email" do scenario "should not receive emails", :js do user = create(:user, :verified, email_on_comment: true) diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index cb5349814..4854fff4d 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -27,7 +27,7 @@ feature "Home" do background do Setting['feature.user.recommendations'] = true user = create(:user) - proposal = create(:proposal, tag_list: "Sport" ) + proposal = create(:proposal, tag_list: "Sport") create(:follow, followable: proposal, user: user) login_as(user) end diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 9925b0d56..75ed91857 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -14,6 +14,12 @@ feature "Notifications" do let(:legislation_question) { create(:legislation_question, process: process, author: administrator) } let(:legislation_annotation) { create(:legislation_annotation, author: author) } + let(:topic) { + proposal = create(:proposal) + community = proposal.community + create(:topic, community: community, author: author) + } + scenario "User commented on my debate", :js do create(:notification, notifiable: debate, user: author) login_as author @@ -40,6 +46,19 @@ feature "Notifications" do expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']" end + scenario "User commented on my topic", :js do + create(:notification, notifiable: topic, user: author) + login_as author + visit root_path + + find(".icon-notification").click + + expect(page).to have_css ".notification", count: 1 + + expect(page).to have_content "Someone commented on" + expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']" + end + scenario "Multiple comments on my proposal", :js do login_as user visit proposal_path proposal diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb index f7e1ad8ef..252d4edd6 100644 --- a/spec/features/officing/results_spec.rb +++ b/spec/features/officing/results_spec.rb @@ -7,8 +7,13 @@ feature 'Officing Results' do @officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer) @poll = @officer_assignment.booth_assignment.poll @poll.update(ends_at: 1.day.ago) - @question_1 = create(:poll_question, poll: @poll, valid_answers: "Yes,No") - @question_2 = create(:poll_question, poll: @poll, valid_answers: "Today,Tomorrow") + @question_1 = create(:poll_question, poll: @poll) + create(:poll_question_answer, title: 'Yes', question: @question_1) + create(:poll_question_answer, title: 'No', question: @question_1) + @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) + login_as(@poll_officer.user) end @@ -53,9 +58,7 @@ feature 'Officing Results' do expect(page).to_not have_content('Your results') booth_name = @officer_assignment.booth_assignment.booth.name - date = I18n.l(@poll.starts_at.to_date, format: :long) select booth_name, from: 'officer_assignment_id' - select date, from: 'date' fill_in "questions[#{@question_1.id}][0]", with: '100' fill_in "questions[#{@question_1.id}][1]", with: '200' @@ -71,8 +74,8 @@ feature 'Officing Results' do expect(page).to have_content('Your results') - within("#results_#{@officer_assignment.booth_assignment_id}_#{@poll.starts_at.to_date.strftime('%Y%m%d')}") do - expect(page).to have_content(date) + within("#results_#{@officer_assignment.booth_assignment_id}_#{Date.current.strftime('%Y%m%d')}") do + expect(page).to have_content(I18n.l(Date.current, format: :long)) expect(page).to have_content(booth_name) end end @@ -81,9 +84,9 @@ feature 'Officing Results' do partial_result = create(:poll_partial_result, officer_assignment: @officer_assignment, booth_assignment: @officer_assignment.booth_assignment, - date: @poll.starts_at, + date: Date.current, question: @question_1, - answer: @question_1.valid_answers[0], + answer: @question_1.question_answers.first.title, author: @poll_officer.user, amount: 7777) @@ -94,9 +97,7 @@ feature 'Officing Results' do visit new_officing_poll_result_path(@poll) booth_name = partial_result.booth_assignment.booth.name - date = I18n.l(partial_result.date, format: :long) select booth_name, from: 'officer_assignment_id' - select date, from: 'date' fill_in "questions[#{@question_1.id}][0]", with: '5555' fill_in "questions[#{@question_1.id}][1]", with: '200' @@ -143,13 +144,13 @@ feature 'Officing Results' do expect(page).to have_content(@officer_assignment.booth_assignment.booth.name) expect(page).to have_content(@question_1.title) - @question_1.valid_answers.each_with_index do |answer, i| - within("#question_#{@question_1.id}_#{i}_result") { expect(page).to have_content(answer) } + @question_1.question_answers.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.valid_answers.each_with_index do |answer, i| - within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer) } + @question_2.question_answers.each_with_index do |answer, i| + within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer.title) } end within('#white_results') { expect(page).to have_content('21') } diff --git a/spec/features/officing_spec.rb b/spec/features/officing_spec.rb index aff3eac4e..b208b735c 100644 --- a/spec/features/officing_spec.rb +++ b/spec/features/officing_spec.rb @@ -1,4 +1,5 @@ require 'rails_helper' +require 'sessions_helper' feature 'Poll Officing' do let(:user) { create(:user) } @@ -54,7 +55,22 @@ feature 'Poll Officing' do expect(page).to have_content "You do not have permission to access this page" end - scenario 'Access as an poll officer is authorized' do + scenario 'Access as an administrator is not authorized' do + create(:administrator, user: user) + create(:poll) + login_as(user) + visit root_path + + expect(page).to_not have_link("Polling officers") + visit officing_root_path + + expect(current_path).not_to eq(officing_root_path) + expect(current_path).to eq(root_path) + expect(page).to have_content "You do not have permission to access this page" + end + + scenario 'Access as an administrator with poll officer role is authorized' do + create(:administrator, user: user) create(:poll_officer, user: user) create(:poll) login_as(user) @@ -67,8 +83,8 @@ feature 'Poll Officing' do expect(page).to_not have_content "You do not have permission to access this page" end - scenario 'Access as an administrator is authorized' do - create(:administrator, user: user) + scenario 'Access as an poll officer is authorized' do + create(:poll_officer, user: user) create(:poll) login_as(user) visit root_path @@ -106,4 +122,64 @@ feature 'Poll Officing' do expect(page).to_not have_css('#moderation_menu') end -end \ No newline at end of file + scenario 'Officing dashboard available for multiple sessions', :js do + poll = create(:poll) + booth = create(:poll_booth) + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + + user1 = create(:user) + user2 = create(:user) + officer1 = create(:poll_officer, user: user1) + officer2 = create(:poll_officer, user: user2) + + create(:poll_shift, officer: officer1, booth: booth, date: Date.current, task: :vote_collection) + create(:poll_shift, officer: officer2, booth: booth, date: Date.current, task: :vote_collection) + + officer_assignment_1 = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer1) + officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer2) + + in_browser(:one) do + login_as user1 + visit officing_root_path + end + + in_browser(:two) do + login_as user2 + visit officing_root_path + end + + in_browser(:one) do + page.should have_content("Here you can validate user documents and store voting results") + + visit new_officing_residence_path + select 'DNI', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + fill_in 'residence_year_of_birth', with: '1980' + click_button 'Validate document' + expect(page).to have_content 'Document verified with Census' + click_button "Confirm vote" + expect(page).to have_content "Vote introduced!" + expect(Poll::Voter.where(document_number: '12345678Z', poll_id: poll, origin: 'booth', officer_id: officer1).count).to be(1) + + visit final_officing_polls_path + page.should have_content("Polls ready for final recounting") + end + + in_browser(:two) do + page.should have_content("Here you can validate user documents and store voting results") + + visit new_officing_residence_path + select 'DNI', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Y" + fill_in 'residence_year_of_birth', with: '1980' + click_button 'Validate document' + expect(page).to have_content 'Document verified with Census' + click_button "Confirm vote" + expect(page).to have_content "Vote introduced!" + expect(Poll::Voter.where(document_number: '12345678Y', poll_id: poll, origin: 'booth', officer_id: officer2).count).to be(1) + + visit final_officing_polls_path + page.should have_content("Polls ready for final recounting") + end + end +end diff --git a/spec/features/polls/answers_spec.rb b/spec/features/polls/answers_spec.rb index f7dfd4d38..8bb87c94e 100644 --- a/spec/features/polls/answers_spec.rb +++ b/spec/features/polls/answers_spec.rb @@ -2,19 +2,21 @@ require 'rails_helper' feature 'Answers' do + let(:question) { create(:poll_question) } + let(:admin) { create(:administrator) } + background do - admin = create(:administrator) login_as(admin.user) end scenario "Index" do - question = create(:poll_question) - answer1 = create(:poll_question_answer, question: question) - answer2 = create(:poll_question_answer, question: question) + answer1 = create(:poll_question_answer, question: question, given_order: 2) + answer2 = create(:poll_question_answer, question: question, given_order: 1) visit admin_question_path(question) expect(page).to have_css(".poll_question_answer", count: 2) + expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title) within("#poll_question_answer_#{answer1.id}") do expect(page).to have_content answer1.title @@ -23,8 +25,6 @@ feature 'Answers' do end scenario "Create" do - question = create(:poll_question) - visit admin_question_path(question) click_link "Add answer" @@ -33,12 +33,34 @@ feature 'Answers' do click_button "Save" expect(page).to have_content "Answer created successfully" - expect(page).to have_css(".poll_question_answer", count: 1) expect(page).to have_content "¿Would you like to reform Central Park?" expect(page).to have_content "Adding more trees, creating a play area..." end + scenario 'Add video to answer' do + answer1 = create(:poll_question_answer, question: question) + answer2 = create(:poll_question_answer, question: question) + + visit admin_question_path(question) + + within("#poll_question_answer_#{answer1.id}") do + click_link "Video list" + end + + click_link "Add video" + + fill_in "poll_question_answer_video_title", with: "Awesome project video" + fill_in "poll_question_answer_video_url", with: "https://www.youtube.com/watch?v=123" + + click_button "Save" + + within("#poll_question_answer_video_#{answer1.videos.last.id}") do + expect(page).to have_content "Awesome project video" + expect(page).to have_content "https://www.youtube.com/watch?v=123" + end + end + pending "Update" pending "Destroy" @@ -54,4 +76,4 @@ feature 'Answers' do true end -end \ No newline at end of file +end diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 9fdb07255..8629a1087 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -59,12 +59,38 @@ feature 'Polls' do expect(page).to have_link('Incoming') expect(page).to_not have_link('Expired') end + + scenario "Poll title link to stats if enabled" do + poll = create(:poll, name: "Poll with stats", stats_enabled: true) + + visit polls_path + + expect(page).to have_link("Poll with stats", href: stats_poll_path(poll)) + end + + scenario "Poll title link to results if enabled" do + poll = create(:poll, name: "Poll with results", stats_enabled: true, results_enabled: true) + + visit polls_path + + expect(page).to have_link("Poll with results", href: results_poll_path(poll)) + end end context 'Show' do let(:geozone) { create(:geozone) } let(:poll) { create(:poll, summary: "Summary", description: "Description") } + scenario 'Show answers with videos' do + question = create(:poll_question, poll: poll) + answer = create(:poll_question_answer, question: question, title: 'Chewbacca') + video = create(:poll_answer_video, answer: answer, title: "Awesome project video", url: "https://www.youtube.com/watch?v=123") + + visit poll_path(poll) + + expect(page).to have_link("Awesome project video", href: "https://www.youtube.com/watch?v=123") + end + scenario 'Lists questions from proposals as well as regular ones' do normal_question = create(:poll_question, poll: poll) proposal_question = create(:poll_question, poll: poll, proposal: create(:proposal)) @@ -78,6 +104,30 @@ feature 'Polls' do expect(page).to have_content(proposal_question.title) end + scenario "Question answers appear in the given order" do + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 2) + answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 1) + + visit poll_path(poll) + + within("div#poll_question_#{question.id}") do + expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title) + end + end + + scenario "More info answers appear in the given order" do + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 2) + answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 1) + + visit poll_path(poll) + + within('div.poll-more-info-answers') do + expect(page.body.index(answer1.title)).to be < page.body.index(answer2.title) + end + end + scenario 'Non-logged in users' do question = create(:poll_question, poll: poll) answer1 = create(:poll_question_answer, question: question, title: 'Han Solo') @@ -333,4 +383,74 @@ feature 'Polls' do end end + + context "Results and stats" do + scenario "Show poll results and stats if enabled and poll expired" do + poll = create(:poll, :expired, results_enabled: true, stats_enabled: true) + user = create(:user) + + login_as user + visit poll_path(poll) + + expect(page).to have_content("Poll results") + expect(page).to have_content("Participation statistics") + + visit results_poll_path(poll) + expect(page).to have_content("Questions") + + visit stats_poll_path(poll) + expect(page).to have_content("Participation data") + end + + scenario "Don't show poll results and stats if not enabled" do + poll = create(:poll, :expired, results_enabled: false, stats_enabled: false) + user = create(:user) + + login_as user + visit poll_path(poll) + + expect(page).to_not have_content("Poll results") + expect(page).to_not have_content("Participation statistics") + + visit results_poll_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.") + + visit stats_poll_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") + end + + scenario "Don't show poll results and stats if is not expired" do + poll = create(:poll, :current, results_enabled: true, stats_enabled: true) + user = create(:user) + + login_as user + visit poll_path(poll) + + expect(page).to_not have_content("Poll results") + expect(page).to_not have_content("Participation statistics") + + visit results_poll_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.") + + visit stats_poll_path(poll) + expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") + end + + scenario "Show poll results and stats if user is administrator" do + poll = create(:poll, :current, results_enabled: false, stats_enabled: false) + user = create(:administrator).user + + login_as user + visit poll_path(poll) + + expect(page).to have_content("Poll results") + expect(page).to have_content("Participation statistics") + + visit results_poll_path(poll) + expect(page).to have_content("Questions") + + visit stats_poll_path(poll) + expect(page).to have_content("Participation data") + end + end end diff --git a/spec/features/polls/results_spec.rb b/spec/features/polls/results_spec.rb new file mode 100644 index 000000000..326344dd9 --- /dev/null +++ b/spec/features/polls/results_spec.rb @@ -0,0 +1,55 @@ +require 'rails_helper' + +feature 'Poll Results' do + scenario 'List each Poll question', :js do + user1 = create(:user, :level_two) + user2 = create(:user, :level_two) + user3 = create(:user, :level_two) + + 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') + + 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') + + login_as user1 + vote_for_poll_via_web(poll, question1, 'Yes') + vote_for_poll_via_web(poll, question2, 'Blue') + expect(Poll::Voter.count).to eq(1) + logout + + login_as user2 + vote_for_poll_via_web(poll, question1, 'Yes') + vote_for_poll_via_web(poll, question2, 'Green') + expect(Poll::Voter.count).to eq(2) + logout + + login_as user3 + vote_for_poll_via_web(poll, question1, 'No') + vote_for_poll_via_web(poll, question2, 'Yellow') + expect(Poll::Voter.count).to eq(3) + logout + + poll.update(ends_at: 1.day.ago) + + visit results_poll_path(poll) + + expect(page).to have_content(question1.title) + expect(page).to have_content(question2.title) + + within("#question_#{question1.id}_results_table") do + expect(find("#answer_#{answer1.id}_result")).to have_content("2 (66.0%)") + expect(find("#answer_#{answer2.id}_result")).to have_content("1 (33.0%)") + end + + within("#question_#{question2.id}_results_table") do + expect(find("#answer_#{answer3.id}_result")).to have_content("1 (33.0%)") + expect(find("#answer_#{answer4.id}_result")).to have_content("1 (33.0%)") + expect(find("#answer_#{answer5.id}_result")).to have_content("1 (33.0%)") + end + end +end diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 256807928..aee0ff522 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -41,6 +41,27 @@ feature "Voter" do expect(Poll::Voter.first.origin).to eq("web") end + scenario "Voting via web as unverified user", :js do + poll = create(:poll) + + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question, title: 'Yes') + answer2 = create(:poll_question_answer, question: question, title: 'No') + + user = create(:user, :incomplete_verification) + + login_as user + visit poll_path(poll) + + within("#poll_question_#{question.id}_answers") do + expect(page).to_not have_link('Yes', href: "/questions/#{question.id}/answer?answer=Yes&token=") + expect(page).to_not have_link('No', href: "/questions/#{question.id}/answer?answer=No&token=") + end + + expect(page).to have_content("You must verify your account in order to answer") + expect(page).to_not have_content("You have already participated in this poll. If you vote again it will be overwritten") + end + scenario "Voting in booth", :js do user = create(:user, :in_census) @@ -51,8 +72,12 @@ feature "Voter" do expect(page).to have_content poll.name - first(:button, "Confirm vote").click - expect(page).to have_content "Vote introduced!" + within("#poll_#{poll.id}") do + click_button("Confirm vote") + expect(page).to_not have_button("Confirm vote") + expect(page).to have_button('Wait, confirming vote...', disabled: true) + expect(page).to have_content "Vote introduced!" + end expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("booth") @@ -70,7 +95,8 @@ feature "Voter" do scenario "Trying to vote in web and then in booth", :js do login_as user - vote_for_poll_via_web(poll, question) + vote_for_poll_via_web(poll, question, 'Yes') + expect(Poll::Voter.count).to eq(1) click_link "Sign out" @@ -102,7 +128,8 @@ feature "Voter" do scenario "Trying to vote in web again", :js do login_as user - vote_for_poll_via_web(poll, question) + vote_for_poll_via_web(poll, question, 'Yes') + expect(Poll::Voter.count).to eq(1) visit poll_path(poll) @@ -122,10 +149,36 @@ feature "Voter" do expect(page).to have_link('Yes') expect(page).to have_link('No') end - end end + scenario "Voting in poll and then verifiying account", :js do + user = create(:user) + + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question, title: 'Yes') + answer2 = create(:poll_question_answer, question: question, title: 'No') + + login_through_form_as_officer(officer.user) + vote_for_poll_via_booth + + visit root_path + click_link "Sign out" + + login_as user + visit account_path + click_link 'Verify my account' + + verify_residence + confirm_phone(user) + + visit poll_path(poll) + + expect(page).to_not have_link('Yes') + 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 + end end diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index ae2bac6d1..5a73209df 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -314,7 +314,7 @@ feature 'Users' do @user.update(public_interests: true) visit user_path(@user) - expect(page).to have_content("List of interests (Tags of elements this user follows)") + expect(page).to have_content("List of interests (tags of elements this user follows)") end scenario 'Should display custom interests title when user is visiting own user page' do @@ -322,7 +322,7 @@ feature 'Users' do login_as(@user) visit user_path(@user) - expect(page).to have_content("List of interests (Tags of elements you follow)") + expect(page).to have_content("List of interests (tags of elements you follow)") end scenario 'Should display generic empty interests list message when visited user has not interests defined' do diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 55ea8445b..fe2cdd786 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -35,7 +35,7 @@ describe UsersHelper do investment.hide - expect(comment_commentable_title(comment)).to eq '
+ +