adds poll CRU actions
This commit is contained in:
@@ -10,7 +10,29 @@ class Admin::Poll::PollsController < Admin::BaseController
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
if @poll.save
|
||||
redirect_to [:admin, @poll], notice: t("flash.actions.create.poll")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @poll.update(poll_params)
|
||||
redirect_to [:admin, @poll], notice: t("flash.actions.update.poll")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def poll_params
|
||||
params.require(:poll).permit(:name)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
class Poll < ActiveRecord::Base
|
||||
has_many :booths
|
||||
has_many :voters, through: :booths, class_name: "Poll::Voter"
|
||||
|
||||
validates :name, presence: true
|
||||
end
|
||||
34
app/views/admin/poll/polls/_form.html.erb
Normal file
34
app/views/admin/poll/polls/_form.html.erb
Normal file
@@ -0,0 +1,34 @@
|
||||
<%= form_for [:admin, @poll] do |f| %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :name,
|
||||
placeholder: t('admin.polls.new.name'),
|
||||
label: t("admin.polls.new.name") %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.reference") %></label>
|
||||
<input type="text" placeholder="<%= t('admin.polls.new.reference') %>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.open_date") %></label>
|
||||
<input type="date">
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.close_date") %></label>
|
||||
<input type="date">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<input type="submit"
|
||||
value='<%= t("admin.polls.#{admin_submit_action(@poll)}.submit_button") %>'
|
||||
class="button success expanded">
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -2,7 +2,7 @@
|
||||
<td>
|
||||
<strong>
|
||||
<%= link_to poll.name, admin_poll_path(poll) %>
|
||||
</strong>ß
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
Próximamente <!-- Estado: Activa, Próximamente o Archivada -->
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<%= render 'shared/back_link' %>
|
||||
|
||||
<h2><%= t("admin.polls.edit.title") %></h2>
|
||||
<%= render "form" %>
|
||||
|
||||
<form>
|
||||
<!-- <form>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.edit.name") %></label>
|
||||
@@ -31,6 +32,6 @@
|
||||
<div class="small-12 medium-4 column">
|
||||
<input type="submit" value="<%= t('admin.polls.edit.submit_button') %>" class="button success expanded">
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
</form>
|
||||
@@ -1,14 +1,10 @@
|
||||
<h2 class="inline-block"><%= t("admin.polls.index.title") %></h2>
|
||||
|
||||
<%= link_to t("admin.polls.index.create"), new_admin_poll_path, class: "button success float-right" %>
|
||||
|
||||
<!-- If polls == 0 -->
|
||||
<div class="callout primary">
|
||||
<%= t("admin.polls.index.no_polls") %>
|
||||
</div>
|
||||
|
||||
<!-- else -->
|
||||
<%= link_to t("admin.polls.index.create"),
|
||||
new_admin_poll_path,
|
||||
class: "button success float-right" %>
|
||||
|
||||
<% if Poll.any? %>
|
||||
<table>
|
||||
<thead>
|
||||
<th><%= t("admin.polls.index.name") %></th>
|
||||
@@ -19,3 +15,8 @@
|
||||
<%= render @polls %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<div class="callout primary">
|
||||
<%= t("admin.polls.index.no_polls") %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -2,35 +2,4 @@
|
||||
|
||||
<h2><%= t("admin.polls.new.title") %></h2>
|
||||
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.name") %></label>
|
||||
<input type="text" placeholder="<%= t('admin.polls.new.name') %>">
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.reference") %></label>
|
||||
<input type="text" placeholder="<%= t('admin.polls.new.reference') %>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.open_date") %></label>
|
||||
<input type="date">
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.polls.new.close_date") %></label>
|
||||
<input type="date">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<input type="submit" value="<%= t('admin.polls.new.submit_button') %>" class="button success expanded">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<%= render "form" %>
|
||||
@@ -5,7 +5,7 @@
|
||||
<%= @poll.name %>
|
||||
</h2>
|
||||
|
||||
<%= link_to t("admin.actions.edit"), "#", class: "button hollow float-right" %>
|
||||
<%= link_to t("admin.actions.edit"), edit_admin_poll_path(@poll), class: "button hollow float-right" %>
|
||||
|
||||
<p>(REFNUM)</p>
|
||||
<p>Próximamente <small>(15/12/2016 - 15/02/2017)</small></p>
|
||||
@@ -26,7 +26,7 @@
|
||||
<th> </th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- @booths.each do |booth| -->
|
||||
<%= @poll.booths.each do |booth| %>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>
|
||||
@@ -40,6 +40,6 @@
|
||||
<%= link_to t("admin.actions.edit"), "#", class: "button hollow" %>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end -->
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -155,7 +155,7 @@ en:
|
||||
polls:
|
||||
index:
|
||||
title: "List of polls"
|
||||
no_polls: "There are any poll."
|
||||
no_polls: "There are no polls."
|
||||
create: "Create poll"
|
||||
name: "Name"
|
||||
status: "Status"
|
||||
|
||||
@@ -6,15 +6,16 @@ en:
|
||||
notice: "%{resource_name} created successfully."
|
||||
debate: "Debate created successfully."
|
||||
direct_message: "You message has been sent successfully."
|
||||
poll: "Poll created successfully."
|
||||
proposal: "Proposal created successfully."
|
||||
proposal_notification: "Your message has been sent correctly."
|
||||
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
|
||||
|
||||
save_changes:
|
||||
notice: Changes saved
|
||||
update:
|
||||
notice: "%{resource_name} updated successfully."
|
||||
debate: "Debate updated successfully."
|
||||
poll: "Poll updated successfully."
|
||||
proposal: "Proposal updated successfully."
|
||||
spending_proposal: "Investment project updated succesfully."
|
||||
destroy:
|
||||
|
||||
@@ -6,6 +6,7 @@ es:
|
||||
notice: "%{resource_name} creado correctamente."
|
||||
debate: "Debate creado correctamente."
|
||||
direct_message: "Tu mensaje ha sido enviado correctamente."
|
||||
poll: "Votación presencial creada correctamente."
|
||||
proposal: "Propuesta creada correctamente."
|
||||
proposal_notification: "Tu message ha sido enviado correctamente."
|
||||
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"
|
||||
|
||||
@@ -7,6 +7,15 @@ feature 'Admin polls' do
|
||||
login_as(admin.user)
|
||||
end
|
||||
|
||||
scenario 'Index empty' do
|
||||
visit admin_root_path
|
||||
within('#side_menu') do
|
||||
click_link "Polls"
|
||||
end
|
||||
|
||||
expect(page).to have_content "There are no polls"
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
3.times { create(:poll) }
|
||||
|
||||
@@ -24,9 +33,10 @@ feature 'Admin polls' do
|
||||
#expect(page).to have_content "Status/Dates" - Hardcoded
|
||||
end
|
||||
end
|
||||
expect(page).to_not have_content "There are no polls"
|
||||
end
|
||||
|
||||
scenario 'Show', :focus do
|
||||
scenario 'Show' do
|
||||
poll = create(:poll)
|
||||
|
||||
visit admin_polls_path
|
||||
@@ -37,4 +47,45 @@ feature 'Admin polls' do
|
||||
#expect(page).to have_content "REFNUM" - Hardcoded
|
||||
end
|
||||
|
||||
scenario "Create" do
|
||||
visit admin_polls_path
|
||||
click_link "Create poll"
|
||||
|
||||
fill_in "poll_name", with: "Upcoming poll"
|
||||
#fill_in reference_number - Hardcoded
|
||||
#fill_in open_date - Hardcoded
|
||||
#fill_in close_date - Hardcoded
|
||||
click_button "Create poll"
|
||||
expect(page).to have_content "Poll created successfully"
|
||||
|
||||
expect(page).to have_content "Upcoming poll"
|
||||
end
|
||||
|
||||
scenario "Edit" do
|
||||
poll = create(:poll)
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
click_link "Edit"
|
||||
save_and_open_page
|
||||
fill_in "poll_name", with: "Next Poll"
|
||||
#fill_in reference_number - Hardcoded
|
||||
#fill_in open_date - Hardcoded
|
||||
#fill_in close_date - Hardcoded
|
||||
click_button "Update poll"
|
||||
expect(page).to have_content "Poll updated successfully"
|
||||
|
||||
expect(page).to have_content "Next Poll"
|
||||
end
|
||||
|
||||
scenario 'Edit from index' do
|
||||
poll = create(:poll)
|
||||
visit admin_polls_path
|
||||
|
||||
within("#poll_#{poll.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
expect(current_path).to eq(edit_admin_poll_path(poll))
|
||||
end
|
||||
|
||||
end
|
||||
16
spec/models/poll_spec.rb
Normal file
16
spec/models/poll_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe :poll do
|
||||
|
||||
let(:poll) { build(:poll) }
|
||||
|
||||
it "should be valid" do
|
||||
expect(poll).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a name" do
|
||||
poll.name = nil
|
||||
expect(poll).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user