From 1a7806150a2fafd987bb9f823e0b633c0bd4cefc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sun, 6 Sep 2015 21:32:54 +0200 Subject: [PATCH] adds pending filter to admin/debates --- app/controllers/admin/debates_controller.rb | 4 ++-- app/views/admin/debates/index.html.erb | 10 ++++++---- config/locales/admin.en.yml | 1 + config/locales/admin.es.yml | 1 + spec/features/admin/debates_spec.rb | 17 +++++++++++++++-- spec/features/debates_spec.rb | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/debates_controller.rb b/app/controllers/admin/debates_controller.rb index da1acc7fe..544c3f23d 100644 --- a/app/controllers/admin/debates_controller.rb +++ b/app/controllers/admin/debates_controller.rb @@ -1,10 +1,10 @@ class Admin::DebatesController < Admin::BaseController - has_filters %w{all with_confirmed_hide}, only: :index + has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index before_action :load_debate, only: [:confirm_hide, :restore] def index - @debates = Debate.only_hidden.send(@current_filter).page(params[:page]) + @debates = Debate.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page]) end def confirm_hide diff --git a/app/views/admin/debates/index.html.erb b/app/views/admin/debates/index.html.erb index 7caa8ecc3..118a0ae66 100644 --- a/app/views/admin/debates/index.html.erb +++ b/app/views/admin/debates/index.html.erb @@ -15,10 +15,12 @@ data: { confirm: t("admin.actions.confirm") }, class: "button radius tiny success right" %> - <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_debate_path(debate, request.query_parameters), - method: :put, - class: "button radius tiny warning right" %> + <% unless debate.confirmed_hide? %> + <%= link_to t("admin.actions.confirm_hide"), + confirm_hide_admin_debate_path(debate, request.query_parameters), + method: :put, + class: "button radius tiny warning right" %> + <% end %> <% end %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index fae6a38c6..4aecba1b0 100644 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -66,6 +66,7 @@ en: filters: all: All with_confirmed_hide: Confirmed + without_confirmed_hide: Pending users: index: title: Banned users diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 13984ab39..fae43bfc1 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -66,6 +66,7 @@ es: filters: all: Todos with_confirmed_hide: Confirmados + without_confirmed_hide: Pendientes users: index: title: Usuarios bloqueados diff --git a/spec/features/admin/debates_spec.rb b/spec/features/admin/debates_spec.rb index 9d956582e..bccd3429c 100644 --- a/spec/features/admin/debates_spec.rb +++ b/spec/features/admin/debates_spec.rb @@ -24,23 +24,32 @@ feature 'Admin debates' do click_link 'Confirm' + expect(page).to_not have_content(debate.title) + click_link('Confirmed') expect(page).to have_content(debate.title) - expect(page).to have_content('Confirmed') expect(debate.reload).to be_confirmed_hide end scenario "Current filter is properly highlighted" do visit admin_debates_path - expect(page).to_not have_link('All') + expect(page).to_not have_link('Pending') + expect(page).to have_link('All') + expect(page).to have_link('Confirmed') + + visit admin_debates_path(filter: 'Pending') + expect(page).to_not have_link('Pending') + expect(page).to have_link('All') expect(page).to have_link('Confirmed') visit admin_debates_path(filter: 'all') + expect(page).to have_link('Pending') expect(page).to_not have_link('All') expect(page).to have_link('Confirmed') visit admin_debates_path(filter: 'with_confirmed_hide') expect(page).to have_link('All') + expect(page).to have_link('Pending') expect(page).to_not have_link('Confirmed') end @@ -48,6 +57,10 @@ feature 'Admin debates' do create(:debate, :hidden, title: "Unconfirmed debate") create(:debate, :hidden, :with_confirmed_hide, title: "Confirmed debate") + visit admin_debates_path(filter: 'pending') + expect(page).to have_content('Unconfirmed debate') + expect(page).to_not have_content('Confirmed debate') + visit admin_debates_path(filter: 'all') expect(page).to have_content('Unconfirmed debate') expect(page).to have_content('Confirmed debate') diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 86903960f..de4d4d627 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -302,7 +302,7 @@ feature 'Debates' do scenario 'Index page shows up to 5 tags per debate' do debate - visible_tags = ["Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] + visible_tags = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares"] visit debates_path