From 947514fbfc4b7ec9b97e67c31a532e8c237eac67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 19 Aug 2015 13:16:17 +0200 Subject: [PATCH 1/7] adds pagination to debates#index Ref: #80 --- app/controllers/debates_controller.rb | 2 +- app/views/debates/index.html.erb | 1 + spec/features/debates_spec.rb | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 4f56b45ab..f0d5ed754 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -5,7 +5,7 @@ class DebatesController < ApplicationController respond_to :html, :js def index - @debates = Debate.includes(:tags).search(params) + @debates = Debate.includes(:tags).search(params).page(params[:page]) set_debate_votes(@debates) end diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 0e3e41d1d..92df365f0 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -75,6 +75,7 @@
<%= render @debates %> + <%= paginate @debates %>
diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index b1f311be5..60f06f169 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -19,6 +19,24 @@ feature 'Comments' do end end + scenario 'Paginated comments' do + debate = create(:debate) + per_page = Kaminari.config.default_per_page + (per_page + 2).times { create(:comment, commentable: debate)} + + visit debate_path(debate) + + expect(page).to have_css('.comment', count: per_page) + within("nav.pagination") do + expect(page).to have_content("1") + expect(page).to have_content("2") + expect(page).to_not have_content("3") + click_link "Next" + end + + expect(page).to have_css('.comment', count: 2) + end + feature 'Not logged user' do scenario 'can not see comments forms' do debate = create(:debate) From a43c753ebbd4ccde36b50047c3a079847c45241c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 19 Aug 2015 14:02:21 +0200 Subject: [PATCH 5/7] updates style of admin/organizations --- app/views/admin/organizations/index.html.erb | 82 ++++++++++---------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index b22dfdbc9..74d0bc220 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -1,48 +1,44 @@ -
+

<%= t('admin.organizations.index.title') %>

-

<%= t('admin.organizations.index.title') %>

+

+ <%= t('admin.organizations.index.filter') %>: -

- <%= t('admin.organizations.index.filter') %>: - - <% @valid_filters.each do |filter| %> - <% if @filter == filter %> - <%= t("admin.organizations.index.filters.#{filter}") %> - <% else %> - <%= link_to t("admin.organizations.index.filters.#{filter}"), - admin_organizations_path(filter: filter) %> - <% end %> + <% @valid_filters.each do |filter| %> + <% if @filter == filter %> + <%= t("admin.organizations.index.filters.#{filter}") %> + <% else %> + <%= link_to t("admin.organizations.index.filters.#{filter}"), + admin_organizations_path(filter: filter) %> <% end %> -

- - - <% @organizations.each do |organization| %> - - - - - <% if organization.verified? %> - - <% end %> - <% if can? :verify, organization %> - - <% end %> - <% if organization.rejected? %> - - <% end %> - <% if can? :reject, organization %> - - <% end %> - <% end %> -
<%= organization.name %><%= organization.email %><%= organization.phone_number %><%= t('admin.organizations.index.verified') %><%= link_to t('admin.organizations.index.verify'), - verify_admin_organization_path(organization, filter: @filter), - method: :put - %> - <%= t('admin.organizations.index.rejected') %><%= link_to t('admin.organizations.index.reject'), - reject_admin_organization_path(organization, filter: @filter), - method: :put - %> -
+

-
+ + <% @organizations.each do |organization| %> + + + + + <% if organization.verified? %> + + <% end %> + <% if can? :verify, organization %> + + <% end %> + <% if organization.rejected? %> + + <% end %> + <% if can? :reject, organization %> + + <% end %> + +<% end %> +
<%= organization.name %><%= organization.email %><%= organization.phone_number %><%= t('admin.organizations.index.verified') %><%= link_to t('admin.organizations.index.verify'), + verify_admin_organization_path(organization, filter: @filter), + method: :put + %> + <%= t('admin.organizations.index.rejected') %><%= link_to t('admin.organizations.index.reject'), + reject_admin_organization_path(organization, filter: @filter), + method: :put + %> +
\ No newline at end of file From fda8412ed3a663b2485035868bd18010a2c6a4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 19 Aug 2015 14:08:22 +0200 Subject: [PATCH 6/7] adds pagination to admin lists Ref: #80 --- app/controllers/admin/comments_controller.rb | 2 +- app/controllers/admin/debates_controller.rb | 2 +- app/controllers/admin/organizations_controller.rb | 2 +- app/controllers/admin/tags_controller.rb | 2 +- app/views/admin/comments/index.html.erb | 4 ++++ app/views/admin/debates/index.html.erb | 4 ++++ app/views/admin/organizations/index.html.erb | 6 +++++- app/views/admin/tags/index.html.erb | 4 +++- 8 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index 4c385b5d4..49dbc2889 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -1,7 +1,7 @@ class Admin::CommentsController < Admin::BaseController def index - @comments = Comment.only_hidden + @comments = Comment.only_hidden.page(params[:page]) end def restore diff --git a/app/controllers/admin/debates_controller.rb b/app/controllers/admin/debates_controller.rb index a37744f71..9f2f21f62 100644 --- a/app/controllers/admin/debates_controller.rb +++ b/app/controllers/admin/debates_controller.rb @@ -1,7 +1,7 @@ class Admin::DebatesController < Admin::BaseController def index - @debates = Debate.only_hidden + @debates = Debate.only_hidden.page(params[:page]) end def show diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index c7e3c159c..d8296ee4a 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -6,7 +6,7 @@ class Admin::OrganizationsController < Admin::BaseController def index @organizations = @organizations.send(@filter) - @organizations = @organizations.includes(:user).order(:name, 'users.email') + @organizations = @organizations.includes(:user).order(:name, 'users.email').page(params[:page]) end def verify diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 03cfeb64f..5655b0f8a 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -4,7 +4,7 @@ class Admin::TagsController < Admin::BaseController respond_to :html, :js def index - @tags = ActsAsTaggableOn::Tag.order(featured: :desc) + @tags = ActsAsTaggableOn::Tag.order(featured: :desc).page(params[:page]) @tag = ActsAsTaggableOn::Tag.new end diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb index c8c7faa8e..5a0b8f967 100644 --- a/app/views/admin/comments/index.html.erb +++ b/app/views/admin/comments/index.html.erb @@ -1,5 +1,7 @@

