Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginator #61

Merged
merged 3 commits into from
Oct 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion spec/features/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,49 @@
page.should have_content('Displaying 1 Post')
end
end

end

context 'with 100 posts' do
let(:per_page) { 30 }
let(:posts_size) { 100 }

before do
posts_size.times { |n|
Post.create!(title: "Quick Brown Fox #{n}", body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user)
}

click_on 'Posts'
end

describe "paginator" do
it "must have paginator with 4 pages" do
page.should have_css('.pagination > .page.current')
page.all(:css, '.pagination > .page').size.should == 4
end

it "must show each page correctly" do
# temprorary go to page 2
page.find('.pagination > .page > a', text: '2').click

nbsp = Nokogiri::HTML(" ").text

(1..4).each do |page_number|
page.find('.pagination > .page > a', text: page_number).click
page.find('.pagination_information').should have_content('Displaying Posts')

offset = (page_number - 1) * per_page
collection_size = [per_page, posts_size - (page_number - 1) * per_page].min

display_total_text = I18n.t 'active_admin.pagination.multiple', :model => 'Posts', :total => posts_size,
:from => offset + 1, :to => offset + collection_size

pagination_information = page.find('.pagination_information').native.to_s.gsub(nbsp,' ')
pagination_information.should include(display_total_text.gsub(' ', ' '))
end
end
end
end # context 'with 100 posts'

end

end
1 change: 1 addition & 0 deletions test_app/app/admin/posts.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ActiveAdmin.register Post do
config.per_page = 30

filter :title
filter :body
Expand Down