From ad2dd7d267ae872ac0d7e1aa933898a486211e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 6 Dec 2016 14:51:53 +0100 Subject: [PATCH] adds officer-polls relation and spec --- app/models/poll.rb | 2 +- app/views/admin/poll/polls/_officers.html.erb | 16 +++------------- config/locales/admin.en.yml | 2 +- config/locales/admin.es.yml | 2 +- spec/factories.rb | 18 +++++++++--------- spec/features/admin/poll/polls_spec.rb | 5 +++++ 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index a274b4df7..e06e9af92 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,7 +1,7 @@ class Poll < ActiveRecord::Base has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments - has_many :officer_assignments, class_name: "Poll::OfficerAssignment" + has_many :officer_assignments, through: :booth_assignments has_many :officers, through: :officer_assignments has_many :voters, through: :booths, class_name: "Poll::Voter" diff --git a/app/views/admin/poll/polls/_officers.html.erb b/app/views/admin/poll/polls/_officers.html.erb index e5001e9da..240eb7b1c 100644 --- a/app/views/admin/poll/polls/_officers.html.erb +++ b/app/views/admin/poll/polls/_officers.html.erb @@ -11,28 +11,18 @@ - - - + <% @poll.officers.each do |officer| %> - - <% end %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index fec35dbe6..b8857e7a1 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -186,7 +186,7 @@ en: booths_title: "List of booths" name: "Name" location: "Location" - officers: "Officers" + email: "Email" questions: index: title: "Questions" diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 457a2f89e..1573b86b5 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -186,7 +186,7 @@ es: booths_title: "Listado de urnas" name: "Nombre" location: "Ubicación" - officers: "Presidentes de mesa" + email: "Email" questions: index: title: "Preguntas ciudadanas" diff --git a/spec/factories.rb b/spec/factories.rb index fa58eee84..50d466718 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -293,15 +293,6 @@ FactoryGirl.define do valid_answers { Faker::Lorem.words(3).join(', ') } end - factory :poll_officer, class: 'Poll::Officer' do - user - end - - factory :officing_booth, class: 'Poll::OfficingBooth' do - association :officer, factory: :poll_officer - association :booth, factory: :poll_booth - end - factory :poll_booth, class: 'Poll::Booth' do sequence(:name) { |n| "Booth #{n}" } sequence(:location) { |n| "Street #{n}" } @@ -312,6 +303,15 @@ FactoryGirl.define do association :booth, factory: :poll_booth end + factory :poll_officer, class: 'Poll::Officer' do + user + end + + factory :poll_officer_assignment, class: 'Poll::OfficerAssignment' do + association :officer, factory: :poll_officer + association :booth_assignment, factory: :poll_booth_assignment + end + factory :poll_voter, class: 'Poll::Voter' do association :booth, factory: :budget_booth diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index afaaf5e7f..5095f36d0 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -132,7 +132,12 @@ feature 'Admin polls' do poll = create(:poll) booth = create(:poll_booth, polls: [poll]) + booth.booth_assignments.each do |booth_assignment| + 3.times {create(:poll_officer_assignment, booth_assignment: booth_assignment) } + end + visit admin_poll_path(poll) + click_link "Officers (3)" expect(page).to have_css ".officer", count: 3
<%= t("admin.polls.show.name") %><%= t("admin.polls.show.location") %><%= t("admin.polls.show.officers") %> <%= t("admin.polls.show.email") %>
- <%= link_to officer.name, admin_poll_officer_path(@poll, booth) %> + <%= officer.name %> - <%= officer.name %> - - N <%= t("admin.booths.index.officers") %> - - <%= link_to t("admin.actions.edit"), - edit_admin_poll_officer_path(@poll, officer), - class: "button hollow" %> + <%= officer.email %>