Merge pull request #3572 from consul/user-polls

Hide polls created by users from proposals dashboard on admin poll index
This commit is contained in:
Alberto
2019-06-01 10:38:07 +02:00
committed by GitHub
3 changed files with 13 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
before_action :load_geozones, only: [:new, :create, :edit, :update]
def index
@polls = Poll.not_budget.order(starts_at: :desc)
@polls = Poll.not_budget.created_by_admin.order(starts_at: :desc)
end
def show

View File

@@ -47,6 +47,7 @@ class Poll < ApplicationRecord
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
scope :public_for_api, -> { all }
scope :not_budget, -> { where(budget_id: nil) }
scope :created_by_admin, -> { where(related_type: nil) }
scope :sort_for_list, -> { joins(:translations).order(:geozone_restricted, :starts_at, "poll_translations.name") }

View File

@@ -44,6 +44,17 @@ describe "Admin polls" do
expect(page).not_to have_content "There are no polls"
end
scenario "Index do not show polls created by users from proposals dashboard" do
create(:poll, name: "Poll created by admin")
create(:poll, name: "Poll from user's proposal", related_type: "Proposal")
visit admin_polls_path
expect(page).to have_css ".poll", count: 1
expect(page).to have_content "Poll created by admin"
expect(page).not_to have_content "Poll from user's proposal"
end
scenario "Show" do
poll = create(:poll)