Added specs and fixed some issues found after executing them
This commit is contained in:
Juan Salvador Pérez García
2018-06-26 12:09:36 +02:00
parent 2ce9f95283
commit 2be107f4da
7 changed files with 85 additions and 5 deletions

View File

@@ -36,8 +36,6 @@ class Dashboard::PollsController < Dashboard::BaseController
def update def update
authorize! :manage_polls, proposal authorize! :manage_polls, proposal
byebug
if poll.update(poll_params) if poll.update(poll_params)
redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll") redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll")
else else

View File

@@ -13,7 +13,7 @@ class Poll < ActiveRecord::Base
has_many :voters has_many :voters
has_many :officer_assignments, through: :booth_assignments has_many :officer_assignments, through: :booth_assignments
has_many :officers, through: :officer_assignments has_many :officers, through: :officer_assignments
has_many :questions has_many :questions, inverse_of: :poll
has_many :comments, as: :commentable has_many :comments, as: :commentable
has_and_belongs_to_many :geozones has_and_belongs_to_many :geozones

View File

@@ -5,7 +5,7 @@ class Poll::Question < ActiveRecord::Base
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases
belongs_to :poll belongs_to :poll, inverse_of: :questions
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
has_many :comments, as: :commentable has_many :comments, as: :commentable
@@ -16,7 +16,7 @@ class Poll::Question < ActiveRecord::Base
validates :title, presence: true validates :title, presence: true
validates :author, presence: true validates :author, presence: true
validates :poll_id, presence: true validates :poll_id, presence: true, if: Proc.new { |question| question.poll.nil? }
validates :title, length: { minimum: 4 } validates :title, length: { minimum: 4 }

View File

@@ -521,6 +521,9 @@ en:
add_question: Add question add_question: Add question
question_fields: question_fields:
remove_question: Remove question remove_question: Remove question
add_answer: Add answer
question_answer_fields:
remove_answer: Remove answer
polls: polls:
all: "All" all: "All"
no_dates: "no date assigned" no_dates: "no date assigned"

View File

@@ -521,6 +521,9 @@ es:
add_question: Añadir pregunta add_question: Añadir pregunta
question_fields: question_fields:
remove_question: Borrar pregunta remove_question: Borrar pregunta
add_answer: Añadir respuesta
question_answer_fields:
remove_answer: Borrar respuesta
polls: polls:
all: "Todas" all: "Todas"
no_dates: "sin fecha asignada" no_dates: "sin fecha asignada"

View File

@@ -0,0 +1,71 @@
require 'rails_helper'
feature 'Polls' do
let!(:proposal) { create(:proposal, :draft) }
before do
login_as(proposal.author)
visit proposal_dashboard_index_path(proposal)
end
scenario 'Has a link to polls feature' do
expect(page).to have_link('Polls')
end
scenario 'Initially there are no polls' do
click_link 'Polls'
expect(page).to have_content('There are no polls coming up.')
end
scenario 'Create a poll', :js do
click_link 'Polls'
click_link 'Create poll'
start_date = 1.week.from_now
end_date = 2.weeks.from_now
fill_in "poll_name", with: "Upcoming poll"
fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y")
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).not_to have_css("#poll_results_enabled")
expect(page).not_to have_css("#poll_stats_enabled")
click_link 'Add question'
fill_in 'Question', with: 'First question'
click_link 'Add answer'
fill_in 'Title', with: 'First answer'
click_button "Create poll"
expect(page).to have_content "Poll created successfully"
expect(page).to have_content "Upcoming poll"
expect(page).to have_content "First question"
expect(page).to have_content I18n.l(start_date.to_date)
expect(page).to have_content I18n.l(end_date.to_date)
expect(page).to have_link('Results')
end
scenario 'Update a poll', :js do
poll = create(:poll, related: proposal)
click_link 'Polls'
expect(page).to have_content(poll.name)
within("#poll_#{poll.id}") do
click_link 'Edit'
end
fill_in "poll_name", with: "Updated upcoming poll"
click_button "Update poll"
expect(page).to have_content "Poll updated successfully"
expect(page).to have_content "Updated upcoming poll"
end
end

View File

@@ -166,6 +166,11 @@ describe Abilities::Common do
it { should_not be_able_to(:dashboard, proposal) } it { should_not be_able_to(:dashboard, proposal) }
end end
describe 'proposal polls' do
it { should be_able_to(:manage_polls, own_proposal) }
it { should_not be_able_to(:manage_polls, proposal) }
end
describe 'publishing proposals' do describe 'publishing proposals' do
let(:draft_own_proposal) { create(:proposal, :draft, author: user) } let(:draft_own_proposal) { create(:proposal, :draft, author: user) }