<%= t("admin.comments.index.title") %>

+

<%= page_entries_info @comments %>

+
    <% @comments.each do |comment| %>
  • @@ -16,3 +18,5 @@
  • <% end %>
+ +<%= paginate @comments %> diff --git a/app/views/admin/debates/index.html.erb b/app/views/admin/debates/index.html.erb index e7e1e5753..710f6ebd6 100644 --- a/app/views/admin/debates/index.html.erb +++ b/app/views/admin/debates/index.html.erb @@ -1,5 +1,7 @@

<%= t("admin.debates.index.title") %>

+

<%= page_entries_info @debates %>

+
    <% @debates.each do |debate| %>
  • @@ -11,3 +13,5 @@
  • <% end %>
+ +<%= paginate @debates %> \ No newline at end of file diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 74d0bc220..b0d651af2 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -13,6 +13,8 @@ <% end %>

+

<%= page_entries_info @organizations %>

+ <% @organizations.each do |organization| %> @@ -41,4 +43,6 @@ <% end %> <% end %> -
\ No newline at end of file + + +<%= paginate @organizations %> \ No newline at end of file diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index f6f14d5da..6e18ef009 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -20,7 +20,7 @@ <% end %> -

<%= t("admin.tags.index.title") %>

+

<%= t("admin.tags.index.title") %>: <%= page_entries_info @tags %>

    <% @tags.each do |tag| %> @@ -44,3 +44,5 @@ <% end %>
+ +<%= paginate @tags %> From 5c3f664da42081da9cef119786197ee0934975bf Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 20 Aug 2015 00:50:50 +0200 Subject: [PATCH 7/7] Fixes links in Admin::Organizations to handle filters + pages --- .../admin/organizations_controller.rb | 4 ++-- app/views/admin/organizations/index.html.erb | 6 +++--- spec/features/admin/organizations_spec.rb | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index d8296ee4a..19003ad3a 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -11,12 +11,12 @@ class Admin::OrganizationsController < Admin::BaseController def verify @organization.verify - redirect_to action: :index, filter: @filter + redirect_to request.query_parameters.merge(action: :index) end def reject @organization.reject - redirect_to action: :index, filter: @filter + redirect_to request.query_parameters.merge(action: :index) end private diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index b0d651af2..425bee1f7 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -26,7 +26,7 @@ <% end %> <% if can? :verify, organization %> <%= link_to t('admin.organizations.index.verify'), - verify_admin_organization_path(organization, filter: @filter), + verify_admin_organization_path(organization, request.query_parameters), method: :put %> @@ -36,7 +36,7 @@ <% end %> <% if can? :reject, organization %> <%= link_to t('admin.organizations.index.reject'), - reject_admin_organization_path(organization, filter: @filter), + reject_admin_organization_path(organization, request.query_parameters), method: :put %> @@ -45,4 +45,4 @@ <% end %> -<%= paginate @organizations %> \ No newline at end of file +<%= paginate @organizations %> diff --git a/spec/features/admin/organizations_spec.rb b/spec/features/admin/organizations_spec.rb index c3ac46d3d..954e2ee8f 100644 --- a/spec/features/admin/organizations_spec.rb +++ b/spec/features/admin/organizations_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Moderations::Organizations' do +feature 'Admin::Organizations' do background do @@ -111,4 +111,18 @@ feature 'Moderations::Organizations' do expect(page).to_not have_content('Verified Organization') end + scenario "Verifying organization links remember the pagination setting and the filter" do + 30.times { create(:organization) } + + visit admin_organizations_path(filter: 'pending', page: 2) + + click_on('Verify', match: :first) + + uri = URI.parse(current_url) + query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys + + expect(query_params[:filter]).to eq('pending') + expect(query_params[:page]).to eq('2') + end + end