Skip to content

Commit bba338a

Browse files
committed
Merge pull request #61 from Zhomart/paginator
Paginator
2 parents 27ce04f + 55b8f71 commit bba338a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

spec/features/smoke_spec.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,49 @@
203203
page.should have_content('Displaying 1 Post')
204204
end
205205
end
206-
207206
end
207+
208+
context 'with 100 posts' do
209+
let(:per_page) { 30 }
210+
let(:posts_size) { 100 }
211+
212+
before do
213+
posts_size.times { |n|
214+
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)
215+
}
216+
217+
click_on 'Posts'
218+
end
219+
220+
describe "paginator" do
221+
it "must have paginator with 4 pages" do
222+
page.should have_css('.pagination > .page.current')
223+
page.all(:css, '.pagination > .page').size.should == 4
224+
end
225+
226+
it "must show each page correctly" do
227+
# temprorary go to page 2
228+
page.find('.pagination > .page > a', text: '2').click
229+
230+
nbsp = Nokogiri::HTML(" ").text
231+
232+
(1..4).each do |page_number|
233+
page.find('.pagination > .page > a', text: page_number).click
234+
page.find('.pagination_information').should have_content('Displaying Posts')
235+
236+
offset = (page_number - 1) * per_page
237+
collection_size = [per_page, posts_size - (page_number - 1) * per_page].min
238+
239+
display_total_text = I18n.t 'active_admin.pagination.multiple', :model => 'Posts', :total => posts_size,
240+
:from => offset + 1, :to => offset + collection_size
241+
242+
pagination_information = page.find('.pagination_information').native.to_s.gsub(nbsp,' ')
243+
pagination_information.should include(display_total_text.gsub(' ', ' '))
244+
end
245+
end
246+
end
247+
end # context 'with 100 posts'
248+
208249
end
209250

210251
end

test_app/app/admin/posts.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ActiveAdmin.register Post do
2+
config.per_page = 30
23

34
filter :title
45
filter :body

0 commit comments

Comments
 (0)