Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue #412 - Disable download links option for PaginatedCollection

When rendering a paginated collection on the show screen for example,
it does not make sense to include resource download links for the collection.
  • Loading branch information...
commit 2043acb080ce4f3fafac2b08a4c1eca8cb6efe53 1 parent 1d3895a
@samvincent authored
View
6 lib/active_admin/views/components/paginated_collection.rb
@@ -33,9 +33,11 @@ class PaginatedCollection < ActiveAdmin::Component
# Useful keys:
# :entry_name - The name to display for this resource collection
# :param_name - Parameter name for page number in the links (:page by default)
+ # :download_links - Set to false to skip download format links
def build(collection, options = {})
@collection = collection
- @param_name = options.delete(:param_name)
+ @param_name = options.delete(:param_name)
+ @download_links = options.delete(:download_links)
unless collection.respond_to?(:num_pages)
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
@@ -60,7 +62,7 @@ def add_child(*args, &block)
def build_pagination_with_formats
div :id => "index_footer" do
- build_download_format_links
+ build_download_format_links unless @download_links == false
build_pagination
end
end
View
20 spec/unit/views/components/paginated_collection_spec.rb
@@ -11,6 +11,7 @@
before do
request.stub!(:query_parameters).and_return({:controller => 'admin/posts', :action => 'index', :page => '1'})
+ controller.params = {:controller => 'admin/posts', :action => 'index'}
end
context "when specifying collection" do
@@ -36,14 +37,23 @@
end
let(:pagination) { paginated_collection(collection, :param_name => :post_page) }
-
- before do
- controller.params = {:controller => 'admin/posts', :action => 'index'}
- end
-
+
it "should customize the page number parameter in pagination links" do
pagination.find_by_tag('div').last.content.should match(/\/admin\/posts\?post_page=2/)
end
end
+
+ context "when specifying :download_links => false option" do
+ let(:collection) do
+ posts = 10.times.inject([]) {|m| m << Post.new }
+ Kaminari.paginate_array(posts).page(1).per(5)
+ end
+
+ let(:pagination) { paginated_collection(collection, :download_links => false) }
+
+ it "should not render download links" do
+ pagination.find_by_tag('div').last.content.should_not match(/Download:/)
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.