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..19003ad3a 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -6,17 +6,17 @@ 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 @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/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/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 4f56b45ab..c30f02233 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -5,13 +5,13 @@ 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 def show set_debate_votes(@debate) - @comments = @debate.root_comments.with_hidden.recent + @comments = @debate.root_comments.with_hidden.recent.page(params[:page]) end def new diff --git a/app/models/debate.rb b/app/models/debate.rb index 7d39384d5..bd7936e73 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,7 +1,7 @@ require 'numeric' class Debate < ActiveRecord::Base include ActsAsParanoidAliases - default_scope { order('created_at DESC') } + default_scope { order(created_at: :desc) } apply_simple_captcha TITLE_LENGTH = Debate.columns.find { |c| c.name == 'title' }.limit 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 %>

+ + +<%= 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 %>

+ + +<%= 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 b22dfdbc9..425bee1f7 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -1,48 +1,48 @@ -
+

<%= 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 - %> -
+

-
+

<%= page_entries_info @organizations %>

+ + + <% @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, request.query_parameters), + method: :put + %> + <%= t('admin.organizations.index.rejected') %><%= link_to t('admin.organizations.index.reject'), + reject_admin_organization_path(organization, request.query_parameters), + method: :put + %> +
+ +<%= paginate @organizations %> 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 %>

+ +<%= paginate @tags %> diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index a60f147ba..d0317d52f 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -30,7 +30,7 @@ <%= t("shared.organization") %> <% end %> - <% if comment.user == @debate.author %> + <% if comment.user_id == @debate.author_id %>  •  <%= t("debates.comment.author") %> @@ -41,7 +41,7 @@ <% if comment.user.official? %>

<%= comment.body %>

- <% elsif comment.user == @debate.author %> + <% elsif comment.user_id == @debate.author_id %>

<%= comment.body %>

<% else %>

<%= comment.body %>

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/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 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) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 36751e9d4..cd0706ca8 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -16,6 +16,24 @@ feature 'Debates' do end end + scenario 'Paginated Index' do + per_page = Kaminari.config.default_per_page + (per_page + 2).times { create(:debate) } + + visit debates_path + + expect(page).to have_selector('#debates .debate', 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_selector('#debates .debate', count: 2) + end + scenario 'Show' do debate = create(:debate)