Skip to content

Commit 3c78616

Browse files
committed
Merge remote-tracking branch 'origin/master' into rails4
2 parents 1b3b9a2 + bba338a commit 3c78616

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# module ActiveAdmin
2-
# module Helpers
3-
# module Collection
4-
# def collection_size(collection=collection)
5-
# raise collection.inspect
6-
# collection.count
7-
# end
8-
# end
9-
# end
10-
# end
1+
module ActiveAdmin
2+
module Helpers
3+
module Collection
4+
def collection_size(collection=collection)
5+
collection.count(true)
6+
end
7+
end
8+
end
9+
end

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

test_app/config/initializers/devise.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
77
config.mailer_sender = "[email protected]"
88

9+
config.secret_key = '8c57910ca9a61008a2566fc337a67ddc043b91d64e0420ca8dd691e80cf362bc8a480ecb1465bd4ae958e715d354264a97934c058c3e14f5d552012ff5755122'
10+
911
# Configure the class responsible to send e-mails.
1012
# config.mailer = "Devise::Mailer"
1113

0 commit comments

Comments
 (0)