adds poll CRU actions

This commit is contained in:
rgarcia
2016-09-25 10:20:38 +02:00
parent c965e2dda1
commit 0795da02d8
13 changed files with 157 additions and 59 deletions

View File

@@ -10,7 +10,29 @@ class Admin::Poll::PollsController < Admin::BaseController
def new def new
end end
def create
if @poll.save
redirect_to [:admin, @poll], notice: t("flash.actions.create.poll")
else
render :new
end
end
def edit def edit
end 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 end

View File

@@ -1,4 +1,6 @@
class Poll < ActiveRecord::Base class Poll < ActiveRecord::Base
has_many :booths has_many :booths
has_many :voters, through: :booths, class_name: "Poll::Voter" has_many :voters, through: :booths, class_name: "Poll::Voter"
validates :name, presence: true
end end

View 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 %>

View File

@@ -2,7 +2,7 @@
<td> <td>
<strong> <strong>
<%= link_to poll.name, admin_poll_path(poll) %> <%= link_to poll.name, admin_poll_path(poll) %>
</strong>ß </strong>
</td> </td>
<td> <td>
Próximamente <!-- Estado: Activa, Próximamente o Archivada --> Próximamente <!-- Estado: Activa, Próximamente o Archivada -->

View File

@@ -1,8 +1,9 @@
<%= render 'shared/back_link' %> <%= render 'shared/back_link' %>
<h2><%= t("admin.polls.edit.title") %></h2> <h2><%= t("admin.polls.edit.title") %></h2>
<%= render "form" %>
<form> <!-- <form>
<div class="row"> <div class="row">
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
<label><%= t("admin.polls.edit.name") %></label> <label><%= t("admin.polls.edit.name") %></label>
@@ -31,6 +32,6 @@
<div class="small-12 medium-4 column"> <div class="small-12 medium-4 column">
<input type="submit" value="<%= t('admin.polls.edit.submit_button') %>" class="button success expanded"> <input type="submit" value="<%= t('admin.polls.edit.submit_button') %>" class="button success expanded">
</div> </div>
</div> </div> -->
</form> </form>

View File

@@ -1,15 +1,11 @@
<h2 class="inline-block"><%= t("admin.polls.index.title") %></h2> <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" %> <%= link_to t("admin.polls.index.create"),
new_admin_poll_path,
class: "button success float-right" %>
<!-- If polls == 0 --> <% if Poll.any? %>
<div class="callout primary"> <table>
<%= t("admin.polls.index.no_polls") %>
</div>
<!-- else -->
<table>
<thead> <thead>
<th><%= t("admin.polls.index.name") %></th> <th><%= t("admin.polls.index.name") %></th>
<th><%= t("admin.polls.index.status") %></th> <th><%= t("admin.polls.index.status") %></th>
@@ -18,4 +14,9 @@
<tbody> <tbody>
<%= render @polls %> <%= render @polls %>
</tbody> </tbody>
</table> </table>
<% else %>
<div class="callout primary">
<%= t("admin.polls.index.no_polls") %>
</div>
<% end %>

View File

@@ -2,35 +2,4 @@
<h2><%= t("admin.polls.new.title") %></h2> <h2><%= t("admin.polls.new.title") %></h2>
<form> <%= render "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>

View File

@@ -5,7 +5,7 @@
<%= @poll.name %> <%= @poll.name %>
</h2> </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>(REFNUM)</p>
<p>Próximamente <small>(15/12/2016 - 15/02/2017)</small></p> <p>Próximamente <small>(15/12/2016 - 15/02/2017)</small></p>
@@ -26,7 +26,7 @@
<th>&nbsp;</th> <th>&nbsp;</th>
</thead> </thead>
<tbody> <tbody>
<!-- @booths.each do |booth| --> <%= @poll.booths.each do |booth| %>
<tr> <tr>
<td> <td>
<strong> <strong>
@@ -40,6 +40,6 @@
<%= link_to t("admin.actions.edit"), "#", class: "button hollow" %> <%= link_to t("admin.actions.edit"), "#", class: "button hollow" %>
</td> </td>
</tr> </tr>
<!-- end --> <% end %>
</tbody> </tbody>
</table> </table>

View File

@@ -155,7 +155,7 @@ en:
polls: polls:
index: index:
title: "List of polls" title: "List of polls"
no_polls: "There are any poll." no_polls: "There are no polls."
create: "Create poll" create: "Create poll"
name: "Name" name: "Name"
status: "Status" status: "Status"

View File

@@ -6,15 +6,16 @@ en:
notice: "%{resource_name} created successfully." notice: "%{resource_name} created successfully."
debate: "Debate created successfully." debate: "Debate created successfully."
direct_message: "You message has been sent successfully." direct_message: "You message has been sent successfully."
poll: "Poll created successfully."
proposal: "Proposal created successfully." proposal: "Proposal created successfully."
proposal_notification: "Your message has been sent correctly." proposal_notification: "Your message has been sent correctly."
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}" spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
save_changes: save_changes:
notice: Changes saved notice: Changes saved
update: update:
notice: "%{resource_name} updated successfully." notice: "%{resource_name} updated successfully."
debate: "Debate updated successfully." debate: "Debate updated successfully."
poll: "Poll updated successfully."
proposal: "Proposal updated successfully." proposal: "Proposal updated successfully."
spending_proposal: "Investment project updated succesfully." spending_proposal: "Investment project updated succesfully."
destroy: destroy:

View File

@@ -6,6 +6,7 @@ es:
notice: "%{resource_name} creado correctamente." notice: "%{resource_name} creado correctamente."
debate: "Debate creado correctamente." debate: "Debate creado correctamente."
direct_message: "Tu mensaje ha sido enviado correctamente." direct_message: "Tu mensaje ha sido enviado correctamente."
poll: "Votación presencial creada correctamente."
proposal: "Propuesta creada correctamente." proposal: "Propuesta creada correctamente."
proposal_notification: "Tu message ha sido enviado correctamente." proposal_notification: "Tu message ha sido enviado correctamente."
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}" spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"

View File

@@ -7,6 +7,15 @@ feature 'Admin polls' do
login_as(admin.user) login_as(admin.user)
end 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 scenario 'Index' do
3.times { create(:poll) } 3.times { create(:poll) }
@@ -24,9 +33,10 @@ feature 'Admin polls' do
#expect(page).to have_content "Status/Dates" - Hardcoded #expect(page).to have_content "Status/Dates" - Hardcoded
end end
end end
expect(page).to_not have_content "There are no polls"
end end
scenario 'Show', :focus do scenario 'Show' do
poll = create(:poll) poll = create(:poll)
visit admin_polls_path visit admin_polls_path
@@ -37,4 +47,45 @@ feature 'Admin polls' do
#expect(page).to have_content "REFNUM" - Hardcoded #expect(page).to have_content "REFNUM" - Hardcoded
end 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 end

16
spec/models/poll_spec.rb Normal file
View 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