updates specs for admin poll questions
This commit is contained in:
@@ -14,13 +14,11 @@ class Poll::Question < ActiveRecord::Base
|
||||
belongs_to :proposal
|
||||
|
||||
validates :title, presence: true
|
||||
validates :question, presence: true
|
||||
validates :summary, presence: true
|
||||
validates :author, presence: true
|
||||
|
||||
validates :title, length: { in: 4..Poll::Question.title_max_length }
|
||||
validates :description, length: { maximum: Poll::Question.description_max_length }
|
||||
validates :question, length: { in: 10..Poll::Question.question_max_length }
|
||||
|
||||
scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)}
|
||||
scope :for_render, -> { includes(:author, :proposal) }
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
<% if @question.proposal.present? %>
|
||||
<div>
|
||||
<%= I18n.t("admin.questions.show.proposal") %>:
|
||||
<%= @question.proposal.title %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if @question.proposal.present? %>
|
||||
<div>
|
||||
<%= I18n.t("admin.questions.show.proposal") %>:
|
||||
<%= link_to @question.proposal.title, proposal_path(@question.proposal) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<%= I18n.t("admin.questions.show.title") %>:
|
||||
<%= @question.title %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= I18n.t("admin.questions.show.author") %>:
|
||||
<%= link_to @question.author.name, user_path(@question.author) %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= I18n.t("admin.questions.show.valid_answers") %>:
|
||||
<%= @question.valid_answers.join(", ") %>
|
||||
@@ -30,7 +35,7 @@
|
||||
<%= I18n.t("admin.questions.show.geozones") %>:
|
||||
<% @question.geozones.each do |geozone| %>
|
||||
<div>
|
||||
<% geozone.name %>
|
||||
<%= geozone.name %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -57,9 +57,16 @@
|
||||
<div class="message">
|
||||
<p>
|
||||
<%= t("proposal_ballots.successfull",
|
||||
voting: link_to(t("proposal_ballots.voting"), proposal_ballots_path)).html_safe %>
|
||||
voting: link_to(t("proposal_ballots.voting"), polls_path)).html_safe %>
|
||||
</p>
|
||||
</div>
|
||||
<% if can? :create, Poll::Question %>
|
||||
<p class="text-center">
|
||||
<%= link_to t('poll_questions.create_question'),
|
||||
new_admin_question_path(proposal_id: proposal.id),
|
||||
class: "button hollow" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% elsif proposal.archived? %>
|
||||
<div class="message">
|
||||
<strong><%= t("proposals.proposal.supports", count: proposal.total_votes) %></strong>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div id="next-voting" class="row featured-proposals-ballot-banner">
|
||||
<%= link_to proposal_ballots_path do %>
|
||||
<%= link_to polls_path do %>
|
||||
<div class="small-12 column padding">
|
||||
<div class="icon-successfull"></div>
|
||||
<h2><%= t("proposal_ballots.featured_title") %></h2>
|
||||
|
||||
@@ -186,7 +186,8 @@ en:
|
||||
new:
|
||||
title: "Create Question"
|
||||
show:
|
||||
proposal: Proposal
|
||||
proposal: Original proposal
|
||||
author: Author
|
||||
title: Title
|
||||
valid_answers: Valid answers
|
||||
summary: Summary
|
||||
|
||||
@@ -186,7 +186,8 @@ es:
|
||||
new:
|
||||
title: "Crear pregunta ciudadana"
|
||||
show:
|
||||
proposal: Propuesta Ciudadana
|
||||
proposal: Propuesta ciudadana original
|
||||
author: Autor
|
||||
title: Título
|
||||
valid_answers: Respuestas válidas
|
||||
summary: Resumen
|
||||
|
||||
@@ -385,7 +385,7 @@ en:
|
||||
cant_answer_incoming: "This poll has not yet started."
|
||||
cant_answer_expired: "This poll has finished."
|
||||
cant_answer_wrong_geozone: "The following questions are not available in your geozone."
|
||||
questions:
|
||||
poll_questions:
|
||||
create_question: "Create question"
|
||||
default_valid_answers: "Yes, No"
|
||||
index:
|
||||
|
||||
@@ -375,8 +375,8 @@ es:
|
||||
update:
|
||||
form:
|
||||
submit_button: Guardar cambios
|
||||
questions:
|
||||
create_enquiry: "Crear votación"
|
||||
poll_questions:
|
||||
create_question: "Crear votación"
|
||||
default_valid_answers: "Sí, No"
|
||||
index:
|
||||
filters:
|
||||
|
||||
@@ -181,6 +181,10 @@ FactoryGirl.define do
|
||||
4.times { create(:vote, votable: debate) }
|
||||
end
|
||||
end
|
||||
|
||||
trait :successful do
|
||||
cached_votes_up { Proposal.votes_needed_for_success + 100 }
|
||||
end
|
||||
end
|
||||
|
||||
factory :spending_proposal do
|
||||
@@ -280,6 +284,15 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question, class: 'Poll::Question' do
|
||||
poll
|
||||
association :author, factory: :user
|
||||
sequence(:title) { |n| "Question title #{n}" }
|
||||
sequence(:summary) { |n| "Question summary #{n}" }
|
||||
sequence(:description) { |n| "Question description #{n}" }
|
||||
valid_answers { Faker::Lorem.words(3).join(', ') }
|
||||
end
|
||||
|
||||
factory :poll_officer, class: 'Poll::Officer' do
|
||||
user
|
||||
end
|
||||
@@ -309,16 +322,6 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question, class: 'Poll::Question' do
|
||||
poll
|
||||
association :author, factory: :user
|
||||
sequence(:title) { |n| "Question title #{n}" }
|
||||
sequence(:summary) { |n| "Question summary #{n}" }
|
||||
sequence(:description) { |n| "Question description #{n}" }
|
||||
sequence(:question) { |n| "Question question #{n}" }
|
||||
valid_answers { Faker::Lorem.words(3).join(', ') }
|
||||
end
|
||||
|
||||
factory :poll_partial_result, class: 'Poll::PartialResult' do
|
||||
association :question, factory: :poll_question
|
||||
association :author, factory: :user
|
||||
|
||||
@@ -1,52 +1,33 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin enquiries' do
|
||||
background { login_as(create(:administrator).user) }
|
||||
|
||||
background do
|
||||
login_as(create(:administrator).user)
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
e1 = create(:enquiry)
|
||||
e2 = create(:enquiry)
|
||||
question1 = create(:poll_question)
|
||||
question2 = create(:poll_question)
|
||||
|
||||
visit admin_enquiries_path
|
||||
visit admin_questions_path
|
||||
|
||||
expect(page).to have_content(e1.title)
|
||||
expect(page).to have_content(e2.title)
|
||||
expect(page).to have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
end
|
||||
|
||||
scenario 'Destroy' do
|
||||
e1 = create(:enquiry)
|
||||
e2 = create(:enquiry)
|
||||
scenario 'Show' do
|
||||
geozone = create(:geozone)
|
||||
question = create(:poll_question, geozone_ids: geozone.id)
|
||||
|
||||
visit admin_enquiries_path
|
||||
visit admin_question_path(question)
|
||||
|
||||
within("#enquiry_#{e1.id}") do
|
||||
click_link "Delete"
|
||||
end
|
||||
|
||||
expect(page).to_not have_content(e1.title)
|
||||
expect(page).to have_content(e2.title)
|
||||
end
|
||||
|
||||
scenario 'Update' do
|
||||
e1 = create(:enquiry)
|
||||
visit admin_enquiries_path
|
||||
within("#enquiry_#{e1.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
old_title = e1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in 'enquiry_title', with: new_title
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
expect(page).to have_content new_title
|
||||
|
||||
visit admin_enquiries_path
|
||||
|
||||
expect(page).to have_content(new_title)
|
||||
expect(page).to_not have_content(old_title)
|
||||
expect(page).to have_content(question.title)
|
||||
expect(page).to have_content(question.description)
|
||||
expect(page).to have_content(question.summary)
|
||||
expect(page).to have_content(question.author.name)
|
||||
expect(page).to have_content(question.valid_answers.join(", "))
|
||||
expect(page).to have_content(geozone.name)
|
||||
end
|
||||
|
||||
scenario 'Create' do
|
||||
@@ -56,53 +37,80 @@ feature 'Admin enquiries' do
|
||||
During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet.
|
||||
Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy....
|
||||
}
|
||||
question = "Aren't you a little short for a stormtrooper?"
|
||||
|
||||
visit admin_enquiries_path
|
||||
click_link "Create enquiry"
|
||||
visit admin_questions_path
|
||||
click_link "Create question"
|
||||
|
||||
fill_in 'enquiry_title', with: title
|
||||
fill_in 'enquiry_summary', with: summary
|
||||
fill_in 'enquiry_description', with: description
|
||||
fill_in 'enquiry_question', with: question
|
||||
fill_in 'poll_question_title', with: title
|
||||
fill_in 'poll_question_summary', with: summary
|
||||
fill_in 'poll_question_description', with: description
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content(title)
|
||||
expect(page).to have_content(description)
|
||||
expect(page).to have_content(summary)
|
||||
expect(page).to have_content(question)
|
||||
end
|
||||
|
||||
scenario 'Create from successful proposal' do
|
||||
scenario 'Create from successful proposal', :focus do
|
||||
geozones = create_list(:geozone, 3)
|
||||
p = create(:proposal, :successful)
|
||||
proposal = create(:proposal, :successful)
|
||||
|
||||
visit proposals_path
|
||||
click_link "Create enquiry"
|
||||
click_link "Create question"
|
||||
|
||||
expect(current_path).to eq(new_admin_enquiry_path)
|
||||
expect(page).to have_field('enquiry_title', with: p.title)
|
||||
expect(page).to have_field('enquiry_summary', with: p.summary)
|
||||
expect(page).to have_field('enquiry_description', with: p.description)
|
||||
expect(page).to have_field('enquiry_question', with: p.question)
|
||||
expect(page).to have_field('enquiry_valid_answers', with: "Yes, No")
|
||||
|
||||
geozones.each do |g|
|
||||
expect(page).to have_checked_field("enquiry_geozone_ids_#{g.id}")
|
||||
end
|
||||
expect(current_path).to eq(new_admin_question_path)
|
||||
expect(page).to have_field('poll_question_title', with: proposal.title)
|
||||
expect(page).to have_field('poll_question_summary', with: proposal.summary)
|
||||
expect(page).to have_field('poll_question_description', with: proposal.description)
|
||||
expect(page).to have_field('poll_question_valid_answers', with: "Yes, No")
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content(p.title)
|
||||
expect(page).to have_content(p.summary)
|
||||
expect(page).to have_content(p.description)
|
||||
expect(page).to have_content(p.question)
|
||||
expect(page).to have_link('Original proposal', href: proposal_path(p))
|
||||
expect(page).to have_link(p.author.name, href: user_path(p.author))
|
||||
geozones.each do |g|
|
||||
expect(page).to have_content(g.name)
|
||||
end
|
||||
expect(page).to have_content(proposal.title)
|
||||
expect(page).to have_content(proposal.summary)
|
||||
expect(page).to have_content(proposal.description)
|
||||
expect(page).to have_link(proposal.title, href: proposal_path(proposal))
|
||||
expect(page).to have_link(proposal.author.name, href: user_path(proposal.author))
|
||||
end
|
||||
|
||||
scenario 'Update' do
|
||||
question1 = create(:poll_question)
|
||||
|
||||
visit admin_questions_path
|
||||
within("#poll_question_#{question1.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
old_title = question1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in 'poll_question_title', with: new_title
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
expect(page).to have_content new_title
|
||||
|
||||
visit admin_questions_path
|
||||
|
||||
expect(page).to have_content(new_title)
|
||||
expect(page).to_not have_content(old_title)
|
||||
end
|
||||
|
||||
scenario 'Destroy' do
|
||||
question1 = create(:poll_question)
|
||||
question2 = create(:poll_question)
|
||||
|
||||
visit admin_questions_path
|
||||
|
||||
within("#poll_question_#{question1.id}") do
|
||||
click_link "Delete"
|
||||
end
|
||||
|
||||
expect(page).to_not have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
end
|
||||
|
||||
pending "Mark all city by default when creating a poll question from a successful proposal"
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user